[Custom loop] Pulling posts by category into pages (3 posts)

  1. jawtry
    Posted 7 years ago #

    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;'); ?>
    <?php endwhile; ?>

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

  2. ionut442
    Posted 7 years ago #


    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

  3. Amanda Giles
    Posted 6 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic