WordPress powered site that is setup with a custom front page. For the most part, the frontage is structured like so:
Cat 1
<bold>
Latest post from category
</bold>
<li>
next 5 posts from category
</li>
Cat 2
<bold>
Latest post from category
</bold>
<li>
next 5 posts from category
</li>
Cat 3
<bold>
Latest post from category
</bold>
<li>
next 5 posts from category
</li>
The problem is, a post can be assigned to more than one category. So, I could write a post "Sample Post" and publish it in the Cat 1 and Cat 2 categories. From here, the front page would display that post under two of the categories, and it would also be the most recent post, so it would be published as <bold>Sample Post</bold> for both categories on the homepage.
I am trying to get the post to only be displayed under one category on the homepage. Any other recommendations regarding this issue would also be welcomed.
Update:Thank you so much for your recommendations, Gary. However, I do not want to have to adjust the date or limit myself to categorizing a post into just one category.
I'm trying to figure out the code that would allow for a post to be in as many categories as I want, but only be displayed on my homepage under one of the categories.
Copyright © 2024 Q2A.ES - All rights reserved.
Answers & Comments
Verified answer
The only way I can think of doing this is by using multiple query_post functions before the loop in the template file you are using for your front page, so
query_posts( array( 'category__and' => array(1,2,3,4), 'posts_per_page' => 5, 'orderby' => 'title', 'order' => 'DESC' ) );
query_posts('category_id=5&showposts=' . get_option('posts_per_page'));
With those queries, you are pulling the first 5 posts from categories with the ids of 1, 2, 3, 4 so in order to hide your sample post, it would have to be the 6th post in categories 1 through 4. Then in category 5, it will be visible.
So your layout would look similar to:
<?php
// Custom queries to show sample post in only category 5
query_posts( array( 'category__and' => array(1,2,3,4), 'posts_per_page' => 5, 'orderby' => 'title', 'order' => 'DESC' ) );
query_posts('category_id=5&showposts=' . get_option('posts_per_page'));
// The Loop
while ( have_posts() ) : the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile;
// Reset Query
wp_reset_query();
?>
Just make sure you put the queries before the loop otherwise they will not work. It might not be exactly what you are looking for, see http://codex.wordpress.org/Function_Reference/quer... for further reference.
i have a similar set-up with a church press theme for wordpress.
i cant separate mine like you are trying. i have to only pick one of the categories. i just use the most relevent one.
see mine here
http://www.pitbull-secrets.com/
as you can see, in my categories, i have all different posts and never use the same category twice...you can get away with by changing the date of the post to make it so it is the 6th post, so it wont show up on your homepage and only in the category search
Really difficult, sorry to say