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.

dynamically populating classes based on categories number

October 23, 2012 4:32am

Subscribe [4]
  • #1 / Oct 23, 2012 4:32am

    christinechaooo

    1 posts

    Hi,

    I’m trying to build a gallery, I have several albums and I created different categories based on my album numbers

    <div id="pictures">
        <div class="album">
            {exp:channel:entries channel="photos" category="1" orderby="entry_id" sort="asc"}
                {photo}
            {/exp:channel:entries}
        </div>
       <div class="album">
            {exp:channel:entries channel="photos" category="2" orderby="entry_id" sort="asc"}
                {photo}
            {/exp:channel:entries}
        </div>
    </div>

    so now im manually entering each category, and it’s really repetitive, is there anyway that the category number can be dynamic so i can just publish as many album without adding in the same code as below? I mean I can use javascript but is there another way to do it in EE? Thanks.

    <div class="album">
            {exp:channel:entries channel="photos" category="3" orderby="entry_id" sort="asc"}
                  {photo}
            {/exp:channel:entries}
     </div>
  • #2 / Oct 24, 2012 9:03pm

    Dan Decker

    7338 posts

    Hi Christine,

    Thanks for your question!

    ExpressionEngine can handle this dynamically if you pass category information in the URL.

    Visit Admin-> Channel Administration-> Global Preferences and set:
    Use Category URL Titles In Links? to “yes” and

    You can use the channel categories tags to build a list of your “albums” that make the links:

    {exp:channel:categories}
        <a href="http://{path=template-grouip/template/category/{category_url_title}}">{category_name}</a>
    {/exp:channel:categories}

    Now, those links will tell your channel entries tag to pull only that category - automatically!

    <div class="album">
            {exp:channel:entries channel="photos" orderby="entry_id" sort="asc"}
                {photo}
            {/exp:channel:entries}
        </div>

    If that’s not quite what you are after, let me know and we’ll work on it.

    Cheers,

  • #3 / Oct 25, 2012 12:30am

    ahmad saad

    364 posts

    if I understand what you want , you can use this code:

    <div id="pictures">
     {exp:channel:category_archive channel="photos" style="linear"}
        {categories}
                
        <div class="album">                                                     
            {exp:channel:entries channel="photos" category="{category_id}" orderby="entry_id" sort="asc"}
                {photo}
            {/exp:channel:entries}
       </div>
    
        {/categories}
    {/exp:channel:category_archive}  
    </div>
  • #4 / Oct 26, 2012 4:39pm

    Shane Eckert

    7174 posts

    Hi Christine,

    How are things going? Anything else we can help with?

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases