Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Let's say that I have a post that I only want to be shown in the page of the category that it belongs to. The problem is that this post is also visible in the latest posts page.

Is there a way to hide this post from the latest post page and show it only in the page of the category of the post?

share|improve this question
    
How are you displaying posts on latest post page? –  Vinod Dalvi Apr 2 '13 at 12:07
    
@VinodDalvi: I only have configured ad the wp-admin interface in the Reading Settings that a page that I created show the posts (This page is not the front page of the blog). –  Renato Lochetti Apr 2 '13 at 12:09
    
Which theme are you using? –  Vinod Dalvi Apr 2 '13 at 12:17
    
I'm using the Chateau Theme, but if you tell me that I need to change the theme, this can be done. The main concern is that it must work in the Minileven mobile theme, because I have many users that access the blog from a mobile device. –  Renato Lochetti Apr 2 '13 at 12:31

2 Answers 2

Your question is hard to understand.. Do you mean a specific post or somthing automatic? if you mean a specific post and If you are using wp_query / query posts to loop for recent posts you can add this parameter.

'post__not_in' => array($postId)

Example query:

$relatedargs = array(
    'post__not_in'      => array($postId) // THIS IS THE LINE
);
$the_query = new WP_Query( $relatedargs );

// The Loop
if( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) : $the_query->the_post();

// YOUR LOOP HERE

endwhile; 
}

Hope this helps ;

share|improve this answer

Since you're using the core "Page for Posts" settings, you should be able to use the awesome pre_get_posts action to remove the specific ID you want to exclude.

This should work in your functions.php file or /mu-plugins/ plugin:

wpse94273_hide_post( $query ) {
    // only remove post ID from page_for_posts and in the main query
    if( $query->is_home() && $query->is_main_query() ) {
        // remove specific page ID from query
        query->set( 'post__not_in', array( {your post id} ) );
    }
}
add_action( 'pre_get_posts', 'wpse_94273_hide_post' );

Replace "{your post id}" with the ID of the post you want to exclude. It's an array, so you can enter multiple IDs separated by commas if desired.

If the post ID changes, then you'd need to setup some kind of option using the Settings API to store the ID you want to exclude.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.