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.

Get the current category from a weblog

December 11, 2008 8:20am

Subscribe [3]
  • #1 / Dec 11, 2008 8:20am

    hildreth

    12 posts

    Is there a way to output the current category from a weblog tag? I am trying to build a breadcrumb nav and I have been able to get the category heading when I am on my category listing page, but when you click on a category name to see all the entries associated with that category, I can’t figure out a way to add a link back to the category listing page they just came from.

  • #2 / Dec 11, 2008 8:23am

    Beertastic

    49 posts

    {categories}{category_name}{/categories}

    put that in your code within the exp:weblog tag

    The will display ALL categories, so if you’ve more than one, you may be in trouble…

  • #3 / Dec 11, 2008 8:32am

    Mark Bowen

    12637 posts

    Erm you should be able to use the Weblog Category Heading Tag shouldn’t you?

    That is if I am understanding what you need correctly?

  • #4 / Dec 11, 2008 8:33am

    hildreth

    12 posts

    Yeah, that returned all the categories. I was hoping that there was a way to get at the assigned category for a weblog.

  • #5 / Dec 11, 2008 8:35am

    Beertastic

    49 posts

    {categories}{category_name}{/categories}

    Should only return the categories that the weblog has assigned to it…
    can you confirm that your weblog entries all ahve only one category assigned to them?

    I had a similar issue recently, and I just echoed segment_3 instead (which contained my category, before the article)

  • #6 / Dec 11, 2008 8:38am

    hildreth

    12 posts

    Thanks Mark, but that doesn’t return anything. Here is what I am trying to do and my code is:

    <div id="crumbs">
    <ul>
    <li><a href="http://{path=">Home</a></li>
    {if segment_1 =="projects" && segment_2 == ""}
    <li class="selected">{segment_1}</li>
    {/if}
    {if segment_1 =="projects" && segment_2 == "project_list"}
    <li><a href="http://{path=">{segment_1}</a></li>
    {exp:weblog:category_heading weblog="{segment_1}"}
    <li class="selected">{category_name}</li>
    {/exp:weblog:category_heading}
    {/if}
    {if segment_1 =="projects" && segment_2 == "project_details"}
    <li><a href="http://{path=">{segment_1}</a></li>
    {exp:weblog:categories weblog="projects" style="linear" status="open" limit="1"}
    {exp:weblog:category_heading weblog="{segment_1}"}
    <li class="selected">{category_name}</li>
    {/exp:weblog:category_heading}
    <li>Current Page</li>
    {/if}
    </ul>
    </div><!-- end crumbs -->
  • #7 / Dec 11, 2008 8:42am

    Beertastic

    49 posts

    is all this code surrounded by a {exp:weblog..} tag?

  • #8 / Dec 11, 2008 8:43am

    Mark Bowen

    12637 posts

    Is there a way to output the current category from a weblog tag? I am trying to build a breadcrumb nav and I have been able to get the category heading when I am on my category listing page, but when you click on a category name to see all the entries associated with that category, I can’t figure out a way to add a link back to the category listing page they just came from.

    Actually looking back over this again I think I am even more confused now 😉

    If you take a look at this page here it shows a list of categories. If you then click on one of them it shows all the songs in that category and shows the name of the category at the top of the page.

    In your instance are you just trying to get back to the page with all the categories on?

    If not then I apologise as I think I must be misunderstanding something otherwise. If I am right though then you would surely just need a link that sends you back to the template that lists all your categories wouldn’t you?

    Best wishes,

    Mark

  • #9 / Dec 11, 2008 8:50am

    hildreth

    12 posts

    No, this is just an embed. I am using one template called projects that display all my categories with this tag

    {exp:weblog:categories weblog="projects" style="linear" status="open"}
    <li>{category_name}</li>
    {/exp:weblog:categories}

    And then I have another template called project list in which I use this tag to get at a list of all weblog posts that have a particular category assigned

    {exp:weblog:entries weblog="projects" orderby="title" sort="asc" status="open"}
    <li>{title}</li>
    {/exp:weblog:entries}

    and finally I have the project details template that shows the particular weblog chosen from the project list template. I then just use the standard weblog:entries tag to show the posted weblog.

  • #10 / Dec 11, 2008 9:01am

    hildreth

    12 posts

    Thanks Beertastic, the {categories}{category_name}{/categories} worked. I had multiple categories assigned like you said.

  • #11 / Dec 11, 2008 9:03am

    Beertastic

    49 posts

    Happy to help…
    that one took me a few hours to sort outmyself…

    Good luck with the next problem!
    See you back here ;-p

  • #12 / Dec 11, 2008 9:04am

    Mark Bowen

    12637 posts

    Aha I think I know what you mean now 😉

    When you say show the posted weblog you actually mean weblog entry don’t you?

    So taking my example previously if you view this page here which would be the final page / weblog entry in this case then you want to place a link back to the category that showed it listed, right?

    If so then you would just need this code :

    {categories}
    <a href="http://{path=site_index}">{category_name}</a>
    {/categories}

    If not that then do you have a link to the site in question so that I can understand a bit more. Have my head in a load of PHP today and I think it’s making me find understanding things more difficult than usual 😉

    Best wishes,

    Mark

  • #13 / Dec 11, 2008 9:11am

    hildreth

    12 posts

    Thanks Guys, Mark you are right, I did mean weblog entry. I added the {path=site_index} and it took me back to the main page of the site, not the page that had the category listing or the page I just came from. That is the only thing I am trying to figure out now. How to link it back to the previous page with the category headings on it.

    Almost there.

  • #14 / Dec 11, 2008 9:17am

    hildreth

    12 posts

    Actually, I figured it out. Here is what I did.

    <div id="crumbs">
    <ul>
    <li><a href="http://{path=">Home</a></li>
    {if segment_1 =="projects" && segment_2 == ""}
    <li class="selected">{segment_1}</li>
    {/if}
    {if segment_1 =="projects" && segment_2 == "project_list"}
    <li><a href="http://{path=">{segment_1}</a></li>
    {exp:weblog:category_heading weblog="{segment_1}"}
    <li class="selected">{category_name}</li>
    {/exp:weblog:category_heading}
    {/if}
    {if segment_1 =="projects" && segment_2 == "project_details"}
    <li><a href="http://{path=">{segment_1}</a></li>
    {exp:weblog:entries weblog="projects" status="open"}
    {categories}
    <li><a href="http://{path=">{category_name}</a></li>
    {/categories}
    {/exp:weblog:entries}
    <li>Current Page</li>
    {/if}
    </ul>
    </div><!-- end crumbs -->

    Thanks again guys.

  • #15 / Dec 11, 2008 9:56am

    Mark Bowen

    12637 posts

    Excellent news! 😉

    Glad you have it all working now. Yep the {categories} tag pair would be what you needed.

    Sorry about all that but I was misunderstanding when you said weblog and then later on I figured you must have meant an actual entry 😉

    Hope everything else goes well for you.

    Best wishes,

    Mark

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

ExpressionEngine News!

#eecms, #events, #releases