开发者 | francoisppeloquin |
---|---|
更新时间 | 2019年3月19日 04:33 |
捐献地址: | 去捐款 |
PHP版本: | 3.0.1 及以上 |
WordPress版本: | 5.1.1 |
版权: | GPLv2 or later |
版权网址: | 版权信息 |
/wp-content/plugins/haystack-wordpress
directory, or install the plugin through the WordPress plugins screen directly.Got to Haystack.menu and follow the simple steps in order to create your account and receive access.
Haystack has built in filters that allow you to change some defined variables that represent your web page. Currently the filters haystack_set_type
, haystack_set_image
, haystack_set_body
, and haystack_set_tags
have been enabled. These functions are passed the ID of the post, and the returned data will be sent to elasticsearch.
Here are two examples set in a user's theme folder in their functions.php file:
//We want type here to show much more data than the average
function _haystack_set_type($id) {
//Adding post type as the first of the tags to pass
$post_type = get_post_type($id);
$post_type = get_post_type_object($post_type);
$tags[] = array($post_type->labels->singular_name);
//Adding the post author as the second part of the tags array to pass
$post_auth = get_post($id);
$post_auth = $post_auth->post_author;
$tags[] = get_the_author_meta('nicename',$post_auth);
//Adding categories to the array
$post_cat = wp_get_post_categories($id);
foreach ($post_cat as $c) {
$cat = get_category($c);
$tags[] = $cat->name;
}
//Adding tags associated with the post, if they exist
$post_tags = wp_get_post_tags($id);
foreach ($post_tags as $key => $val) {
$tags[] = $val->name;
}
//Return in tags
return (!empty($tags) ? ''.implode('',$tags).'' : '');
}
//Apply the filter
add_filter('haystack_set_type','_haystack_set_type');
The second example here hooks in and replaces all images with a static one:
//Add a sample image to each Haystack post item. Image could alternately be fetched from the ID
function _haystack_set_image($id) {
return 'http://www.gallaghersmash.com/wp-content/uploads/2015/04/gallagher.jpg';
}
//Apply the filter
add_filter('haystack_set_image','_haystack_set_image');