x
 
Create New Page
 View Previous Changes    ( Last updated by Sue Crocker )

Recent Comments

Someone was asking on the forums how to have a list of recent comments on their page (not a single-entry page by the way) but have multiple comments showing which are linking to multiple weblogs. Normally you would either have the comment tag on a single-entry page like the documentation states or you would just have them all link to the same template and utilise the same fields to get the desired effect.

The problem arises if you have multiple weblogs with comments and you want to link to different pages for each weblog / comment.

This is pretty simple to overcome using the {weblog_id} variable which is the only thing that we can use here to achieve the desired effect.

The code :

{exp:comment:entries sort="desc" orderby="date" limit="6" dynamic="off" weblog="blog|news"}

{if weblog_id
== "1"}
<p><a href="{title_permalink="blog/detail"}" title="Blog Post">{title}</a></p>
{/if}

{if weblog_id
== "2"}
<p><a class="footerLinks" href="{title_permalink="news/detail"}" title="News Post">{title}</a></p>
{/if}

{
/exp:comment:entries}

You will need to exchange the weblog_id == “1” and weblog_id == “2” ids for the id numbers of your own weblogs and also the weblog="blog|news” for the names of your weblogs but that should get the desired effect!

Hope that helps some people out somewhere.

By the way this is useful if you want a list of recent comments on any page and not just a single-entry page and you want the comments to link to a template based upon their respective weblog.

Any extra ideas, comments to this gladly appreciated.

Mark

Category:HowTo

Categories: