Support » Plugin: Nelio Featured Posts » Repeating posts on multiple loops

  • Resolved SonalM

    (@sonalm)


    Hi, I’ve been using the featured posts plugin with great ease and the customisation capabilities are great! I have run in to one minor issue though, I have two container divs with two posts loops (for different parts of the layout, one for featured posts and the other for latest posts), if a featured post is set it also gets displayed in the latest posts loop.

    I’ve tried using WordPress’s guide on tackling this but since in this case the featured posts come from a plugin and not a category I’m not really sure what to do, my PHP knowledge is fairly low as well, but I think something like, if a post is shown in one container div, to not have it repeat in another container div.

    https://wordpress.org/plugins/nelio-featured-posts/

Viewing 1 replies (of 1 total)
  • Plugin Author David Aguilera

    (@davilera)

    Hi! In my opinion, the easiest solution would be to add a tiny JavaScript that does something like this:

    jQuery(document).ready(function() {
      var latestPostIds = [];
      jQuery('#latest-posts article').each(function() {
        // get jQuery(this) id (or something similar)
        var id = 0; // TODO
        latestPostIds.push(id);
      });
      jQuery('#featured-posts article').each(function() {
        // get jQuery(this) id (or something similar)
        var id = 0; // TODO
        for ( var i = 0; i < latestPostIds.length; ++i ) {
           if ( latestPostids[i] == id )
              jQuery(this).hide();
        }
      });
    });

    which, as you can see, will hide any article in #featured-posts that also appears in #latest-posts. You’ll have to find out, however, how to make the posts in one list match with the posts of the other list (a specific class such as post-xxx where xxx is the ID of the post?).

    However, in my opinion this is not the best solution: if all posts were the same in one list and the other, the latter list would appear empty (for we’d hide all posts). A different solution would be to edit your PHP files and make sure that the posts that will be included in a list won’t be included in the other. The easiest solution for achieving so could be, for instance, not to include featured posts that are one month old or less. This way, newest posts will not be able to appear in the featured post list (they are one month old or less), but they’ll probably appear in the latest post list.

    I hope these ideas help you solve the issue. Let us know what you implemented in the end and how.

    Good luck!

Viewing 1 replies (of 1 total)
  • The topic ‘Repeating posts on multiple loops’ is closed to new replies.