• Resolved prowebdesign.ro

    (@prowebdesignro)


    I would like to use the plugin for a client’s project. One thing that is required is displaying the aggregate rating on post excerpts in post archives. I am using the Comment Rating feature. What I am looking for is a php function/snippet that I can use in the archive template and other places too. Can’t seem to find it in the documentation. Could you help?

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Brecht

    (@brechtvds)

    You can use this shortcode to display the rating, for example:
    [wprm-recipe-rating]

    There are a bunch of different shortcodes with different attributes. The easiest way to get a shortcode is to use our Template Editor, add the block you want and set the options you need. Then you’ll find the shortcode under “Edit HTML”.
    https://help.bootstrapped.ventures/article/53-template-editor

    It’s also possible to access the recipes through code:
    https://help.bootstrapped.ventures/article/110-access-recipes-in-a-post-via-code

    Thread Starter prowebdesign.ro

    (@prowebdesignro)

    Thank you!
    The “Access via code” article was just what I needed.

    If you access the demo link, you’ll see that the post outputs the average rating now: https://www.prowebdesign.ro/clientwp3/index.php/category/dutch-oven-and-camping-recipes/

    I have another question though: how do I output the stars? I could write a simple else/if loop, but I suppose this already exists in plugin functions somewhere. I mean the function that outputs stars based on average rating. I just can’t find it. Could you help?

    My code is
    $recipes = WPRM_Recipe_Manager::get_recipe_ids_from_post();

    // Access the first recipe, if there is one.
    if ( isset( $recipes[0] ) ) {
    $recipe_id = $recipes[0];
    $recipe = WPRM_Recipe_Manager::get_recipe( $recipe_id );

    // Output the recipe name.
    echo ‘<div class=”alert alert-info”><div>RECIPE NAME: ‘.$recipe->name().'</div>’;
    $myrating = $recipe->rating();
    echo ‘<div>RECIPE NAME: ‘.$myrating[“average”].'</div></div>’;
    }

    Plugin Author Brecht

    (@brechtvds)

    Happy to hear that worked for you!

    Well the easiest way to display the stars is using that [wprm-recipe-rating display=“stars”] shortcode, actually. You could specify id=“123” as an attribute there as well.

    Thread Starter prowebdesign.ro

    (@prowebdesignro)

    I totally forgot that you can do the do_shortcode in php templates! Silly me:)). Thank you, solved!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Displaying aggregate star rating on post rchive’ is closed to new replies.