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.

Pass Category Name to Single Post

June 11, 2009 4:05pm

Subscribe [2]
  • #1 / Jun 11, 2009 4:05pm

    Big Skillet

    364 posts

    Is it possible to pass a category name to a single post page?  If you click a category and then click a post from that category, EE removes the category name from the URL when you hit the single post page.

    On my single post page, I need to display what category you just came from.

    Make sense?

  • #2 / Jun 11, 2009 5:42pm

    Big Skillet

    364 posts

    Ping

  • #3 / Jun 11, 2009 6:00pm

    ender

    1644 posts

    you could try using the $SESS->tracker to look back a page to see if they came from a category page and then parse the cat_url_title from the url, perform a query to select the cat_name from the database and display it 😉

    or perform a query on the database to select all the categories the entry is assigned to and then process those to select the one you want (most general, most specific, etc.).

  • #4 / Jun 11, 2009 6:23pm

    Big Skillet

    364 posts

    Your first suggestion like it would work the best, but is way over my head.  How exactly would I do everything you explained, and what would the code look like?

  • #5 / Jun 11, 2009 7:31pm

    Boyink!

    5011 posts

    You could pass the category name in a custom URL segment, and then pull it to the page using a {segment_x} variable.

    Will the entries be in more than one category at a time?

  • #6 / Jun 11, 2009 7:36pm

    Big Skillet

    364 posts

    Yes, the entries will be in more than one category. 

    I’ve tried grabbing the {segment} while on the category page, but can’t can’t seem to pull it on the next page.  How exactly would I do that?  I’m running the SegsCat plugin already…

  • #7 / Jun 11, 2009 7:43pm

    Boyink!

    5011 posts

    You’d have to put the category url title in the URL on the single entry page, then you could use seg2cat to translate the cat_url_title to the readable category name.

  • #8 / Jun 12, 2009 4:05pm

    Big Skillet

    364 posts

    Right, but I’m not sure how to do that exactly.  Would you mind providing an example?

  • #9 / Jun 15, 2009 3:38pm

    Big Skillet

    364 posts

    Boyink!...  Would you mind explaining a little more how to implement your recommendation?

  • #10 / Jun 15, 2009 3:56pm

    Boyink!

    5011 posts

    Sorry.. occasionly I have to make a living..😉

    Two ideas, try this one first:

    You’re going to be rolling your own links and then doing some extra logic on the single entry page.

    Link while on category page:

    <ahref="index.php/template_group/{segment_3}/{url_title}/">{title}</a>

    That assumes the category URL title is in segment 3 position, adjust if not.  Also that link has to be created within a weblog:entries loop where the url title and title variables are available.

    Then on detail page:

    You just came from the {segment_2_category_name} category

    That code assumes Lows Seg2Cat is installed.

    and then

    {exp:weblog:entries weblog="weblog" dynamic="off" url_title="segment_3"}
    stuff
    {/exp:weblog:entries}

    The second idea is to tack the category url title on after the entry url title -which might also work but won’t look as right.

  • #11 / Jun 15, 2009 4:15pm

    Big Skillet

    364 posts

    I hear ya… thanks for coming back.

    Yes, I’ve tried your recommendation and the URL passes fine, but it doesn’t pull up the single post template.  Click the link below, choose “action” from the categories dropdown, then click a movie title.  You’ll see that the URL changes, but it’s doesn’t pull up the “title” template.

    http://toprankedmovies.earph.com/catalog/action/

    I’m using the code below in the href:

    {path="catalog/{segment_2}/title/{url_title}"}

    What am I doing wrong?

  • #12 / Jun 15, 2009 4:20pm

    Mark Bowen

    12637 posts

    Sorry for popping in on this one here. Pretty sure Mike meant this instead :

    {exp:weblog:entries weblog="weblog" dynamic="off" url_title="{segment_3}"}
    stuff
    {/exp:weblog:entries}

    Note the url_title=”{segment_3}” instead of url_title=“segment_3”

  • #13 / Jun 15, 2009 4:23pm

    Big Skillet

    364 posts

    Mark, that code would go on the single post page right?  If so, the problem is that I can’t even get the single post page to come up when I try to include the category in the URL.

  • #14 / Jun 15, 2009 4:34pm

    Boyink!

    5011 posts

    Hmm..see I wonder if the second idea is going to be the way to go..because I’m guessing its not loading because EE is looking for template with the name of “action”.

    I think you could either build a more robust index template in the catalog group, or you’ll have to tack the category name onto the end of the URL instead.

  • #15 / Jun 15, 2009 4:46pm

    Big Skillet

    364 posts

    Yes, I did originally have a more robust index template like there http://fortysevenmedia.com/blog/archives/setting_up_custom_category_url_structures_in_expressionengine/, but some functionality wouldn’t work in the single post section of the {if} statement.  For example, “next_entry” and “prev_entry” wouldn’t show up.  I was afraid that even more problems might arise along the way due the hack…

    I guess there really isn’t any way to keep the category in the URL then, huh? 

    I wonder if I used the category “trigger” if it would allow the name in the URL since it knows it’s a category instead of a template…

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

ExpressionEngine News!

#eecms, #events, #releases