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.

Comment class/output if is guest or registered member

March 18, 2011 11:06am

Subscribe [4]
  • #1 / Mar 18, 2011 11:06am

    Jon @ Kernel

    122 posts

    I’m sure I must be missing something basic here.  I want output comments on an entry and change the output if the comment is made by a registered member.  Registered members will show avatar/link to profile etc, guests will just show their name.

    I just can’t seem to get this working with conditionals.  The following seems to get me halfway there - works perfectly for guests, but then if the user is a member, it outputs both the code blocks.  Any ideas on a quick fix?

    {exp:query sql="select member_id, screen_name, username from exp_members where screen_name = '{name}' "}
    <a href="http://{path=%22class=%22thumb" title="{author} profil" class="thumb">{if photo}{photo_url}{if:else}/images/member_photos/thumb.gif{/if}</a>
    <span class="auteur-name">
        <a href="http://{path=" title="Profil de {author}"><strong>{author}</strong></a>
        {if location}<span class="location">{location}</span>{/if}
        <span class="comment-date">{comment_date format='%D %d %M %Y'}</span>            
    </span>
    {/exp:query}
    
    <span class="auteur-name full">            
        <strong>{name}</strong>
        <span class="comment-date">{comment_date format='%D %d %M %Y'}</span>
    </span>
  • #2 / Mar 19, 2011 4:11pm

    Greg Salt

    3988 posts

    Hi Vanquished,

    I’m afraid that some of your code seems to have been stripped so I can’t see exactly what you have done. Are you trying to link to a non-member template because there is an example of how to do this in the Comment Entries documentation?

    Cheers

    Greg

  • #3 / Mar 19, 2011 9:59pm

    Jon @ Kernel

    122 posts

    Hi Greg - I was indeed trying to check whether the user posting the comment was a member or a non-member.  That tip seems to have got me 80% of the way there - thanks!

    This all seems to be working now, with the member profile picture and location shown for logged in users, and with the correct styling applied if the comment is written by author of the original author, but with one problem: the link associated with the registered member points to my (logged in) profile, not that of the commenter - i.e. the

    {username}
    tag isn’t parsing properly.  When logged out, that link points to
    <a href="http://mysite.com/bios/{username}">http://mysite.com/bios/{username}</a>

    (the word ‘username’, surrounded by curly braces, ends up in the URL itself.

    Here’s what I have so far - working perfectly apart from the fact that the username in the URL doesn’t work:

    {exp:weblog:entries limit="1" require_entry="yes" status="not pending|closed"}
        <div id="comments">
            {if allow_comments}<h3 class="sectiontitle first">{if comment_total <=1} {comment_total} commentaire{if:else} {comment_total} commentaires{/if}</h3>{/if}
        {/exp:weblog:entries}
        
            {exp:comment:entries sort="asc" require_entry="yes"}
                <div class="comment-wrap group{if entry_author_id == author_id} auteur{/if}">
            
                    <div class="commentator group">
                        
                        {if author_id != "0"}
                        
                        <a href="http://{path=%22class=%22thumb" title="{author} profil" class="thumb">{if photo}{photo_url}{if:else}/images/member_photos/thumb.gif{/if}</a>
                        <span class="auteur-name">
                            <a href="http://{path=" title="Profil de {author}"><strong>{author}</strong></a>
                            {if location}<span class="location">{location}</span>{/if}
                            <span class="comment-date">{comment_date format='%D %d %M %Y'}</span>
                        </span>
                        
                        {if:else}
                        
                        <span class="auteur-name full">
                            <strong>{name}</strong>
                            <span class="comment-date">{comment_date format='%D %d %M %Y'}</span>
                        </span>
                        {/if}
                        
                    </div>
                    
                    <div class="comment">
                        {comment}
                    </div>
                    <a href="http://{comment_url_title_auto_path}#c{comment_id}%22class=%22comment-id" title="lien permanent de ce commentaire" class="comment-id">#{comment_id}</a>
            
                </div>{!-- /.comment-wrap !--}
            {/exp:comment:entries}
        </div>{!-- /#comments !--}

    Compared to the following (repositioned weblog:entries tags), in which the usernames work, and the comments are displayed properly, but the wrong author information is being pulled (seems to think the entry author has posted all the comments):

    {exp:weblog:entries limit="1" require_entry="yes" status="not pending|closed"}
        <div id="comments">
            {if allow_comments}<h3 class="sectiontitle first">{if comment_total <=1} {comment_total} commentaire{if:else} {comment_total} commentaires{/if}</h3>{/if}
        
            {exp:comment:entries sort="asc" require_entry="yes"}
                <div class="comment-wrap group{if entry_author_id == author_id} auteur{/if}">
            
                    <div class="commentator group">
                        
                        {if author_id != "0"}
                        
                        <a href="http://{path=%22class=%22thumb" title="{author} profil" class="thumb">{if photo}{photo_url}{if:else}/images/member_photos/thumb.gif{/if}</a>
                        <span class="auteur-name">
                            <a href="http://{path=" title="Profil de {author}"><strong>{author}</strong></a>
                            {if location}<span class="location">{location}</span>{/if}
                            <span class="comment-date">{comment_date format='%D %d %M %Y'}</span>
                        </span>
                        
                        {if:else}
                        
                        <span class="auteur-name full">
                            <strong>{name}</strong>
                            <span class="comment-date">{comment_date format='%D %d %M %Y'}</span>
                        </span>
                        {/if}
                        
                    </div>
                    
                    <div class="comment">
                        {comment}
                    </div>
                    <a href="http://{comment_url_title_auto_path}#c{comment_id}%22class=%22comment-id" title="lien permanent de ce commentaire" class="comment-id">#{comment_id}</a>
            
                </div>{!-- /.comment-wrap !--}
            {/exp:comment:entries}
        </div>{!-- /#comments !--}
    
        {/exp:weblog:entries}
  • #4 / Mar 21, 2011 10:11am

    Sue Crocker

    26054 posts

    Hi, Vanquished.

    Please note that the comment entries tag should not typically be nested inside of a standard {exp:weblog:entries} tag.

  • #5 / Mar 21, 2011 10:19am

    Jon @ Kernel

    122 posts

    Hi Sue - that’s why I posted the first code block in which comment:entries is outside the weblog:entries tag.  I believe {if allow_comments} doesn’t work unless it’s inside {weblog:entries}?

    Any ideas?

  • #6 / Mar 22, 2011 4:30am

    John Henry Donovan

    12339 posts

    Vanquished,

    That’s cool. Just stick to the un-nested version.

    I can’t see your correct path variable but {author_id} is what you need to use as Greg linked to and not {username}

    <a href="http://example.com/index.php/member/{author_id}/%22class=%22thumb" title="{author} profil" class="thumb">{if photo}{photo_url}{if:else}/images/member_photos/thumb.gif{/if}</a>

    Does that help?

  • #7 / Mar 22, 2011 9:46am

    Jon @ Kernel

    122 posts

    Thanks John - author_id works, but the issue is that my member profile page isn’t located at /bios/xxxx/, but rather /bios/username/, so I need to be able to pull the username.  I can’t understand why the following would work perfectly in the title of the single entry to link to the author page by {username}, but not in the comments, hence why I was trying to nest a weblog:entries tag to pull the username as well:

    <div class="heading group">
                    <div class="title group{if photo} photo-ok{/if}">
                        <h2 class="single-title">{title}</h2>
                        {if photo}
                        <a href="http://{path=class=authorimage">_                    {exp:imgsizer:size src="{photo_url}" width="58" height="58" remote="off"}{sized}{/exp:imgsizer:size}_                    </a>
    
                        {/if}
                        <ul class="article-details">
                            <li class="auteur"><a href="http://{path=">{author}</a></li>
                            <li class="date">{entry_date format="%j %F %Y"}</li>
                        </ul>
                    </div>
                </div>
  • #8 / Mar 22, 2011 5:03pm

    Sue Crocker

    26054 posts

  • #9 / Mar 22, 2011 5:22pm

    Jon @ Kernel

    122 posts

    Thanks Sue - didn’t spot that before, but looks like it’s working now.  Thanks to all of you for the help.

  • #10 / Mar 23, 2011 10:29am

    Sue Crocker

    26054 posts

    Glad you were able to figure out what the problem was. Don’t hesitate to post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases