• Hello,

    what I need is to display the tags of the post and its categories (can be one or more), outside the loop, in an ALT or TITLE image attribute.

    This is the code Im using (on homepage) to show a little image (only) for every post with the category “Adopt”:

    <?php $lastposts = get_posts('numberposts=10&category_name=Adopt');
    foreach($lastposts as $post) : setup_postdata($post); ?>
    <div class="foto"><a href="<?php the_permalink() ?>">
    <?php show_photo($thumbs['mini_thumb_w'],$thumbs['mini_thumb_h']); ?></a>
    </div>
    <?php endforeach; ?>

    The “alt”/”title” attribute of the image however, is controlled by the function show_photo() which is:

    function show_photo($width,$height) {
    
    	global $post;
    	$key = "photo";
    	$custom_field_value = get_post_meta($post->ID, $key, true);
    	$attachments = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'rand', 'numberposts' => 1) );
    
    	if ($attachments == true) {
    
    	foreach($attachments as $id => $attachment) {
    	$img = wp_get_attachment_image_src($id, 'full');
    	$img_url = parse_url($img[0], PHP_URL_PATH);
    	print '<a href="'.get_permalink($post).'" <strong>title="'.$post->post_title.'"</strong>><img src="'.get_template_directory_uri().'/scripts/timthumb.php?src='.$img_url.'&w='.$width.'&h='.$height.'&zc=1&q=100" alt="'.$post->post_title.'" /></a>';
    	}
    
    	} else { }
    }

    How could I add in the “TITLE” attribute (or alt, if I add it), also all the tags and categories of the post? Could I also exclude some?

    This is for an Animal Rescue Association website, to put up ads for abandoned animals 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get Tags and Categories Outside The Loop’ is closed to new replies.