Support » Plugin: Custom Layouts - Post + Product grids made easy » How to add star rating and rating label below each post in custom layout grid

  • Resolved Valerie

    (@eve777)


    Hi,

    I’m trying to render a star rating and rating label below each recipe post title in the custom layout grid, but am really stuck.

    As I cannot see the source code, can you please tell me how to access the post id of each post in the custom layout grid?

    Once I have the post id, I can get the average rating and correct rating label, but then I’ll have to work out how to place that <p> tag under the title.

    I tried using the title filter but I don’t think this plugin is coded that way, so that didn’t work.

    If you can help me with this, I will definitely give this plugin a 5 star rating and a stellar review. πŸ™‚

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Code Amp

    (@codeamp)

    Hi Valerie

    If you use one of our filters to modify the output of an element, you should be able to get the post ID by doing (recommended):

    get_the_ID() ?

    Otherwise, this should work:

    global $post;
    $post->ID; // this is the var

    Let me know how you get on πŸ™‚

    Best

    • This reply was modified 10 months, 1 week ago by Code Amp.
    Thread Starter Valerie

    (@eve777)

    Hi,

    Thanks for replying.

    When you say “one of your filters”, can you please give me examples of filters (exact names) I can use to modify the output of each post element displayed in the custom layout grid?

    Thanks,
    Valerie

    Thread Starter Valerie

    (@eve777)

    I tried the following with both ways to get post id, but both pieces of code below only print out the id of the recipe search page, and don’t give the post ids of the posts displayed in the custom layout grid. Can you please tell me how to get this?

    add_action( 'wp_footer', 'add_rating_below_cl_result_post_title');
    
    function add_rating_below_cl_result_post_title(){
    
    	global $post;
    	$post_id = $post->ID;
    	logpprint($post_id);
    	
    }

    and

    function add_rating_below_cl_result_post_title($title){
    
    	logpprint(get_the_ID());
    	return $title;
    	
    }
    
    add_filter('the_title', 'add_rating_below_cl_result_post_title',1);

    Thanks in advance,
    Valerie

    Plugin Author Code Amp

    (@codeamp)

    Hi Valerie

    Just before I double check this, are you on the latest version (1.4.2)?

    I believe in a recent update we made these vars available in our loops – if not then I will need to track down a bug it looks like :/

    Thanks

    • This reply was modified 10 months ago by Code Amp.
    Plugin Author Code Amp

    (@codeamp)

    In regards to the filters – you can find them here:
    https://customlayouts.com/documentation/action-filter-reference/

    The one you probably want is this:
    custom-layouts/element/render_output

    This allows you to completely replace the HTML of the element.

    • This reply was modified 10 months ago by Code Amp.
    Plugin Author Code Amp

    (@codeamp)

    Also, try get_the_ID() inside this hook custom-layouts/element/render_output and let me know if it works for you?

    Thread Starter Valerie

    (@eve777)

    Yes, I’m on the latest version (1.4.2), and I’m so happy to tell you that adding my code inside the custom-layouts/element/render_output hook worked perfectly. πŸ™‚
    I was able to use get_the_ID() within that hook just fine so no bugs to report.

    Thank you so much for the amazing support and help, and of course for developing this awesome plugin. Couldn’t have done it without you.

    Thanks again,
    Valerie

    P.S. I’m just about to write a stellar review for this plugin and give it a well deserved 5 stars. πŸ™‚

    Plugin Author Code Amp

    (@codeamp)

    So glad it worked out for you πŸ™‚

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to add star rating and rating label below each post in custom layout grid’ is closed to new replies.