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.

Category by keyword

October 03, 2007 11:17pm

Subscribe [3]
  • #1 / Oct 03, 2007 11:17pm

    Arden

    23 posts

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

    {exp:weblog:entries category="keyword"}

    Anybody have any ideas?

  • #2 / Oct 04, 2007 3:21pm

    e-man

    1816 posts

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

    {exp:weblog:entries category="keyword"}

    Anybody have any ideas?

    From the docs:

    Categories are specified by ID number (the ID number of each category is displayed in the Control Panel). The reason we use the ID is because categories can be called anything (with spaces, quotes, etc.), and also renamed. It would be much more difficult to have to update the tag parameters every time you updated a category name. Further, you can have multiple categories with the same name either in different Category Groups or in different parts of the hierarchy within the same Category Group.

    But maybe you could explain in a bit more detail what you’re trying to do. There might be a workaround.

  • #3 / Oct 04, 2007 3:28pm

    Arden

    23 posts

    Right, I was hoping there was a way around that.

    I’m reimplementing a bunch of sites in EE (for example) that have virtually identical structures, including categories, and that will be organizing a navbar based on those categories.  They are pulling most of their template data from one set of templates in one “master site” through the MSM.  I need to be able to specify which categories to pull from based on keyword instead of ID because ID’s are unique to each site’s categories, while multiple sites can have the same categories with the same keywords.  I could come up with a query using the query module, but that’s overhead-intensive and probably won’t work… any ideas how to do it through straight PHP?

  • #4 / Oct 04, 2007 3:41pm

    e-man

    1816 posts

    Just brainstorming here but how about using a PHP array matching category id’s and names? e.g

    $catnames = array('business' => 1, 'culture' => 3); etc…

    Then in your templates you could use:

    {exp:weblog:entries category="<?php echo $catname[keyword] ?>"}

    I’m sure the array can be generated through a pair of {exp:weblog} tags… Just my 2c

  • #5 / Oct 04, 2007 3:45pm

    Arden

    23 posts

    The main thing is that the categories have to be pulled dynamically; I can’t hard-code ID’s because two sites may have the same categories, but their categories have different ID’s.  So site 1 could have 1 => Business and 2 => Personal while site 2 has 3 => Business and 4 => Personal.  It’s something I’ll work on when I have time, though… I have a couple ideas of how to do it, and I’ll look into your method.  I’m pretty sure I’m going to have to get down and dirty with PHP at some point.

  • #6 / Oct 04, 2007 3:49pm

    e-man

    1816 posts

    Sounds like a doozy 😊  Do post back here if and when you solve it!

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

ExpressionEngine News!

#eecms, #events, #releases