• I have added a box to the top of my blog that I want to contain all the posts made in the “Site news” category. The idea being people can collapse the news box so site news doesn’t get mixed up with the actual posts. Is there a php include or something I can use to show posts made in the site news category in that div tag?
    You can view my site at: https://www.blogfrog.co.uk where there you can see where the news is going to go if my explanation wasn’t very clear.
    Thanks a lot.

Viewing 7 replies - 1 through 7 (of 7 total)
  • There are several solutions presented in the Codex. See
    https://codex.www.ads-software.com/The_Loop
    (especially Multiple Loops examples)
    https://codex.www.ads-software.com/The_Loop_in_Action
    https://codex.www.ads-software.com/Template_Tags/query_posts
    [for the moment it is down but hopefully it will be back soon]

    Thread Starter Edd

    (@edd)

    Thanks for those links, I am still having a bit of trouble though. I’ve figured I need to use something like:
    <?php
    get_header();
    if (have_posts()) :
    while (have_posts()) :
    the_post();
    the_content();
    endwhile;
    endif;
    get_sidebar();
    get_footer();
    ?>

    And I found I need to include query_posts("cat=2"); as well. The above code generates posts from all categories, and when I try adding the query posts line I just get a 404 error. Where should I be putting that line?
    Many thanks,

    If you take a closer look to the Multiple Loops examples and also the query_posts examples – it is always before the Loop.

    Thread Starter Edd

    (@edd)

    I had another look and I got:
    <?php $my_query = new WP_Query('category_name=Site-news&showposts=10'); ?>

    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <!-- Do special_cat stuff... -->
    <?php endwhile; ?>

    I do this and nothing happens, it seemingly just ignores the code. What have a I done wrong? Also, the category is called “Site news” – how should I express that space? I have tried underscores, hypens, %20 but none made a difference to a bit of clarifcation on that would help too.
    Thanks for the help so far ??

    Insert the category name as it is
    WP_Query('category_name=Site news&showposts=10')

    <!-- Do special_cat stuff... -->
    Did you replace this with the template tags you want to use there? E.g. the_title, the_content etc. see how it is done in your “normal” Loop ??

    Thread Starter Edd

    (@edd)

    Thanks SO much for the help, I have got it working now! It was what you suggested, I didn’t realise!
    Thanks again!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Calling all posts from one category’ is closed to new replies.