开发者

Wordpress If post title already on page remove from list

This is a bit of a complex one I have been working on. I have four main categories. Formal, Fasion, Social and Wedding. I have Wordpress set up so it shows the twelve most recent posts of all these in one section.

    <li> 
<?php $recent = new WP_Query("category_name=social,fashion,wedding,formal&showposts=1&offset=1"); while($recent->have_posts()) : $recent->the_post();?>
<div class="show">
    <a class="thumb" href="<?php the_permalink() ?>">
        <?php the_post_thumbnail(); ?>
    </a>

    <a href="<?php the_permalink() ?>">
            <section class="phototitle"><p><?php the_title(); ?></p></section>
    </a>
</div>
<?php endwhile; ?>
</li>

This works fine and I use the offset function to show them over and over.

I then have the same four categories listed below this in separated boxes. So they have a bit of order.

<section class="postlist">
<h1>Formal</h1>
<hr>
<?php $recent = new WP_Query("category_name=formal&showposts=6"); while($recent->have_posts()) : $recent->the_post();?>
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a><br />
<?php endwhile; ?>
</section>

My question is how do I stop repeat posts from the top section so the postlist section will have different link titles.

I thought it might be something to do with the exclude technique and if the title already appears on the page remove it. Or if title is on page and if child of top section remove or something along those lines.

The problem is the top sectio开发者_StackOverflown is random so I can just offset it by 12.

Any input appreciated.

Cheers


You can collect the post id's you already displayed and then make use of the WP_Query exclude feature for the second query. Already displayed posts will be excluded then.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜