Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Show star rating on archiv pages

  • Hi 🙂

    I want to show the star rating on my recipe archiv pages. Therefore I have to implement that peace of code:

    echo '<article class="post-summary">';
    	echo '<a class="entry-image-link" href="' . get_permalink() . '" tabindex="-1" aria-hidden="true">' . get_the_post_thumbnail( get_the_ID(), 'small_thumbnail' ) . '</a>';
    
    	echo '<header class="post-summary__content">';
    		be_star_rating();
    		echo '<h4 class="entry-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h4>';
    	echo '</header>';
    echo '</article>';

    But where I should place that code in the theme?

    Greetings Kathrin

  • Hi there,

    can you share a link to an archive page on your site ?

  • Sure, I have added the link in the private section.

    Thank you very much!

    Greetings Kathrin

  • I don’t see anything in the private info field.

    Please confirm.

  • Next try, I hope it works now 🙂

    Greetings Kathrin

  • If the be_star_rating(); function returns the star rating for the current post object then you can:

    1. create a new Hook Element ( not a block element ).
    2. set the Hook to: generate_after_entry_title
    3. set the Display rules location to the archive pages you require it on.
    4. in the Hook editor add:

    <?php be_star_rating(); ?>

    5. check the Execute PHP option.

  • Ok, I will try it. This code should be inserted in the code snippets plugin. Do I need it also? It is the first part before the echo… :

    /**
     * Star Rating 
     * @see https://www.billerickson.net/include-recipe-rating-on-archive-pages
     *
     */
    function be_star_rating() {
    
    	// Return early if WP Recipe Maker isn't active 
    	if( ! class_exists( 'WPRM_Recipe_Manager' ) )
    		return;
    
    	global $post;
    	$recipes = WPRM_Recipe_Manager::get_recipe_ids_from_content( $post->post_content );
    	if ( isset( $recipes[0] ) ) {
    		$recipe_id = $recipes[0];
    		echo do_shortcode( '[wprm-recipe-rating id="' . $recipe_id . '"]' );
    	}
    
    }

    Greetings Kathrin

  • Yes, the code is needed for <?php be_star_rating(); ?> to work.

  • Thank you very much, it works great. Maybe it is possible to change the position. The stars should appear on the archiv pages after the featured image, but I can’t find a hook related to the featured image.

    Greetings Kathrin

  • To position it after the featured image, change the Hook to:

    generate_after_entry_header and set the Priority to 20

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.