• Resolved Gregg

    (@cinemadiving)


    I know very little about PHP and I’ve been fumbling around with this for a while, but I’m stumped. Hopefully I can explain this problem clearly enough.

    On my home page the theme displays recent posts in different formats i.e. the most recent two within a larger feature block, the next 4 in a smaller block and the rest as a list. The original code looked like this:

    query_posts( 'showposts=2' );
    if (have_posts()) :
    while (have_posts()) : the_post(); $category = get_the_category();

    However, I want to exclude any “news” posts in the query. Unfortunately, the solution I came up with results in duplicate articles in each segment block as you can see on my site https://www.cinemadiving.com.

    The change I made:

    query_posts( array(
    'showposts' => '2',
    'cat' => '-20,-18') );
    if (have_posts()) :
    while (have_posts()) : the_post(); $category = get_the_category();

    I would be extremely grateful if anyone could help with this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    So, you’re doing a different query before each and every section? Or what?

    There’s nothing wrong with that code, so what’s wrong must be somewhere in your assumptions. For example, you’re saying that you show “the most recent two within a larger feature block, the next 4 in a smaller block and the rest as a list”, which makes me wonder why your query has showposts=2 at all. Unless I’m missing something.

    If you could post your whole Loop for all these sections onto https://wordpress.pastebin.com and then post the link back here so we can see it, we’d be better equipped to help you.

    If you’re wanting to use an offset, BTW, then the offset is going to be on the later queries, not on the first one.

    Thread Starter Gregg

    (@cinemadiving)

    Thanks for helping out Otto42. I just pasted the code here https://wordpress.pastebin.com/m13e97a24. It’s from a free theme called Magazeen.

    Hopefully you can make sense of it.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Okay. This won’t work.

    query_posts( array(
    'showposts=4&offset=2',
    'cat' => '-20,-18'));

    That’s the wrong way to do it. Try this instead:

    query_posts( array(
    'showposts'=>4,
    'offset'=>2,
    'cat' => '-20,-18'));

    That should get what you want. Same goes for the others following that one.

    Thread Starter Gregg

    (@cinemadiving)

    You are an absolute star Otto42. That works perfectly and the site is looking much better … thank you so much. It’s tough trying to add functionality with so little PHP experience.

    Cheers.

    Hi Otto42, I am using the same theme but I am wanting to take out the showpost 4 & offset 2. For some reason when I remove this code it causes the site to do some funky stuff. I just want my post to look like my first post. My site is https://www.feltandfitted.com

    Here is the php code

    Cinemadiving, nice work at using the theme. What tag widget are you using. that is pretty sweet!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to Exclude Posts While Using Showposts offset’ is closed to new replies.