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.

{count} in comments always seems to be "1"

July 04, 2007 12:28pm

Subscribe [5]
  • #1 / Jul 04, 2007 12:28pm

    mrwarren

    31 posts

    Seems like things just don’t add up sometimes! I’m always getting “1” when I use {count} here:

    {exp:comment:entries sort="asc" }
       <li id="{comment_id}">
        {comment}
        
          {count} By {url_as_author} on {comment_date format="%d/%m/%Y"}
        
       </li>
    {/exp:comment:entries}

    I’ve tried {absolute_count} and I get the same thing. What glaring error am I just not noticing?

    Thanks a ton for your help!

  • #2 / Jul 04, 2007 12:45pm

    silenz

    1651 posts

    When there are more than one comments for that weblog-entry, you get “1” for every comment?

    Is the {exp:comment:entries}-tag nested inside a {exp:weblog:entries}-tag by any chance?

  • #3 / Jul 04, 2007 1:00pm

    Derek Allard

    3168 posts

    Silenz thought of the first thing I did also.  Sounds like a nesting issue.  If it is inside of an entries tag, try moving it out, if not, could you post your full template?

  • #4 / Jul 04, 2007 1:00pm

    mrwarren

    31 posts

    Ahh, I see, if I take the comment entries tag outside the weblog entries tag, the problem goes away, but then it screws up a ton of other conditionals and make the whole thing less clean. That’s ok. I’ll just resort to using php to make the count. Thanks for pointing me in the right direction, I appreciate it.

  • #5 / Jul 04, 2007 1:01pm

    Derek Allard

    3168 posts

    My pleasure.  Thanks silenz also for dropping in.  Good catch.

  • #6 / Jul 04, 2007 1:39pm

    Derek Jones

    7561 posts

    mrwarren, you might post the entire weblog entries tag, including your nested comments tag.  They are not designed to be nested, and makes it very difficult to provide support for you, and could potentially break functionality for you in future updates.  If you post what you’re doing, we can likely provide alternative solutions to your conditional and markup needs without having to nest the comment tag.

  • #7 / Jul 04, 2007 5:19pm

    mrwarren

    31 posts

    Derek,
    thanks for the offer. It’s ok. I moved the comment entries out of the weblog entries tag. I used a little bit of php to fix allt he conditionals. It was more work, that’s why I wasn’t going to do it before, but since you gave me a perfectly good reason to actually do it, I figured it’d be worth it.

  • #8 / Jul 04, 2007 5:27pm

    Derek Jones

    7561 posts

    If you have time, I’d still like to see it.  If what you did is great, then other users could benefit.  And if there are ways that we could simplify it, by perhaps alerting you to options, variables, or tags that you aren’t aware of, then that would be helpful for you as well.

  • #9 / Jul 04, 2007 5:50pm

    mrwarren

    31 posts

    Gotcha. Glad to. Ironically i used my php that I had used to calculate comment count to check for if I should add the opening and closing tags for the comment list.  I’m sure the collective mind would have a suggestion or two for me to simplify.

    {exp:weblog:entries weblog="blog"}
            <div class="hentry {weblog_short_name}">
                <h2 class="entry-title"><a href="http://{link-url}">{title}</a></h2>
                <div class="meta">    
                    <abbr title="%Y-%m-&amp;#xd;T;%H:%i:%s%Q">{entry_date format="%d %F, %Y"}</abbr>
                     • <a href="http://{title_permalink=article}" rel="bookmark" class="permalink">Permalink</a>
                </div>
                <div class="entry-summary">
                    {desc}
                </div><!-- //Entry-Summary -->        
            </div><!-- //ENTRY -->
    
            {if allow_comments OR "{comment_total}" > 0}
                <h3 id="comment">Comments</h3>
            {/if}
    
    {/exp:weblog:entries}
        <? $commentcount=1; ?>        
        {exp:comment:entries sort="asc" }
          <? if($commentcount==1) echo "<ol id=\"comment-list\">"; ?>
           <li id="{comment_id}" class="commentauthor{author_id}">
            {comment}
                 
                   <a href="#{comment_id}" class="commentid">§ </a> 
                    #<? echo $commentcount; $commentcount++; ?> By {url_as_author} on {comment_date format="%d/%m/%Y"}
                 
           </li>
        {/exp:comment:entries}
        <? if($commentcount!=1) echo "</ol>"; ?>
    
        {exp:comment:form}
            <dl>
            {if logged_out}
                <dt>Name</dt>
                <dd><input type="text" class="form-text" name="name" value="{name}" size="50" /></dd>
    
                <dt>Email (required but private)</dt>
                <dd><input type="text"  class="form-text" name="email" value="{email}" size="50" /></dd>
            
                <dt>Location</dt>
                <dd><input type="text"  class="form-text" name="location" value="{location}" size="50" /></dd>
            
                <dt>URL</dt>
                <dd><input type="text"  class="form-text" name="url" value="{url}" size="50" /></dd>
                {if captcha}
                <dt>Please enter the word you see in the image below:</dt>
                <dd>{captcha}
    
                <input type="text" name="captcha" value="{captcha_word}" size="20" maxlength="20" style="width:140px;" /></dd>
                {/if}
            {/if}
            <dt>Comment</dt>
            <dd><textarea name="comment"  class="form-text form-area" >{comment}</textarea></dd>
            
            <dd><input type="checkbox" name="save_info" value="yes" {save_info} /> Remember my personal information</dd>
            
            <dd><input type="checkbox" name="notify_me" value="yes" {notify_me} /> Notify me of follow-up comments?</dd>
            
            <dt><input type="submit" name="submit" value="Submit" />
            <input type="submit" name="preview" value="Preview" /></dt>
        
        {/exp:comment:form}
  • #10 / Jul 04, 2007 5:59pm

    Derek Jones

    7561 posts

    Yep, few modifications for you, and we can get rid of the PHP altogether!

    ——————————————————-

    Change this:

    {if allow_comments OR "{comment_total}" > 0}
        <h3 id="comment">Comments</h3>
    {/if}

    to:

    {if allow_comments == 'y' OR comment_total > 0}
        <h3 id="comment">Comments</h3>
    {/if}

    ——————————————————-

    And replace this:

    <? if($commentcount==1) echo "<ol id=\"comment-list\">"; ?>

    With:

    {if count == 1}<ol id="comment-list">{/if}

    ——————————————————-

    And this:

    <? echo $commentcount; $commentcount++; ?>

    with simply:

    {count}

    ——————————————————-

    And this:

    <? if($commentcount!=1) echo "</ol>"; ?>

    With this, inside the tag, right before {/exp:comment:entries}:

    {if count == total_results}</ol>{/if}

    And lastly you can drop the rest of the PHP. :-D

  • #11 / Jul 04, 2007 6:01pm

    mrwarren

    31 posts

    Most excellent! No php and a tiny bit simpler. In record time!

    EDIT: Thanks a bunch!

  • #12 / Jul 04, 2007 6:13pm

    Derek Jones

    7561 posts

    You’re most welcome, glad you got it working like you wanted.

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

ExpressionEngine News!

#eecms, #events, #releases