PaternitEE

Find the parents of children from multiple relationships.

Imagine a world where you don't need native categories anymore.

Native categories suck and many ExpressionEngine developers are turning to alternative solutions such as using relationships field.

Finding the entries related to a category using this method is fairly simple. But relationships are messy and when it comes to multiple relationships fields linking multiple parents and children you might end up on Maury Povich awaiting the results of a paternity test.

Enter PaternitEE. With a simple template tag similar to exp:channel:entries or a set of GET variables you can filter and find the parent entries of your relationship children and work with them in the same way you would any other entries in ExpressionEngine.

{exp:paternitee:entries}

The {exp:paternitee:entries} provides the core functionality for PaternitEE. Used in place of a {exp:channel:entries} tag, it will allow you to filter entries by multiple Relationship children, either in the template parameters or dynamically through GET parameters.

Parameters

The entries tag accepts some of the Channel Entries parameters. Generally any parameters that filter the channel entries tag (like category or author_id) will not work with PaternitEE.

Additionally, it accepts the following new parameters:

field:custom_field_name

  • The name of any Relationships field. The value can be either a URL Title or an Entry ID.
  • Note: All filters, whether they are passed in through tag parameters of through GET parameters are AND filters, meaning the entries returned match all filters.

use_get

  • Determines if PaternitEE will accept GET parameters for field names. Defaults to no.
  • optional
  • Values are either yes or no
  • With use_get = "yes" set, the {exp:paternitee:entries} tag will dynamically filter based off of field names in the URL query string. For example, the URL http://example.com/blog?category=news would add a filter to the tag equivalent to the parameter field:category = "news"
  • Note: All filters, whether they are passed in through tag parameters of through GET parameters are AND filters, meaning the entries returned match all filters.

allow_unknown_params

  • Controls whether unknown dynamic parameters should be ignored or return no results. Defaults to no
  • Values are either yes or no
  • When set to yes, dynamic parameters for nonexistent fields will not prevent results from being returned by the {exp:paternitee:entries} tag. This is useful when other GET parameters are needed aside from those being used for relationship filters.

results_with_no_filters

  • Controls whether to return all results or return no results when no filters are specified, useful when using query string filters. Defaults to no
  • Values are either yes or no
  • When set to yes and there are no filters specified in the tag or in the query string (when use_get is in use), all results based on the other tag parameters will be returned. Otherwise the tag will return no results.

Variables

All of Channel Entries variables.

The {exp:paternitee:entries} tag does not add any additional variables to the entries loop.


Examples

Relationships for Categories

The following is an example of basic usage for PaternitEE with a Relationships field using relationships to build categories.

In this scenario we have two channels: Blog and Categories. Blog is populated with a number of blog entries featuring a body textarea field and a Relationships field tied to Categories while Categories will have no fields.

The Blog channel fields in this example are set up like this:

Field Name Field Short Name Field Type
Body blog_body Textarea
Categories blog_category Relationships - tied to Categories channel

The following code block will display the Title, Entry ID and Body of any Blog entry with a Category relationship to Category 1 and Category 2. It does so by using the the blog_category field name in the field parameters, setting the value for each respective parameter to the URL Title of the Category that we want to filter by.

<ul>
	{exp:paternitee:entries 
		channel="blog"
		field:blog_category="category-1"
		field:blog_category="category-2"
	}
		{if no_results}
			Sorry there are no results.
		{/if}
		<li>
			{title} - {entry_id}
{blog_body} </li> {/exp:paternitee:entries} </ul>

Relationships for Categories with Dynamic Filtering

The following is an example of basic usage for PaternitEE with a Relationships field using relationships to build categories.

The scenario is the same as the above example except now we want to add the ability to filter based on GET parameters as well.

The code below is almost identical except we've removed the second field parameter and can now access it via the URL by adding the use_get = "yes" parameter to the tag. An example URL that would filter any entries that also have a category of Category 2 would look something like this: www.example.com/category_template?blog_category=category-2

<ul>
	{exp:paternitee:entries 
		channel="blog"
		field:blog_category="category-1"
		use_get = "yes"
	}
		{if no_results}
			Sorry there are no results.
		{/if}
		<li>
			{title} - {entry_id}
		</li>
	{/exp:paternitee:entries}
</ul>
		  		

{exp:paternitee:entry_ids}

The {exp:paternitee:entry_ids} tag is identical to {exp:paternitee:entries}, except that it only provides one variable, {entry_ids} containing a pipe-separated list of entry ids, rather than returning the full channel entries results.

The following code example will return the exact same results as the first example using the {exp:paternitee:entries} tag, except it feeds the {entry_ids} variable to a standard {exp:channel:entries} tag instead. Practically speaking this example is unnecessary, but you can feed the {entry_ids} variable to any module's tag that accepts a pipe-separated list of entry_ids.

<ul>
	{exp:paternitee:entry_ids 
		channel="blog"
		field:blog_category="category-1"
		field:blog_category="category-2"
	}
		{exp:channel:entries
			dynamic="no"
			entry_id="{entry_ids}"
		}

			{if no_results}
				Sorry there are no results.
			{/if}
			<li>
				{title} - {entry_id}
{blog_body} </li> {/exp:channel:entries} {/exp:paternitee:entry_ids} </ul>

{exp:paternitee:get_pagination_url}

The {exp:paternitee:get_pagination_url} tag assists in paginating entries when using the use_get="yes" parameter on the {exp:paternitee:entries} tag. Since ExpressionEngine's pagination doesn't pass through GET parameters by default, this template tag will append the current query string onto the end of your pagination URLs.

Parameters

url

  • Set the URL parameter to the value of the pagination URL.
  • Should always be set to url="{pagination_url}"

Variables

This tag has no variables


Examples

Pagination

{paginate}
<div class="pagination">
  <p>Page
    {pagination_links}
      {page}
        <a href="{exp:paternitee:get_pagination_url url="{pagination_url}"}">
          {pagination_page_number}
        </a>
      {/page}
    {/pagination_links}
  </p>
</div>
{/paginate}
		  		

{exp:paternitee:kids}

The {exp:paternitee:kids} tag is useful when listing a single entry's children, for example, listing all the category entries selected for a given blog post. This tag adds a field_name variable, which enables easy linking to category pages when using the use_get = "yes" parameter on the {exp:paternitee:entries} tag.

Parameters

entry_id (required)

  • Sets the entry to be used.
  • Note: This tag only supports a single entry at a time.
  • In many cases, this tag will be used inside a {exp:paternitee:entries} or {exp:channel:entries} tag. Because of the nature of the queries used, be mindful of the number of times this tag is called within a given template. In a template listing many entries, the tag may add a significant amount of queries.

prefix

  • Sets a prefix for variables inside the {exp:paternitee:kids} tag. When a prefix is set, all variables are accessed as prefix:variable_name.
  • Note: Since the {exp:paternitee:kids} tag extends the {exp:channel:entries} tag, we strongly recommend using the prefix="" parameter whenever using this tag in order to avoid variable conflicts with any surrounding tags.

field

  • Limits the listing of child entries to a specific field in the parent entry.
  • Can be any valid field short name that is assigned to the parent entry's channel.

disable

  • To minimize database queries, the disable="" parameter for this tag defaults to categories|member_data|pagination|custom_fields, which should work in most cases when simply listing the titles of child entries and linking to them. This can be overridden in the template as needed, but we recommend keeping it as restrictive as is feasible for your use case.

Variables

This tag has no variables


Examples

Display the categories assigned to a blog entry on the blog's single-entry template

{exp:channel:entries channel="blog" limit="1"}
	<h2>{title}</h2>
	
	<h3>Categories</h3>

	<ul>
		{exp:paternitee:kids
			entry_id="{entry_id}"
			prefix="kids"
		}
			<li><a href="{path="blog/list"}?{kids:field_name}={kids:url_title}">{kids:title}</a></li>
		{/exp:paternitee:kids}
	</ul>	
{/exp:channel:entries}
		  		

Changelog

1.5 - April 26, 2016

Updated to allow compatibility with ExpressionEngine 3.x

Removed field_type parameter, since Playa is not available for ExpressionEngine 3.x.

1.1 - May 15, 2014

Added {exp:paternitee:entry_ids} tag.

Added results_with_no_filters parameter.

1.0

Initial release.

Support

Support is available through our support forums on Devot:ee.