Advertisement
geminilabs

[site-reviews] show rating with "Posts in Sidebar" plugin

Sep 9th, 2018 (edited)
920
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.33 KB | None | 0 0
  1. /**
  2.  * Displays the star rating above the excerpt when using the Posts in Sidebar plugin
  3.  * This will only work if your pages or posts have reviews that have been assigned to them
  4.  * Since the Posts in Sidebar plugin hardcodes the text in <p> tags, we have to use
  5.  * the glsr_star_rating() function instead of the [site_reviews_summary] shortcode.
  6.  *
  7.  * Make sure to set the following widget options:
  8.  *     1. Get posts with this meta key: _glsr_ranking
  9.  *     2. Order posts by: Meta value number
  10.  *     3. The order will be: Descending
  11.  *
  12.  * Paste this code in your theme's functions.php file.
  13.  */
  14. function glsr_display_rating_in_pis_excerpt($content) {
  15.     $rating = get_post_meta(get_the_ID(), '_glsr_average', true);
  16.     $starsHtml = apply_filters('glsr_star_rating', null, $rating);
  17.     $starsHtml = str_replace(['<div', '/div>'], ['<span', '/span>'], $starsHtml);
  18.     $starsHtml = '<span class="glsr glsr-default">'.$starsHtml.'</span><br>';
  19.     return $starsHtml.$content;
  20. }
  21.  
  22. add_filter('pis_content', 'glsr_display_rating_in_pis_excerpt');
  23. add_filter('pis_excerpt_text', 'glsr_display_rating_in_pis_excerpt');
  24. add_filter('pis_more_excerpt_text', 'glsr_display_rating_in_pis_excerpt');
  25. add_filter('pis_only_read_more', 'glsr_display_rating_in_pis_excerpt');
  26. add_filter('pis_rich_content', 'glsr_display_rating_in_pis_excerpt');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement