if you had looked up the get_posts reference information in the codex, you would have found the ‘exclude’ parameter.
http://codex.wordpress.org/Template_Tags/get_posts
enjoy π
Thread Starter
medak
(@medak)
Hey
I looked. but $exclude is just for a specific ID, not for a category.
Am i wrong?
Ahh no you’re not *I’m* wrong. Sorry.
use query_posts() to create a custom loop instead http://codex.wordpress.org/Template_Tags/query_posts
this one *does* allow you to exclude categories.
Thread Starter
medak
(@medak)
I looked at query_posts, but i tried almost everything i could, but i didn’t manage to do it right. It displays or pages or posts, but not pages and posts.
I spend last 2 hours looking for the solution to display pages and posts at the same time, but i didn’t find it π
Do you have any idea?
well, I don’t understand how your pages are supposed to work in the chronology.
do you create new pages all the time? if so, why the hell would you do that when you can just post into a new category?
pages and posts are almost identical, until that ‘almost’ part comes to bite you in the ass at display time.
Thread Starter
medak
(@medak)
π
Unfortunately yes, i can not use categories for this purpose.
And yes, that ‘almost’ is a big pain in the ass π
ps: pozdrav u Austrailiju
OK… since there seems to be no wordpress function which will do exactly what you want, you have 2 choices.
1) write your own SQL query, which is effective, but not very future-resistant. It would be best to use wordpress functions.
2) use wordpress functions but cheat a little. It’s not going to win you any programming awards, but it’ll work.
consider pulling more results than you need, but only outputting the first 5. This should compensate for any posts in the category you wish to exclude.
lets try this:
<?php
$count = 1;
$postslist = get_posts('post_type&numberposts=10&offset=2');
foreach ($postslist as $post) :
setup_postdata($post);
if (!in_category('3') && $count < 6) :
?>
<div id="post-<?php echo $count++; ?>" class="posti">
<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<?php the_content_limit(150,'VeΔ →'); ?>
</div>
<?php
endif;
endforeach;
?>
puno sreΔe.
Thread Starter
medak
(@medak)
Thank you very much!
The code works great, just now ther is a problem with offset π
Look at this example(1. is last posted, 2. is second last posted…:
1.postZZZ-(published in category 3)
2.postXXX-(not published in category 3)
3.postYYY-(not published in category 3)
4.postMMM-(not published in category 3)
If offset=2, the first post to apper it will postYYY. But i need to display the postMMM. Offset in my situacion is relativ (i want to skip first two posts that are not from category 3, but the first two latest posts). Do you know what i mean? π
Hi,
I was having a similar problem. I ended up using
query_posts("cat=-X")
where X is the category you want to exclude. I found that this didn’t interfere with the count in the loop and it now shows the appropriate number of posts excluding the category I wanted hidden.
I just placed it in my code before the
if (have_posts()) :
Codex: query_posts > Category Parameters