Navigation and pagination issues in ExpressionEngine - expressionengine

I’ve set up a site with eight channels divided into two sections.
One of the sections is called “Articles” and within that section there are two channels, “Features” and “News”.
Everything was working great until I introduced pagination into the equation.
On the Articles index page, I have tabs for “Latest”, “Features” and “News” and I navigate through them and select entries based on the segment:
<ul id="tabs">
<li>{if segment_2 == ''}<strong>Latest</strong>{if:else}Latest{/if}</li>
<li>{if segment_2 == 'features'}<strong>Features</strong>{if:else}Features{/if}</li>
<li>{if segment_2 == 'news'}<strong>News</strong>{if:else}News{/if}</li>
</ul>
{if segment_2 == ''}{exp:channel:entries channel="features|news" limit="10" dynamic="no" order="date" paginate="both"}{/if}
{if segment_2 == 'features'}{exp:channel:entries channel="features" limit="10" dynamic="no" order="date" paginate="both"}{/if}
{if segment_2 == 'news'}{exp:channel:entries channel="news" limit="10" dynamic="no" order="date" paginate="both"}{/if}
site.com/articles brings up all entries
site.com/articles/features/ brings up all entries in the Features channel
site.com/articles/news/ brings up all entries in the News channel
This works great until there is a channel with multiple pages and something like “P4” is added to the URL and then {segment_2} for the unfiltered index becomes P4 instead of what I am doing to navigate the channel entries.
Paginate URL:
site.com/articles/P4
I guess my question is this:
Am I navigating or filtering entries correctly? If so how would I do so now with pagination?
Thanks!

There are two possible solutions here.
You can use the paginate_base parameter to explicitly tell EE to use a specific path before the pagination argument:
{if segment_2 == 'features'}{exp:channel:entries channel="features" limit="10" dynamic="no" order="date" paginate="both" paginate_base="articles/features"}{/if}
{if segment_2 == 'news'}{exp:channel:entries channel="news" limit="10" dynamic="no" order="date" paginate="both" paginate_base="articles/news"}{/if}`
Alternately - and my preferred solution - is to create two new templates under the "articles" group, named "news" and "features", and list your entries there. You can avoid any duplication of code by turning your tab navigation (and even the markup/logic you plan on placing between your channel:entries tags, if it will be the same for each section) into snippets.

Related

ExpressionEngine: Display related entries from another channel in a single entry of one channe

I have two channels, events and news. Both have the same category group assigned (international, national, rock, etc.). I need to display a Widget of news entries that belong to the same category as the event in the single entry of the event. Something like
{exp:channel:entries channel="event" require_entry="yes"}
{!-- here the event information is displayed --}
<div class="widget"><h2>News</h2>
{exp:channel:entries channel="news" dynamic="no" category="????"}
{/exp:channel:entries}
</div>
{/exp:channel:entries}
Is this possible from within EEs or do I need a plugin/development?
Good news, EE will do this for you :)
Add related_categories_mode="yes" to the exp:channel:entries tag for the news channel then go get yourself a beer with all the time you've saved.
https://docs.expressionengine.com/latest/channel/channel_entries.html#related-categories-mode

Expression Engine Conditional Based on status of a page

I am trying to turn on and off a section of navigation based on if a published entry has a status of open or closed.
So my intent is something like:
{if particluarpage == "closed"}
content
{if:elseif}
content
{/if}
Thanks
There are a couple of ways of achieving this. The simplest option would probably be to issue a query via the query module.
{exp:query sql="SELECT status FROM exp_channel_titles WHERE entry_id = '4'"}
{if status == 'open'}
Show Block A
{if:else}
Show Block B
{/if}
{/exp:query}
Shouldn't that be something like this?
{if "{exp:channel:entries channel="yourchannel" entry_id="X"}{status}{/exp:channel:entries}" == "closed"}
content
{if:else}
content
{/if}
Maybe you'll need the dynamic="no" parameter too.

EE - How do I make the current segment active using Category Tags?

I am using the channel:categories tag to pull in categories for a section navigation. This works fine, but I also would like to tag the current active category as the active item in the navigation for styling purposes:
a class="active"
I tried two approaches neither of which works.
Attempt 1 (per the documentation):
<a {if active} class="active"{/if} href="{path='internal-staff-center/{category_url_title}'}">{category_name}</a>
Attempt 2:
<a {if segment_2 == "{category_url_title}"}class="active"{/if} href="{path='internal-staff-center/{category_url_title}'}">{category_name}</a>
I would appreciate some input from another viewpoint out there.
Thanks.
The {path} variable within Channel Categories will output a path using your category trigger word or the C(n) URL segment (C2, C15, etc). So it's doubtful that {segment_2} is actually your category_url_title ... it's more likely {segment_3}.
What is an example URL structure of these pages?
{if segment_X == category_url_title} should work so long as the comparison is correct.
Try
{if "{segment_2}" == "{category_url_title}"} class="current"{/if}

Redirect when last segment missing

I have a single entry url structure like:
www.site.com/template_group/template_1/entry_id
But I want it to be:
www.site.com/template_group/template_1/entry_id/url_title.
Entry_id would be the segment feeding exp:channel:entries. How can I redirect www.site.com/template_group/template_1/entry_id to www.site.com/template_group/template_1/entry_id/url_title.
Thanks a lot!
Something like the following should work - it's untested, but it'll give you a good idea of how to go forward with it.
{if segment_4==""}
{exp:channel:entries channel="x" limit="1" dynamic="no" entry_id="{segment_3}"}
{redirect="template_group/template_1/{entry_id}/{url_title}"}
{/exp:channel:entries}
{/if}
put this at the very top of your template:
{if segment_4 == ""}
{exp:channel:entries channel="channel_goes_here" entry_id="{segment_3}"}
{redirect="{site_url}/{segment_1}/{segment_2}/{segment_3}/{url_title}
{/exp:channel:entries}
{/if}
This will check if you have set a fourth segment, if not it takes the third segment containing your entry_id, feeds it to the channel entries tag, which returns the url_title you need. With this url_title you can easily redirect to the correct page.
Good answers from janvl and madebyhippo
Quick note if you are using complex conditionals (the ones in the answers are simple ones so you will not have that problem) is that EE will parse the channel entries tags they contain, wich can slow down performance.
If you find yourself in that situation, best to avoid the problem altogether using Mark "The croxton" addons like switchee or ifelse

Expression Engine - How do I display external links in Category Archive List?

I have a series of entries that need to be displayed as part of a Category Archive.
I did the code this way:
{exp:channel:category_archive channel="botanical_gardens" style="linear"}
{categories}
<h3>{category_name}</h3>
{if category_description}
<p>{category_description}</p>
{/if}
{/categories}
{entry_titles}
{title}<br />
{/entry_titles}
{/exp:channel:category_archive}
This works with the exception of the URL which ties into the site url. Since each of these entries link to outside sites, how do I write the code to get the correct URL?
Thanks!
Custom fields can't be displayed within the Category Archive tag. Instead, you'll have to use the Channel Categories tag, and put a Channel Entries tag within it.
{exp:channel:categories channel="botanical_gardens" style="linear" disable="category_fields"}
<h3>{category_name}</h3>
{if category_description}
<p>{category_description}</p>
{/if}
{exp:channel:entries channel="botanical_gardens" category="{category_id}" disable="member_data|pagination|categories"}
{title}<br />
{/exp:channel:entries}
{/exp:channel:categories}

Resources