hi, i am having troubles with the database. My posts are in 5 categories and when i want to display them (all), i only get posts from one. The other categories (the posts in them) do not display.
hi, i am having troubles with the database. My posts are in 5 categories and when i want to display them (all), i only get posts from one. The other categories (the posts in them) do not display.
More than likely theres's nothing wrong with your databse. The wordpress loop will display all posts by default. Are the other posts in categories of their own, or are they also in the default category?
the other posts are in categories of their own...
i use this to display them:
<?php query_posts('category=1,4'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php if (in_category('1')) { ?>
<div class="prispevek_1">
<?php the_title(); ?>
<?php the_content() ?>
</div>
<?php } else if (in_category('4')) { ?>
<div class="prispevek_2">
<?php the_title(); ?>
<?php the_content() ?>
</div>
<?php } ?>
<?php endwhile; ?>
but it works only with one category. these two it ignores :(
Most strange is that it worked for me perfectly, until...that's what i am not able to say - it's stopped working without a reason
thanks for you help
I don't know why it might have stopped working, but this is what I use for multiple loops on a page. A new WP query won't interfere with other queries or the main WP loop.
<?php $my_query = new WP_Query('category_name=mycategory&showposts=1'); ?><?php while ($my_query->have_posts()) : $my_query->the_post(); ?><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a><?php the_content() ?><?php endwhile; ?>
Showposts=1 will show one post; 5 will show 5; -1 will show all. Delete the <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"> if you don't want a permalink. Add your prispevek class in, too.
songdogtech thank you, your code works... :)
would you know, please, an answer to this too:
wanna have a sidebar with "news". In administration, I have news divided in two categories (lets say ecru and purple). To be more friendly to the visitor I want the particular news to show up in terms - one ecru one purple, one ecru one purple...
Again, this worked for me until it has stopped:
<?php query_posts('showposts='); ?>
<?php while (have_posts()) : the_post(); ?>
<?php if (in_category('1')) { ?>
<div class="rb_1">
<?php the_title(); ?>
<?php the_content() ?>
</div>
<?php } else if (in_category('4')) { ?>
<div class="rb_2">
<?php the_title(); ?>
<?php the_content() ?>
</div>
<?php } ?>
<?php endwhile; ?>
you might see the result here:
http://www.obec-ruzova.cz
(wordpress version - under testing - here:)
http://www.obec-ruzova.cz/wordpress
thank you a lot
just FYI - your code is now used in "uredni deska" :)
Glad it worked; It's not really "my" code, as I got some of it around these forums. Later today, I'll look at a way to make the categories different colors.....
This topic has been closed to new replies.