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.

Displaying # of comments on single entry pages

December 05, 2009 2:23pm

Subscribe [3]
  • #1 / Dec 05, 2009 2:23pm

    arilyn

    8 posts

    I’m having a lot of trouble getting the following to work properly.

    {exp:channel:entries channel="mwblog" limit="1" disable="member_data|pagination|trackbacks"}
    <div class="box a">
        <h1>{title}</h1>
        <div class="meta">by <a href="http://{profile_path=member}">{author}</a> on {entry_date format="%F %j%S, %Y"}</div>
        {body}
    </div><!--entry-->
    {/exp:channel:entries} 
    
    <ul id="comments" class="box comments">
        <h3>{total_comments} Comments <a href="#add-commentid=right">Add yours</a></h3>
    <p>    {exp:comment:entries channel="mwblog"}<br />
        <li class="comment"><br />
            <a href="http://{permalink}class=count">{count}</a><br />
            {comment}<br />
            by {url_or_email_as_author} on {comment_date format="%F %j%S, %Y at %g:%i%a"}<br />
        </li><!--comment--><br />
        {/exp:comment:entries}<br />
    </ul>

    The problem I’m having is that {total_comments} is showing the total comments for the entire site, not just the specific entry. Moving {total_comments} inside {exp:comment:entries} works, but that <h3> ends up getting repeated for every single comment.

    {comment_total} works if I move ul#comments inside the {exp:channel:entries}. However, that makes {count} show the id for the entry instead of the ids for the comments.

    I’m also looking for a conditional that will hide ul#comments when there are zero comments on an entry. I tried using {if total_comments > 0}{/if}, but that seems to hide ul#comments in all cases.

    Thanks for any help.

  • #2 / Dec 05, 2009 4:43pm

    Herb

    224 posts

    I know this doesn’t solve the problem completely; but you can put opening html inside:

    {if count == 1}put html here that should precede entries{/if}

    and then you can place closing html inside:

    {if count == total_results}put html here that should follow entires{/if}

    Then you can nest your tags to get what you need.

  • #3 / Dec 06, 2009 1:40am

    arilyn

    8 posts

    I figured out a hackish solution to my problem.

    {exp:channel:entries channel="mwblog" limit="1" disable="member_data|pagination|trackbacks"}
    <div class="box a">
        <h1>{title}</h1>
        <div class="meta">by <a href="http://{profile_path=member}">{author}</a> on {entry_date format="%F %j%S, %Y"}</div>
        {body}
    </div><!--entry-->
    
    {if comment_total > 0}
    <ul id="comments" class="box comments">
        <h3>{comment_total} Comment{if comment_total != 1}s{/if}{/exp:channel:entries}<a href="#add-commentid=right">Add yours</a></h3>
    <p>    {exp:comment:entries channel="mwblog"}<br />
        <li id="{count}" class="comment"><br />
            <a href="http://{permalink}class=count">{count}</a><br />
            {comment}<br />
            by {url_or_email_as_author} on {comment_date format="%F %j%S, %Y at %g:%i%a"}<br />
            {if avatar}<br />
                {avatar_url}<br />
            {/if}<br />
        </li><!--comment--><br />
        {/exp:comment:entries}<br />
    </ul><br />
    {/if}

    I moved {/exp:channel:entries} to after {comment_total}, which fixes the {comment_total} showing the number of site-wide comments problem. With {comment_total} working correctly, I was able to finally use the simple conditional {if comment_total > 0} to hide the comment display when there are zero comments.

  • #4 / Dec 06, 2009 12:32pm

    Focus Lab Dev Team

    1129 posts

    That’s not hackish at all. That SOP.

  • #5 / Feb 27, 2010 5:48pm

    briankalwat

    50 posts

    You can also use this conditional within your comment count, so when there is only one comment, the plurality is dropped. I wanted to add this to the user guide, but I don’t have enough posts… so if an ambitious moderator happens to see this… that’d be great!

    {comment_total} {if comment_total == "1"}Comment{if:else}Comments{/if}
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases