Hide last added posts
-
is there a way to hide 3 last added posts on home page?
Thanx
-
You can set their “Visibility” to “Private” on the post edit page when you create them, or any other time for that matter.
OK, but it’s that I have hot news panel at the top with 3 last added posts and below should be following posts, unless there is also a repeat 3 last added posts from hot news panel…
so i’m looking for something like ‘query_posts’ or ‘post__not_in’…?You and I both need to take a course in PHP.
Hi Mannonero,
Indeed, you do need php code to accomplish what you’re looking for. In my opinion, the best way to accomplish what you desire is to assign a certain category or tag to your “hot news” posts, and then only show that category or tag in the “hot news panel” and exclude it from The Loop in the home page (index.php). The final result would be two loops running simultaneously: one for your hot news panel, one for your the rest of your homepage content.
Here’s how you do it:
1. By category:
Hot News Panel:query_posts('cat=x');
Homepage content:query_posts('cat=-x');
2. By tag:
Hot News Panel:query_posts('tag=y');
Homepage content:$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args=array( 'tag__not_in' => array(y), 'paged'=>$paged, ); query_posts($args); ?>
Bear in mind that you need to replace “x” and “y” with the category ID number and the tag ID number (respectively) assigned to your hot news. You can retrieve the category or Tag ID from the WP admin panel, under “Posts” –> “Categories” and “Posts” –> “Post Tags.”
Also, don’t forget you need to accompany the corresponding code mentioned above with The Loop code, which usually looks like this:<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?>
Like I said earlier, you are going to use The Loop code two times: 1. to display the Hot News Panel posts; and 2. to display the rest of your content (this version of The Loop should already be included in your template).
That should do the trick for you. Let me know if this works or if you run into any problems.see techniques for avoiding duplicate posts:
https://codex.www.ads-software.com/The_Loop#Multiple_Loops_in_Action
particular:Alternatively you can pass the entire $do_not_duplicate array to $wp_query and only entries that match your criteria will be returned:
<?php query_posts(array('post__not_in'=>$do_not_duplicate)); if (have_posts()) : while (have_posts()) : the_post(); ?>
Note that instead a string, the query parameter was an associative array, with post__not_in option.
Yep, resorting to the
$do_not_duplicate
array like Alcymyth suggests is a very good idea too, and it simplifies things on the ‘rest of the homepage content’ side.
However, you would still have to ‘populate’ the$do_not_duplicate
array with the Hot News posts (i.e., the posts you’re seeking to exclude from the normal Loop). The best moment to do that would probably be when calling the posts inside the Hot News panel through the 2nd Loop.
What do you think, Alcymyth?the best place to collect the posts already shown, is using the array method with this line
$do_not_duplicate[] = $post->ID;
in the loop(s) that precede the loop in which the duplicates should be ‘hidden’.( https://codex.www.ads-software.com/The_Loop has examples for this )
this ‘hiding’ of duplicate posts can be done in (many) consecutive loops – principle:
-loop1:
while(have_posts()): the_post(); $do_not_duplicate[] = $post->ID; /*show content*/ endwhile;
-loop2:
query_posts(array('post__not_in'=>$do_not_duplicate));
while(have_posts()): the_post(); $do_not_duplicate[] = $post->ID; /*show content*/ endwhile;
-loop3:
query_posts(array('post__not_in'=>$do_not_duplicate));
while(have_posts()): the_post(); $do_not_duplicate[] = $post->ID; /*show content*/ endwhile;
-loop4:
query_posts(array('post__not_in'=>$do_not_duplicate));
while(have_posts()): the_post(); /*show content*/ endwhile;
- The topic ‘Hide last added posts’ is closed to new replies.