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.

Using {switch} with EE categories. Will it work?

June 23, 2007 9:54pm

Subscribe [3]
  • #1 / Jun 23, 2007 9:54pm

    Louis L.

    13 posts

    Hello I was wondering if {switch} can be used with

    {exp:weblog:categories weblog="{my_weblog}" style="linear"}
    <a href="http://{path={my_template_group}/index}">{category_name}</a>
    {/exp:weblog:categories}

    I’ve been trying but all I get is an empty “div” like below when the page is rendered.

    <div class=””>Category name</div>

    I did something like this with {switch} but I’m not even sure it will work.

    {exp:weblog:categories weblog="{my_weblog}" style="linear"}
    <div class="{switch optionone|optiontwo|optionthree}">
    <a href="http://{path={my_template_group}/index}">{category_name}</a></div>
    {/exp:weblog:categories}

    Basically I was trying to give each category a different color using the switch. Any suggestions or feedback on what I could be missing would be greatly appreciated.

  • #2 / Jun 24, 2007 2:12am

    Martin Hipp

    3 posts

    I do believe it works, you’ve just got a typo in your third code example, it should look like this:

    {exp:weblog:categories weblog="{my_weblog}" style="linear"}
    <div class="{switch="optionone|optiontwo|optionthree"}">
    <a href="http://{path={my_template_group}/index}">{category_name}</a></div>
    {/exp:weblog:categories}
  • #3 / Jun 24, 2007 7:54am

    Louis L.

    13 posts

    Thanks Martin, but from what I read this morning on the boards… You cannot use {switch} with the exp:cats tag. The typo was just cutting and pasting to the forums.

    I’ve tried every which way bit switch does not work. Too bad I thought it would be a handy option in the cats case.

  • #4 / Jun 24, 2007 9:11am

    Boyink!

    5011 posts

    Take a look at the “switchplus” plug-in referenced in this thread.

  • #5 / Jun 24, 2007 12:12pm

    Louis L.

    13 posts

    Take a look at the “switchplus” plug-in referenced in this thread.

    Hey Boyink thanks for the “switchplus” link. But it still wont work for some reason. Now I was looking at the file itself to see if I needed to edit something but did not see anything that mentioned modifying the file.

    Right now it looks like this:

    {exp:switchplus values="cat1|cat2|cat3|cat4|cat5|cat6|cat7|cat8|cat9|cat10"}
    
    {exp:weblog:categories weblog="{master_weblog_name}" style="linear"}
    
    <div class="{switchplus}"><a href="http://{path={master_weblog_name}/index}">{category_name}</a></div>
    
    {/exp:weblog:categories}
    
    {/exp:switchplus}

    When I view it though it still shows up empty, like so:

    <div class=""><a href="http://mysite.com/blog/cat/news/">News</a></div>
    
    <div class=""><a href="http://mysite.com/blog/cat/blogging/">Blogging</a></div>
    
    <div class=""><a href="http://mysite.com/blog/cat/web/">Web</a></div>

    For some reason it’s not clear to me why it wont work. I’ve been trying to move the links in and out of the ee tags but no dice. Right now I’m going to redo the cat code and see if there is a typo, or missing link somewhere. Thanks again for your help.

  • #6 / Jun 24, 2007 6:29pm

    Martin Hipp

    3 posts

    Have you tried to have the SwitchPlus tags inside the Weblog tags:

    {exp:weblog:categories weblog="{master_weblog_name}" style="linear"}
    {exp:switchplus values="cat1|cat2|cat3|cat4|cat5|cat6|cat7|cat8|cat9|cat10"}
    <div class="{switchplus}"><a href="http://{path={master_weblog_name}/index}">{category_name}</a></div>
    {/exp:switchplus}
    {/exp:weblog:categories}
  • #7 / Jun 26, 2007 9:26am

    Louis L.

    13 posts

    Have you tried to have the SwitchPlus tags inside the Weblog tags:

    {exp:weblog:categories weblog="{master_weblog_name}" style="linear"}
    {exp:switchplus values="cat1|cat2|cat3|cat4|cat5|cat6|cat7|cat8|cat9|cat10"}
    <div class="{switchplus}"><a href="http://{path={master_weblog_name}/index}">{category_name}</a></div>
    {/exp:switchplus}
    {/exp:weblog:categories}

    I’ve tried every way I can think of. Inside, outside, etc. It just comes up empty. I going to do another search here and see what I can find.

  • #8 / Jun 26, 2007 10:56am

    Boyink!

    5011 posts

    Here’s the code I’m using - a bit more complex as I use it with different weblogs, and made the switch value a variable so I could change the starting color as desired:

    <ul>
    {exp:switchplus values="{embed:the_switch}"}
        {exp:weblog:categories weblog="{embed:the_weblog}" dynamic="off"  show_empty="no" style="linear"}
            <li class="{switchplus}">
                <a href="http://{path={embed:the_category_template}}" title="{exp:replace find="><span class="capitalize">{exp:replace find="-" replace="SPACE"}{category_name}{/exp:replace}</span><br>_            {if category_description}<span class="weblog_meta">{category_description}</span>{/if}</a>
            </li>
        {/exp:weblog:categories}
    {/exp:switchplus} 
    </ul>
  • #9 / Jun 26, 2007 1:18pm

    Louis L.

    13 posts

    Boyink

    I’m going to assume you did the following with “switchplus.”

    1. DL the plugin.
    2. Uploaded it (the pi.switchplus.php file) to the plugins folder.
    3. Added the switchplus code to your templates.

    Which at this time is exactly what I’ve done. Can you verify that i do not need to edit/add anything to the “pi.switchplus.php” file itself?

    When I get home from work today I’m going to make a couple of examples to see how each work. Also I’m going to take a look at the code snippet you have here for reference.

  • #10 / Jun 26, 2007 2:24pm

    Boyink!

    5011 posts

    Yes - that’s all I did, and no, I didn’t edit the code for the plugin.

    What kind of page are you using this on—does the category tag return categories without using the switchplus?

    If not - have you tried the dynamic=“off” parameter?

  • #11 / Jun 26, 2007 3:17pm

    Louis L.

    13 posts

    Right now my code looks like this:

    {exp:switchplus values="cat1|cat2|cat3|cat4|cat5|cat6|cat7|cat8|cat9|cat10"}
    
    {exp:weblog:categories weblog="{master_weblog_name}" style="linear"}
    
    <div class="{switchplus}"><a href="http://{path={master_weblog_name}/index}">{category_name}</a></div>
    
    {/exp:weblog:categories}
    
    {/exp:switchplus}

    And this is how the “index.php” page shows the list. As you can see each class is empty. The categories show, but without switchplus.

    <div class=""><a href="http://mysite.com/blog/cat/news/">News</a></div>
    
    <div class=""><a href="http://mysite.com/blog/cat/blogging/">Blogging</a></div>
    
    <div class=""><a href="http://mysite.com/blog/cat/web/">Web</a></div>

    I will add the “dynamic=“off” parameter” as you mentioned and test it out.

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

ExpressionEngine News!

#eecms, #events, #releases