SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Wordpress: Limiting Tag Retrieval

    Note: If this is the wrong place, please move to the PHP forum.

    Here is the scenario. I am creating a site with Wordpress and want to use tags to categorize things. However I basically one two sets of tags. Primary tags and a set limited to a secondary topic.

    The secondary topic is of the site are healthy recipes. Basically for the recipes each primary ingredient becomes a tag to make for easy searching. I want to show these tags only on the recipe category page and not in any other tag clouds.

    Right now, I am doing this using the function provided by Wordpress to control this. As seen in this example:

    PHP Code:
    <?php if ( function_exists('wp_tag_cloud') ) : ?>
    <div class="widget">
      <h5>Browse by topic</h5>
      <ul>
        <?php wp_tag_cloud('smallest=8&largest=22&exclude='.$recipe_tags); ?>
      </ul>
    <?php endif; ?>
    To only use those tags I would do something like:
    PHP Code:
    wp_tag_cloud('smallest=12&largest=12&include='.$recipe_tags); 
    The $recipe_tags is filled in an included settings file with the following content currently:
    PHP Code:
    <?php
    $recipe_tags 
    '52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100';
    ?>
    Those are the tags for less than a couple of dozen recipes. It can quickly get unwieldy. Some would argue that it already has. Does anyone know of a way to automatically pull tags that are only used in a particular category to pre-populate this array? This works well but it will be a pain to manage when I have several hundred recipes covering many different ingredients.
    Wayne Luke
    ------------


  2. #2
    SitePoint Addict
    Join Date
    Mar 2006
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It sounds like you have less frequent additions to your primary tags, so why not set those as the variable, and then include and exclude them as needed? That might be a little easier to manage. I would setup a little admin panel and save them as a wordpress option (and live with the additional database hit) so I didn't have to make edits to the theme so often.

    On a more fundamental level, I wouldn't rely on tags to categorize things. That's what categories are for. I would set it up so your "primary tags" are sub-cats of your recipe category, and then use tags for ingredients.

  3. #3
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    As I add content to the primary categories, I am sure I will have just as many if not more tags assigned to it. I am primarily using Wordpress as a CMS to build an online magazine. Wordpress was chosen its lightweight and fairly easy to use while things like Joomla and Drupal are very heavy and I found difficult to use. There are only going to be 6-8 categories/sections. Most content is entered as posts not pages.

    The tags I am referring to for recipes are ingredients... So they can click on "chicken" and get all chicken recipes. The only one that isn't an ingredient is "vegetarian" but it is a pretty necessary tag as well. I don't really plan on having categories like "Main Course" or "Side Dish" but instead encourage people to look up recipes by the ingredients that they have available. I am limiting the recipes to only include ingredients that can be grown in California but that is a lot of things.

    As it is, I can easily think of over 20 types of fruit alone. Apples, Pears, Peaches, Apricots, Crenshaw Melon, Figs, Pomegranate, Kiwi, Cantaloupe, Apriums, Pluots, Plums, Oranges, Lemons, Limes, Nectarines, Watermelon, Grapefruit, Honeydew Melon, Blueberries, Raspberries, Cherries, Blackberries, Strawberries, and Pumpkin. Even then, I am probably missing some. I've already reduced some tags so for instants instead of saying Butternut Squash, Crook Neck, Zucchini, Patty Pan Squash, Acorn Squash, Golden Squash, or Baby Bell Squash on things, I just use the tag of Squash. Same for Potatoes even though a Red Potato, Russet and Yukon Gold all have different flavors and textures.

    Oh well, will probably end up doing it the manual way until I get time to code something (which will probably be never).
    Wayne Luke
    ------------


  4. #4
    SitePoint Addict
    Join Date
    Mar 2006
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It actually wouldn't be that hard to code it. you could use get_posts to grab all the posts in the recipe category, then loop through them and add the tags of each to an array then array_unique and you're set. You would also want to setup an action that watched for new posts in the recipe category and added any new tags to the array.

  5. #5
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Possibly, I'll have to look into it soon.
    Wayne Luke
    ------------



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •