Support » Fixing WordPress » [Custom loop] Pulling posts by category into pages

  • I’m trying to create a series of pages that also pull posts in. I’ve gotten that far — the next step is that I’d like to have those posts be pulled by category. The trick is that I’d like a page to pull posts matching the the same category as the title.

    Example: A page with a title of “Ships” would pull in all posts with category of “Ships” … I know I could do this with a custom template for each page, but I’m trying to learn more PHP the “right” way. Here’s a snippet of relevant code:

    <?php $temp_query = $wp_query; ?>
    <?php $page_temp = the_title(); ?>
    <?php query_posts("category_name='$page_temp'&showposts=1"); ?>
    <?php while (have_posts()) : the_post(); ?>
      <div class="post" id="post-<?php the_ID(); ?>">
      <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
     <div class="entry">
       <?php the_content('Read more &raquo;'); ?>
     </div>
    	</div>
    <?php endwhile; ?>

    Site I’m developing is at http://test.fireflyrpg.com

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    I’m also trying to to this for my blog but I don’t know PHP. Can you help me please with this code, explaining me where I need to insert it?

    Thanks in advance

    jawtry: Did you get this working? I’m interested in doing something similar.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Custom loop] Pulling posts by category into pages’ is closed to new replies.