I'm trying to accomplish the following:

I wan't to display all posts from a certain category on a page that has the same layout as the homepage of the actual blog.

I found the following online to display posts for the category

<?php $recent = new WP_Query("cat=797&showposts=30"); while($recent->have_posts()) : $recent->the_post();?>

but I don't know

a) should I just take my index.php and edit the loop to the above

b) where should I place this new file? in the root of my WP install or in the themes folder?


My homepage is a regular "archive" showing the latest posts for any category

The current loop starts with

    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>   
    <?php global $ar_ID; global $post; $ar_ID[] = $post->ID; ?>

Entire index.php is here

  • Is homepage a page or a regular archive? Because if it's a regular archive (loop), any archive will usually share the visuals. You need to provide examples as all loops usually look the same and your question is quite theme dependent. – EarnestoDev Oct 29 '11 at 18:02
  • Edited to answer your questions. – Jan Henckens Oct 29 '11 at 18:37
  • So the category archive does not do what you want? Or you want ALL posts and not paginated? Or the archive.php is styled differently compared to index.php. Usually the archive is handled by index.php which shows both homepage posts and category/tag posts. Only if you have a different design from the homepage, you actually have a problem. Are you asking how to point a category archive to index.php instead of archive.php or another template file it uses? – EarnestoDev Oct 29 '11 at 18:47
  • I want the same layout/design as the actual homepage, displaying only posts for a certain category but i'm not sure into which page I should add the code. – Jan Henckens Oct 29 '11 at 19:03

This should help you, the second diagram... this one.

Just copy the index.php code to the properly named category-*.php file and see if it works.

  • Where would I place the new file? In the folder of the used theme or on the site's root? – Jan Henckens Oct 29 '11 at 19:48
  • In the theme folder. Where the index.php of the theme exists. And make sure you replace the * with the ID or slug of the category. – EarnestoDev Oct 29 '11 at 19:52
  • Done. Now, how do I get to the page is just created? (sounds stupid but since it's in the themes folder I can't just do domain/category-*.php...) – Jan Henckens Oct 29 '11 at 20:02
  • 1
    :) Add a Categories Widget and click the category you need. Really? – EarnestoDev Oct 29 '11 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.