-
Topfgartenwelt
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 ?
-
Topfgartenwelt
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.
-
Topfgartenwelt
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.
-
Topfgartenwelt
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. -
Topfgartenwelt
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 to20
- You must be logged in to reply to this topic.