We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How would I get a specific category_id for an entry?

How Do I?

User 1EKsh2eFf's avatar
User 1EKsh2eFf
3 posts
about 3 months ago
User 1EKsh2eFf's avatar User 1EKsh2eFf

I have a category Group titles “portfolio” (id #3) and inside of it I have 4 categories. Each portfolio entry is assigned to just 1 of them. NExt I would like to use the Next/Previous entries tag on my portfolio item page, but i want to limit the results on that to entries in the same category as the one being displayed. Right now I have this within my channel entries tag:

{layout:set name="catid"}
    {categories category_group="3"}{category_id}{/categories}
{/layout:set}

and then I pass the layout variable “catid” into the Next/previous entries, but this doesn’t seem to work.

       
User AGuHpHcD's avatar
User AGuHpHcD
2 posts
about 3 months ago
User AGuHpHcD's avatar User AGuHpHcD

There’s a {parent_id} variable that might help (I’ve never used it so, not sure how it works).

       
User olbp8DKG's avatar
User olbp8DKG
4 posts
about 3 months ago
User olbp8DKG's avatar User olbp8DKG

Not tested but I’d go for putting your Previous/Next page navigation links https://docs.expressionengine.com/latest/channels/entry-linking.html inside an embed, then pass the cat ID as an embed variable.

       
jelle's avatar
jelle
87 posts
about 3 months ago
jelle's avatar jelle

You can do the same with template layouts, just use a template higher up the stack instead of an embed

       
User 1EKsh2eFf's avatar
User 1EKsh2eFf
3 posts
about 3 months ago
User 1EKsh2eFf's avatar User 1EKsh2eFf

Thanks for the suggestions… When I looked at it with fresh eyes this morning, what actually worked was to modify my creation of the layout variable like so within the channel entries loop: {categories category<em>group="3"} {layout:set name="catid"}{category</em>id}{/layout:set} {/categories}

       
jelle's avatar
jelle
87 posts
about 3 months ago
jelle's avatar jelle

that layout:catid would always be the id of the latest category in the loop

       
User 1EKsh2eFf's avatar
User 1EKsh2eFf
3 posts
about 3 months ago
User 1EKsh2eFf's avatar User 1EKsh2eFf

Yeah… I see that now that you mention it. but for category group 3, I only ever use one of them. the entry is either branding, marketing, web, or Motion (or one of it’s child categories - so here maybe I should grab the parent_id instead), so here it should be safe. it’s my own site so I should be OK (until I’m not I guess)

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.