My assistant put together a template that combines the entry list, the single-entry page and categories. The way he did it, though, won’t allow it to display a page with the list of categories, although it will list individual categories and the entries that fall into them.
I’m trying to split the categories templates out into their own templates, but for some reason, I can’t get some elements to load properly. For example, the category template, which uses a conditional to check the page’s segments, refuses to display the breadcrumbs properly, even though the same code works on the main entries page.
Here’s the code for the Categories pages (we call them ‘topics’ on the site):
{!--- stories/topics
Dynamic template that, based on URL segments, displays a list of topics
*See template main/index for more template details; only details on this specific template will be documented --}
{exp:stash:set name="site_section" type="snippet" parse_tags="yes"}stories{/exp:stash:set}
{html_head}
<title>
Topics | RJI
</title>
{head_content}
{html_head_end}
<body>
{embed="main/_navbar"}
{if segment_2 == "topics" AND segment_3 == ""}
<ol class="breadcrumb">
<li><a href="http://{site_url}">Home</a></li>
<li><a href="/stories">Stories</a></li>
<li class="active">Topics</li>
</ol>
{/if}
{if segment_2 == "topics" AND segment_3 != ""}
{exp:channel:category_heading channel="stories"}
<ol class="breadcrumb">
<li><a href="http://{site_url}">Home</a></li>
<li><a href="/stories">Stories</a></li>
<li><a href="/stories/topics">Topics</a></li>
<li class="active visible-xs-inline-block">{exp:trunchtml chars="22" exact="yes" ending="..."}{category_name}{/exp:trunchtml}</li>
<li class="active visible-sm-inline-block">{exp:trunchtml chars="100" exact="yes" ending="..."}{category_name}{/exp:trunchtml}</li>
<li class="active visible-md-inline-block visible-lg-inline-block">{category_name}</li>
</ol>
{/exp:channel:category_heading}
{/if}
<div id="main-section" class="container">
<div class="row">
<div id="primary-section" class="col-md-8 col-sm-12">
{!-- TOPIC stories -----------------------------
Both segment 2 is topics && 3 is given; should look like /stories/topics/'topic-name'
Display specified topic and its stories --}
{if segment_2 == "topics" AND segment_3 != ""}
{!-- exp:channel:category_heading allows you to grab the category you are looking at specifically --}
{exp:channel:category_heading channel="stories"}
<div class="page-header">
<h2>
{!-- Category image should be self explanatory so is used IN PLACE of category title instead with it --}
{if category_image}
{category_image}
{if:else}
{category_name}
{/if}
{if category_description}
<small>{category_description}</small>{/if}
</h2>
</div>
{/exp:channel:category_heading}
{!-- .media-list of entries, is automatically dynamic to the topic --}
<div class="card-bg">
<ul id="recent-posts" class="media-list">
{exp:channel:entries channel="stories" limit="10" disable="categories|member_data|category_fields" status="open" cache="yes" refresh="100"}
{if no_results}No results found.{/if}
{rji_media_list}
{pagination_snippet}
{/exp:channel:entries}
</ul>
</div>
{/if}
</div> {!-- ends primary section --}
<div id="sidebar" class="col-md-4 hidden-sm hidden-xs">
{!-- If we are looking at a single post, show related, and if we are listing topics, we don't need to show them again --}
{if segment_2 != "" && segment_2 != "topics" }{embed="main/_sidebar" recent="YES" events="YES" related="YES" topics="YES"}
{if:else}
{embed="main/_sidebar" recent="YES" events="YES" related="NO" topics="YES"}
{/if}
</div>
</div> {!-- ends .row --}
</div> {!-- ends #main-section --}
{page_end}The site can be viewed at https://www.rjionline.net/ if you want to see it.
Thanks.
L.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.