ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Listing Comments For Related Entry

October 28, 2009 6:32am

Subscribe [2]
  • #1 / Oct 28, 2009 6:32am

    Frychiko

    79 posts

    I am having trouble with listing comments for a related entry (different from my last comment issue).

    I have various (product) models and they are all categorized / linked to the same product under which they fall. ie. Product = Sony PS3. Models = PS3 120GB, PS3 160GB etc. On the frontend, people can comment under each model, but in the backend, the comments get associated with the product rather than each individual model.

    So what I do is this below:

    {related_entries id="db_model_product"}
    
    <!-- comments section -->
    {embed="templates/comments" 
    entryid="{entry_id}"  <!-- entry_id of product (ie. PS3) -->
    total_comments="?????"
    weblog="db_product"
    }
    
    {/related_entries}

    And with that template I can list all the comments that fall under a certain product.

    Problem is I cant figure out how to conditionally display the comments. I only want to display comment info if {comment_total} > 0, but I don’t have access to that info outside of the template.

    What would be a good way to access this variable?

  • #2 / Oct 28, 2009 9:47am

    Sue Crocker

    26054 posts

    You’d need to use the query module to bring back comment_total from exp_weblog_titles by passing in {entry_id} and use that result to do the rest of your embed.

    Does that help?

  • #3 / Oct 28, 2009 10:05am

    Frychiko

    79 posts

    Hi Sue,

    Thanks for that, it works! The only thing I had to do was rename comment_total to get any result.

    {exp:query sql="SELECT comment_total as comments FROM exp_weblog_titles WHERE entry_id = '{entry_id}' "}
    
    <!-- comments section -->
    {embed="templates/comments" 
    entryid="{entry_id}"
    comment_total="{comments}"
    weblog="db_product"
    }
    
    {/exp:query}
  • #4 / Oct 28, 2009 10:14am

    Sue Crocker

    26054 posts

    Glad that worked. 😊 Don’t hesitate to post again as needed.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases