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.

How to get Category ID from URL title in URL segment

August 03, 2011 5:26pm

Subscribe [5]
  • #1 / Aug 03, 2011 5:26pm

    BCPower

    8 posts

    I have this:

    {exp:channel:entries channel="{segment_2}” category=”{translate_category}”}
    • {title}

    {/exp:channel:entries}

    {translate_category} is this snippet:

    {if segment_3 == "ankle_foot"}2
    {if:elseif segment_3 == "shoulder"}10
    {if:elseif segment_3 == "other"}9
    {if:elseif segment_3 == "neck"}8
    {if:elseif segment_3 == "knee"}7
    {if:elseif segment_3 == "hip"}6
    {if:elseif segment_3 == "hand"}5
    {if:elseif segment_3 == "elbow"}4
    {if:elseif segment_3 == "back"}3
    {if:elseif segment_3 == "wrist"}11
    {if:else}x
    {/if}

    The problem is, the snippet doesn’t work as a tag parameter.  Is there a better way to put the Category ID in the parameter by looking at the URL title in the URL segment?

  • #2 / Aug 03, 2011 7:19pm

    Dave @ Exp:resso

    465 posts

    Do you realise you can have the channel:entries tag auto-detect the category, based on the url? So your url could be anatomy/bodyparts/category/hand, which would display the ‘anatomy/bodyparts’ template, with the category ‘hand’?

  • #3 / Aug 04, 2011 10:53am

    Kevin Smith

    4784 posts

    Thanks for the assist, Dave. BCPower, have you been able to chase down anything based on Dave’s tip?

  • #4 / Aug 04, 2011 3:30pm

    BCPower

    8 posts

    Well, what I want to do is set the category ID so that I can list entry titles with that particular category.  I don’t want to go to another template.

  • #5 / Aug 04, 2011 5:57pm

    Dave @ Exp:resso

    465 posts

    Wekk you don’t need the category id for this, you can do it from the url title automatically

  • #6 / Aug 04, 2011 6:05pm

    Brandon Jones

    5500 posts

    Hi BCPower,

    Yes, Dave’s suggestion should work. Are you making progress here?

  • #7 / Jun 26, 2012 10:50am

    hexarmor

    8 posts

    I think I am trying to do something similar, but dont want to use conditionals.

    I would like to be able to do something like the following: 

    {exp:channel:entries channel=”{segment_1}” category=”{segment_2}”}

    {exp:channel:entries channel=”products” category=”{segment_2}”}

    Are either of these possible?

    Thanks!

  • #8 / Jun 29, 2012 4:01pm

    Dan Decker

    7338 posts

    Hi hexarmor,


    Indeed!

    In order to use segment_2 for categories, you’ll need to use Seg2Cat to translate the segment into a category_id number.

    With that, you would be in good shape.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases