Jump to content

Choose Posts Order in Homepage Display

Recommended Posts

I have 3 sections In my WP theme in the display of the homepage:
"main story", "editor's pick" and "trending stories".
Each one of my latest 2 posts displayed several times in the homepage in different sections (!): under "main story", under "editor's pick" and under "trending stories".

Instead, I want all the 5 latest posts will display on the homepage, but each of them will appear once only.
(For example: under main story - post 1, under trending - posts 2+3, under editor's pick - posts 4+5).

How can I do this?

Attached screenshot of my homepage

newscard homepage.PNG

Edited by shir

Share this post

Link to post
Share on other sites

It's indeed determined by the time the post was published (=latest posts).
However, I'm looking for the code who'd say; let's publish the latest 5 posts in the 3 sections - while each one would appear once.
Meaning, avoid post duplicated display
, as well as determine the post order, as I mentioned above (latest under "main story", the 2 before - under "trending stories", the 2 before - under "editor's pick".

I got one code to prevent duplication. But it made the posts display disappeared from the top 3 sections completely, and leave display of latest post only in the sections below the 3 top sections.

The code was (if that helps): + attached screenshot after implanting the code

add_action('parse_query', 'mts_exclude_duplicates');

function mts_exclude_duplicates( &$query ) {

if (!is_home()) return;

global $adp_posts;

$disable_now = $query->get('adp_disable'); // use 'adp_disable' to prevent exclusion

if (empty($query->post__not_in) && empty($disable_now)) {

$query->set('post__not_in', $adp_posts);




add_filter('the_posts', 'mts_log_posts', 10, 2);

$adp_posts = array();

function mts_log_posts( $posts, $query ) {

if (!is_home()) return $posts;

global $adp_posts;

foreach ($posts as $i => $post) {

$adp_posts[] = $post->ID;


return $posts;


hp after implanting code.PNG

Edited by shir

Share this post

Link to post
Share on other sites

Yes but! If one shows latest published, one shows most viewed which could be the pages/posts you are working currently on and viewing, it WILL show duplicate, because you haven't enough views from others to increase views on other posts. By hiding duplicates for so few posts, and views which it is supposed to do, you are overriding its default functionality. Also using this code to not display duplicates, well surely the result is exactly you would expect? If it prevented duplicate to show alternative other posts, that would be what you want. You can change publish date, view history try adjusting these for different posts. If this plugin? has setting to filter posts from these four, adjust those.

This plugin seems to allow you do exactly that


Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...