Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

charlesdunworth on "php echo a title above my list of related posts"

$
0
0

hello

I am using the bones template theme but really this question must be so basic that that is irrelevant.

bones has a function for related posts which outputs an <li> foreach post in an array. Above this list I would like to echo a <p> or maybe <h3> tag which just says "here are some related posts"

here is the function

function bones_related_posts() {
	echo '<ul id="bones-related-posts">';
	global $post;
	$tags = wp_get_post_tags( $post->ID );
	if($tags) {
		foreach( $tags as $tag ) {
			$tag_arr .= $tag->slug . ',';
		}
		$args = array(
			'tag' => $tag_arr,
			'numberposts' => 5,
			'post__not_in' => array($post->ID)
		);
		$related_posts = get_posts( $args );
		if($related_posts) {
			foreach ( $related_posts as $post ) : setup_postdata( $post ); ?>
				<li class="related_post"><a class="entry-unrelated" href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a><?php the_excerpt(); ?></li>
			<?php endforeach; }
		else { ?>
			<?php echo '<li class="no_related_post">' . __( 'No Related Posts Yet!', 'bonestheme' ) . '</li>'; ?>
		<?php }
	}
	wp_reset_query();
	echo '</ul>';

Of course I don't want this title to show up if there are no related posts, nor do I want it to display foreach related post. ( this, of course, happened when I tried just whacking <p>title related</p> in the if(related_posts) foreach function.

Any help for a rank amateur would be much appreciated. I suppose if I could use the $tag_arr to use the tag name in the title that would be even better but I'd settle for any help or a nudge in the right direction


Viewing all articles
Browse latest Browse all 8245

Trending Articles