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.

Displaying entries based on a default category

March 06, 2012 9:11am

Subscribe [2]
  • #1 / Mar 06, 2012 9:11am

    Mediakitchen

    261 posts

    I have created a simple photo gallery that has the photos categorised using the built in categories functionality.

    My template has a list of each category which acts as a link to display the photos for that particular category. This works absolutely fine.

    Problem I am encountering is that when a user first visits the gallery page, it displays the photos from all categories. I would like to be able to only display the images from the first category.

    My code to display the category links

    <ul>
     
    {exp:channel:categories channel="galleryImage" style="nested" class="category_list" sort="asc" show_empty="no" }
    
       
     <li {if count=="1"} class="first" {/if}  {if count=="{total_results}"} class="last" {/if} ><a href="http://{path=">{category_name}</a></li>
    
        
    {/exp:channel:categories}
    
    </ul>

    And my code to display the images

    <ul class="pop-up">
    
     {exp:channel:entries channel="galleryImage" limit="15" dynamic="on" }                  
    
          <li><a href="http://{galleryImage}">"]{galleryImage}</a>
    {title}</li> 
                     
                
            {/exp:channel:entries}
    
    </ul>

    Note I have tried setting one of the categories to default using

    To set a default category for a Channel you would go to Admin > Channel Administration > Channels > Edit Preferences (Your Channel Name) > Administrative Preferences

    I would prefer not to have to put the link on my site main navigation as something like

    http://www.mysite.com/index.php/gallery/category/category1

    as I do not know what the categories are in advance as this is something the client will do and they could change completely.

    Thanks in advance

     

  • #2 / Mar 06, 2012 11:53am

    zizther

    228 posts

    Have you tried using the category attribute in the channel entries call?
    http://ellislab.com/expressionengine/user-guide/modules/channel/channel_entries.html#category

  • #3 / Mar 06, 2012 11:58am

    Mediakitchen

    261 posts

    Yes I tried that but it then hard codes it to use the same category every time and ignores the dynamic URL elements.

    Thanks

  • #4 / Mar 06, 2012 12:00pm

    zizther

    228 posts

    Maybe you could use conditionals in and test against the URL segments.

  • #5 / Mar 07, 2012 1:42pm

    Dan Decker

    7338 posts

    Hi Mediakitchen,

    There are a few options available to help deal with categories in a more dynamic fashion.

    You can look at Seg2Cat which will let you translate URL segments into category IDs

    Also have a look at Solspace’s Primary Category. It allows you to assign a primary category by default in the channel entry and then call the default category for that channel in your templates using special tags.

    Cheers!

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

ExpressionEngine News!

#eecms, #events, #releases