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 »'); ?> </div> </div> <?php endwhile; ?>
Site I’m developing is at http://test.fireflyrpg.com
- The topic ‘[Custom loop] Pulling posts by category into pages’ is closed to new replies.