brandnewbox.co.uk

Home of Andrew Weaver, a uk-based web developer specialised in building high-quality websites

Followers module - Part 3

Friday, January 23rd, 2009

Andrew Weaver

Category: , ,

Part 3 of this introduction to the Followers module for ExpressionEngine will show how to display a list of your friends’ entries.

The basic {exp:weblog:entries} tag allows you to use a author_id= parameter to display all entries by a particular author. Multiple authors can be selected by ‘pipe’ separating their ids (eg, author_id=“1|12|34”.

The Followers module can output your list of friends in this format, like so:

{exp:ajw_followers:display show="following" member_id="{segment_3}"}
  {if no_members}
-1{/if}
  {members backspace
="1"}{member_id}|{/members}
{
/exp:ajw_followers:display} 

But, there is a problem with supplying this list of authors to the {exp:weblog:entries} tag, as ExpressionEngine runs the {exp:weblog:entries} before the {exp:ajw_followers:display} and so it does not get the list of authors that we want.

To get around this problem we can use an embedded template.

The Solution

We put the basic code to display the list of our friends’ entries in a separate template - called for this example embed_articles_by_author

<h3>Friends articles</h3>
<
ol>
{exp:weblog:entries weblog="default_site" orderby="date" sort="desc" disable="member_data|trackbacks" dynamic="off" author_id="{embed:authors}"}
{if no_results}No articles by friends{
/if}
<li>
  <
a href="{title_permalink=home/index}">{title}</aby {author} on {entry_date format="%d/%m/%Y"}
</li>
{/exp:weblog:entries}
</ol

Notice that the author_id= parameter now contains an embed variable, {embed:authors}.

To display this list of friends’ entries, we then need to call the embedded template with the list of authors.

{embed="followers/embed_articles_by_author" authors="{exp:ajw_followers:display show="following" member_id="{segment_3}"}{if no_members}-1{/if}{members backspace="1"}{member_id}|{/members}{/exp:ajw_followers:display}"

This is just a basic embedded template call but with the {exp:ajw_followers:display} tag being used to populate the authors= parameter. (For safety’s sake, all whitespace between tags has been removed, which makes it look more comlicated than it is.)

Summary

The Followers module allows you to create and manage friend relationships between members. These relationships can be used however you wish within ExpressionEngine. Using embedded templates allows you to get around any problems due to the order which templates are parsed.

Related

Comments

1. .(JavaScript must be enabled to view this email address)
25th Feb 2009 at 8:14 pm

This is interesting. How would you do a “recent news” sort of thing. Similar to facebook newsfeed, but showing if followers have added or made changes to entries. Perhaps this is asking too much though?

2. Chuck Manson
19th Mar 2009 at 8:26 pm

I am looking for a way to have readers on our website “subscribe” to a particular author(s) posts and receive an email notification when a new post is added to the site. Could this module accomplish that or would I need some modifications? I was looking for something similar to the comments notification that is built in EE. Also, I would want to restrict this to where people could follow only certain groups of members (i.e. authors, admins, etc). Thanks.

Commenting is not available in this weblog entry.

© brandnewbox.co.uk 2004-2010