• Somewhat new to wordpress, but I have spent quite a bit of time reading the forums and couldn’t find an answer for a couple of questions.

    1.) Is there a developed plugin that allows custom fields for categories, not posts?

    I did find a post regarding this issue, but it was made a while ago and doesn’t appear to fully developed.

    http://farm1.static.flickr.com/176/423821335_2e5854d6d2_o.jpg

    2.) Is there a way to associate a graphic with a particular tag? i.e. any post tagged “best” would display a star graphic?

    I was able to find the associated tag id, but couldn’t determine if it is possible to make a conditional call to check for a tag id (which would then make it easy to display the graphic)?

Viewing 3 replies - 1 through 3 (of 3 total)
  • 1. Sadly, no. A far more general custom fields feature in WordPress, where categories, links and other elements can be pinned with meta data, is something I’ve longed for.

    A plugin would certainly be great, but it would have to be a pretty invasive one to accomplish this with some completeness. Not sure how possible that is, as a plugin.

    2. Some (relatively) simple code to accomplish that:

    <?php
    $post_tags = get_the_tags();
    $tag_names = array();
    
    foreach( $post_tags as $tag ) :
    	$tag_names[] = $tag->name;
    endforeach;
    ?>
    
    <?php if( in_array('best', $tag_names) ) : ?>
    <img src="/path/to/star-image.jpg" />
    <?php endif; ?>

    Thread Starter swaro

    (@swaro)

    Thank you for the reply.

    I tried the code you supplied, but it generates an error.

    <b>Warning</b>: Invalid argument supplied for foreach()

    Any ideas?

    1. Are there tags associated with the post?

    2. Is the code run in or out of The Loop?

    Try this:

    <?php
    global $post;
    $post_tags = get_the_tags();
    
    if( $post_tags ) :
    	$tag_names = array();
    	foreach( $post_tags as $tag ) :
    		$tag_names[] = $tag->name;
    	endforeach;
    ?>
    
    <?php if( in_array('best', $tag_names) ) : ?>
    <img src="/path/to/star-image.jpg" />
    <?php endif; ?>
    <?php endif; ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Conditional call for tag id? Custom fields for Category?’ is closed to new replies.