We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Template doesn't display content based on segment conditionals

How Do I?

rjionline's avatar
rjionline
37 posts
10 years ago
rjionline's avatar rjionline

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.

       
rjionline's avatar
rjionline
37 posts
10 years ago
rjionline's avatar rjionline

Figured it out. Thanks.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.