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 a Category Name based upon it's ID in a URL segment.

December 04, 2010 1:50am

Subscribe [4]
  • #1 / Dec 04, 2010 1:50am

    briankalwat

    50 posts

    I’m trying to dynamically display the name of a category at the top of a list of entries, but I want it to be based on the URL structure.

    For instance, if the URL reads

    http://experienceresonate.com/media/browse/C20, where segment_03 == C20, I want the Category name for C20 to be displayed at the top of the page. I’m sure there’s a simple way to do this, but I haven’t been able to come up with any ideas. Any suggestions are welcomed and appreciated.

    Thanks!

  • #2 / Dec 04, 2010 2:50am

    This should do the trick: http://devot-ee.com/add-ons/low-seg2cat/

  • #3 / Dec 04, 2010 3:22am

    briankalwat

    50 posts

    So this appeared to be the perfect solution, but I can’t seem to get it working…

    I have a category, 20, which the name is Galatians.

    My URL structure is as follows http://experienceresonate.com/media/browse/20

    If I use {segment_3_category_name}, it’s returning an empty string…

  • #4 / Dec 04, 2010 3:34am

    Sorry, I read your OP a bit too quickly. Seg2Cat does the opposite: http://experienceresonate.com/media/browse/Galatians would give you {segment_3_category_id), etc.

    You want something like:

    {exp:channel:categories id="{segment_3}"}
    
    {category_name}
    
    {/exp:channel:categories}

    You’ll have to do a bit of find/replace (or substring, if you want to use raw php) magic to get rid of the C.

    Or, change up your linking structure and get more-readable urls in the process ; )

  • #5 / Dec 04, 2010 3:54am

    briankalwat

    50 posts

    Unfortunately, that’s not working either. I removed the “C” from my URL structure manually,

    <div id="categorycontainer">
       <ul>
       {exp:channel:categories style="nested" channel="mediacontent"}
       <a href="http://experienceresonate.com/media/browse/{category_id}">{category_name}</a>
       {/exp:channel:categories}
       </ul>
    </div><!-- END CATEGORY CONTAINER -->

    and now - not only is the category name not being displayed with this -

    {exp:channel:categories id="{segment_3}"}{category_name}{/exp:channel:categories}

    ..but no entries are being returned either. Any ideas?

    Tried this too, with no better result:

    {exp:channel:categories show="{segment_3}"}{category_name}{/exp:channel:categories}
  • #6 / Dec 04, 2010 4:21am

    Sorry if the suggestion’s too simplistic, but I always have trouble with code that’s been copied from web pages; try zapping some gremlins - there might be some funky characters in there.

  • #7 / Dec 04, 2010 5:23pm

    briankalwat

    50 posts

    Any other suggestions on this?

    Currently, I have a main media page that on the right sidebar has a list of all my categories with links to the “browse” template, where the entries are dynamically limited by the URL:

    <div id="mediarightsidebar">
            <h3>Browse By Category</h3>
    <p>        <div id="categorycontainer"><br />
                {exp:channel:categories style="nested" channel="mediacontent"}<br />
                <a href="http://media/browse/C{category_id}/">{category_name}</a><br />
                {/exp:channel:categories}<br />
            </div><!-- END CATEGORY CONTAINER --><br />
        </div><!-- END MEDIA RIGHT SIDEBAR -->


    Here’s my entire {media/browse} template code. Inline styles… gross I know. I’m working on it.

    
    
    

    I’m using

    {exp:channel:categories show="{segment_3}"}{category_name}{/exp:channel:categories}

    to try to display the category name associated with the ID in URL {segment_3}.

    Originally, I had thought that it wasn’t displaying the name because of the “C” that preceded the category ID in {segment_3}, but even when I remove it from the URL, it won’t display the name correctly…

  • #8 / Dec 04, 2010 6:37pm

    Wouter Vervloet

    758 posts

    Hi Brian,

    Have you ever thought of using the {exp:channel:category_heading} tag? That particular tag is made for showing the name of the current viewed category. Also, I think it would be better if you don’t hardcode your category URL’s, but just use the {path} tag to generate the URL.

    {exp:channel:categories style="nested" channel="mediacontent"}
      <a href="http://{path=media/browse}">{category_name}</a>
      // Generates: <a href="http://domain.com/media/browse/C20">http://domain.com/media/browse/C20</a>
    {/exp:channel:categories}

    As long “Use Category URL Titles In Links?” if turned off it will use the category id’s in the URL. (Cxx)

    Greetz,
    Wouter

  • #9 / Dec 04, 2010 7:19pm

    briankalwat

    50 posts

    Working fabulous! Thanks for the tip, I don’t know how I missed that tag.

  • #10 / Dec 06, 2010 3:07am

    John Henry Donovan

    12339 posts

    Glad you are up and running again.Feel free to start a new thread if you have any more questions.

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

ExpressionEngine News!

#eecms, #events, #releases