On our current site we have different company profiles. Some companies have blog posts that display on their profile and some don't. Their is an h2 tag above posts that is in the page template then the code to bring in the posts. The code looks like this.
<h2>Recent Blog Articles</a></h2>
then
echo get_related_author_posts();
I am trying to find a way so that if their are no posts for the company the h2 tag will not show up. The code in the functions file is
function get_related_author_posts() {
global $authordata, $post;
$authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => 5 ) );
$output = ' <ul style="list-style: none;">';
foreach ( $authors_posts as $authors_post ) {
$output .= '<li><a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a></li>';
}
$output .= '</ul>';
return $output;
}
while ( have_posts() )). So, if there are no posts, the heading won't be echoed. Or am I mistaken? – t f Mar 7 at 17:58