Reputation: 453
I'm working on a WordPress site, and I'm working on a requested feature from my client. The client would like to be able to feature certain posts, so that they appear at the top of a list. To make it easy for my client, I created a featured category. So when the client wants to feature a post, all they have to do is to add the featured category to the post.
Here is my current query to display all posts with the category name of events:
$query = new WP_Query( array( 'category_name' => array('events'), 'posts_per_page' => '1' ) );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$postLink = get_permalink();
echo '<li class="wp-post">
<h5><a href="'.$postLink.'">'.get_the_title().'</a></h5>
<p>'.get_the_excerpt().'</p>
<div class="wp-post-details">
<span class="post-date">'.get_the_date().'</span>
</div>
</li>';
}
echo '<li><a href="/categories/events/" class="btn">View All Events</a></li>';
wp_reset_postdata();
} else {
echo '<li>No Posts Found</li>';
}
I would like to change it, so it would display events posts that have the additional category of featured first. I have done some searching on Google and here. But as of yet, I have not found a solution that works for my instance.
Upvotes: 0
Views: 1316
Reputation: 453
I found the an solution to my issue. I just had to add if (in_category('feature')) {...
before I echo the HTML.
Upvotes: 0