They Call Me Marty!
Design goodness and other ramblings.

Posted on January 15th, 2010 0 Comments

Related Posts in ExpressionEngine

I wanted to implement a “Related Posts” section at the bottom of each entry in V.2 of TheyCallMeMarty. But there aren’t very many tutorials out there showing you how to do it. You would think that this is a simple process and maybe I am over thinking—so much that I might have missed it. This is how I did it, but if you have a better way to do it please share.

The solution was in using

{exp:channel:related_entries}
The code in my single entry page looks like this.
<br />
    
{exp:channel:entries channel="blog" limit="1"}</p>
<
h1>
    <
a href="#">{title}</a></h1>
<
p>
    &
nbsp{extended}<br />
    &
nbsp{comment_total}<br />
    
{/exp:channel:entries}</p>
<
div class="hr-div">
    <
hr />
</
div>
<
p>
<!--
end hr-->    <br /> 

The code simply grabs the entry title and the content inside a custom field extended.

I simply added the following code underneath the extended field:

<br />
    <!--
related entries--></p>
<
h2>
    
Related Posts</h2>
<
ul>
    &
nbsp{exp:channel:related_entries channel="blog" orderby="date" sort="desc" limit="5"&nbsp; &nbsp;
    <
li>
        <
a href="{title_permalink=" post="">{title}</a></li>
    &
nbsp{/exp:channel:related_entries} &nbsp;
</
ul>
<
p>
<!--
end related entries-->    <br /> 

In the “exp:channel:related_entries” tag, simply use the channel/weblog name that you need to pull information from (in this case I need to pull the title of entries in my “blog” channel/weblog, so I used “channel=‘blog’”). Finally I limit the query to 5 entries. Just remember to keep the “exp:channel:related_entries” tag inside your “exp:channel:entries” tag and you’re good to go.

There is probably a better way of doing this by Relating Entries to Other Entries, But after failing miserably, this was workaround.

0 Comments



What do you think?

Are you human?

Enter the image you see above