Support » Fixing WordPress » Display posts from one category on one page

Viewing 7 replies - 1 through 7 (of 7 total)
  • This is a pretty decent plugin for that problem:

    And if you want to code it yourself you can always add this to your page.php (BEFORE the loop):

    if( is_page( 'news' ) {
             query_posts( array( 'category_name' => 'news' ) );

    (By the way; i recommend using the ‘code it yourself option’; the plugin is alright but isn’t optimal for page-load.


    I’m going to try the code option, but forgive me if this is a dumb question, but where’s the loop?

    The loop is what we call the piece of code that gets the posts or page out of the database and puts it in your theme. So it’s not a dumb question at all… it’s actually pretty advanced 😉

    You’ll recognize it by this line:

    if ( have_posts( ) while( have_posts() ) : the_post()

    Thanks, you’ve been a big help. I do have one more question though. I don’t have anything that looks like that code. At least I don’t think so.

    This is from my page.php file:

     * @template  Mystique
     * @revised   December 20, 2011
     * @author    digitalnature,
     * @license   GPL,
    // The "page" post type.
    // pagename.php, page-slug.php, page-id.php or page-custom_template can override it.
    <?php atom()->template('header'); ?>
    <!-- main content: primary + sidebar(s) -->
    <div id="mask-3" class="clear-block">
      <div id="mask-2">
        <div id="mask-1">
          <!-- primary content -->
          <div id="primary-content">
            <div class="blocks clear-block">
              <?php atom()->action('before_primary'); ?>
              <?php the_post(); ?>
              <?php atom()->action('before_post'); ?>
              <!-- page content -->
     <div id="post-<?php the_ID(); ?>" <?php post_class('primary'); ?>>
                <?php if(!atom()->post->getMeta('hide_title')): ?>
                <h1 class="title"><?php the_title(); ?></h1>
                <?php endif; ?>
                <div class="clear-block">
                  <?php the_content(); ?>
                <?php atom()->post->pagination(); ?>
                <?php atom()->controls('post-edit'); ?>
              <!-- /page content -->
              <?php atom()->action('after_post'); ?>
              <?php atom()->template('meta'); ?>
              <?php atom()->action('after_primary'); ?>
          <!-- /primary content -->
          <?php atom()->template('sidebar'); ?>
    <!-- /main content -->
    <?php atom()->template('footer'); ?>

    I’m not really sure where I need to put that like of code.

    Ah, okay; this particular theme decided to put all the loop-information into other files and functions; that makes it a bit harder.

    My best guess is to put it in between these lines:
    <div id="mask-1">
    <!-- primary content -->

    So that would make:

    <div id="mask-1">
    if( is_page( 'news' ) {
             query_posts( array( 'category_name' => 'news' ) );
    <!-- primary content -->

    Ofcourse this will only work on the page ‘news’ with the category name ‘news’, but you can always change the ‘news’-strings to something else…

    Doesn’t work for me, gives me a blank page instead. Hmm.

    I tried this code snippet as follows:

    ‘<?php if (is_page( ‘whiskycast-episodes’) {
    query_posts( array( ‘category_name’ => ‘episodes’ ( ) ;
    } ?>’

    However, reloading the specific page returned all of my posts from all of my categories.

    Any idea where I might have messed up…I’m not a coder by any means.



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