ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Separate layouts for channel front, categories and month archive.

January 23, 2014 2:30pm

Subscribe [2]
  • #1 / Jan 23, 2014 2:30pm

    biblio

    9 posts

    Hey there,

    I’m trying to do three different page layouts if the index template for my channel is accessed (category, year/month or none), and this is what I’ve come up with:

    {exp:channel:entries channel="blog" limit="30"}
    {if category_request}
               .... template code for categories .....
    {if:else}
        {if segment_3 == "{year}" AND segment_4 == "{month}"}
             {date_heading display="monthly"}Entries from {entry_date format="%F %Y"}{/date_heading}
             ....  template code for date stuff ....
        {if:else}
             ..... template code for frontpage (no cat or date) ....
             {exp:channel:entries channel="blog" limit="1"}
                  ....  HEADLINER CODE ....
             {/exp:channel:entries}
             
             ... some (nonchannel) stuff that can't be repeated every top loop  ...
             
             {exp:channel:entries channel="blog" limit="3" offset="3"}
                  ... SUBHEAD STYLED ENTRIES .... 
             {/exp:channel:entries}
     
             .... MORE CUSTOM (nonchannel) STUFF THAT CAN'T BE LOOPED ....
    
             {exp:channel:entries channel="blog" limit="10" offset="10"}
                .... list of entries ...
             {/exp:channel:entries}
              
        {/if}
    {/if}
    {/exp:channel:entries}

    The problem is that the frontpage code keeps getting looped from the higher loop.  Is there a way that I can just tell that the template isn’t called in categories or archive mode, and do my stuff outside the top loop? (It seems like I have to call a channel dynamically to have access to the {category_request} and {year} {month} stuff.

    Any help would be appreciated!

    M.

  • #2 / Jan 23, 2014 5:29pm

    Boyink!

    5011 posts

    Can’t you tell if it’s in category mode by the URL it appears at?  Just

    {if segment_2=="category"}

    etc?

    You will also want to read about advanced conditionals and parse order. The way you are coding the template all of those channel:entries loops are going to run, then EE will decide which to display.

    If you can use all simple conditionals then only the desired channel:entries loop will run.

  • #3 / Jan 24, 2014 3:08pm

    biblio

    9 posts

    Thanks, that does it.  My index.html template now looks something like:

    {if segment_2 == 'category'}
             {exp:channel:entries channel="mychannel"}
             ....  content ...
             {:exp:channel:entries}
    {if:elseif segment_2 == 'author'}
             {exp:channel:entries channel="mychannel"}
             ....  content ...
             {:exp:channel:entries}
    {if:elseif segment_2 == 'archives'}
             {exp:channel:entries channel="mychannel"}
             ....  content ...
             {:exp:channel:entries}
    {if:else} {!-- FRONTPAGE --}
             {exp:channel:entries channel="mychannel"}
             ....  content ...
             {:exp:channel:entries}
    {/if}

    And allows me to customize the layout.  Thanks!

    M.

  • #4 / Jan 24, 2014 3:10pm

    Boyink!

    5011 posts

    Again, that will work just keep in mind that ALL of those loops will run on every page load, no matter the URL. Then EE will figure out which one is correct and display it.

    So you are running 4x the number of queries really necessary.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases