On our Single entry pages we recommend other articles. Four slots are available. channel: articles. channel fields: Content Elements field for the text and a native EE Relationship field called "related_articles"
Here´s the editorial workflow: After writing the article an editor can select between 0 and 4 articles manually. The EE-field "related_articles" will be used for that. All relationships are between entries of the same channel.
There are 4 slots to fill. EE will fill the empty slots automatically with articles from the same category.
An example: The editor wrote an article in the category A and manually added one related article. Then EE has to add three more category A articles to the mix.
This is my code for the editor´s picks:
{exp:channel:entries channel="article"}
{related_articles}
<p>{related_articles:title}</p>
{/related_articles}
{/exp:channel:entries}
This is my code for the stuff, that EE adds automatically.
{exp:channel:entries channel='article'
related_categories_mode='yes'
custom_fields='yes'
limit='{4 - count_of_editors_pick}'
entry_id='not {the_IDs_from_editors_pick}'
}
<p>{title}</p>
{/exp:channel:entries}
Both work well solo, but how do I combine them? I tried the math plugin plus the session variables plugin. I stored the {count} for the first loop in {rel_art}, so I know, how many articles the editor added.
{exp:math formula='4 - [1]' params='{exp:session_variables:get name="rel_art"}'}
But it seems, that I run into a parse order issue here. I can´t use this to set the limit parameter within the channel entries tag.
My questions
- How do I limit EE´s related categories loop so that it fills up the remaining slots?
- How do I avoid entry dublications? EE should not add any entries choosen by the editor.