WordPress.org

Ready to get started?Download WordPress

Forums

Display posts from one category on one page (8 posts)

  1. Noodle123
    Member
    Posted 2 years ago #

    Hey guys,

    I'm using the theme Mystique (http://digitalnature.eu/themes/mystique/) and I'm trying to show posts from only one category on one page.

    For example, I have a category "news" and I have a page named "News." I want all the content that is in the category "news" to show on the "news" page. That's not to say that I don't want it on the main page as well.

    But I want it a certain way. The best way to show you is if you look at this site: http://nerdreactor.com/. And then look at their page for video games: http://nerdreactor.com/category/videogames/.

    That's what I would like to do also.

  2. LucP
    Member
    Posted 2 years ago #

    This is a pretty decent plugin for that problem: http://wordpress.org/extend/plugins/wp-posts-filter/

    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.

  3. Noodle123
    Member
    Posted 2 years ago #

    Thanks.

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

  4. LucP
    Member
    Posted 2 years ago #

    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()
  5. Noodle123
    Member
    Posted 2 years ago #

    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:

    <?php
    
    /*
     * @template  Mystique
     * @revised   December 20, 2011
     * @author    digitalnature, http://digitalnature.eu
     * @license   GPL, http://www.opensource.org/licenses/gpl-license
     */
    
    // 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(); ?>
                </div>
    
                <?php atom()->post->pagination(); ?>
    
                <?php atom()->controls('post-edit'); ?>
              </div>
              <!-- /page content -->
    
              <?php atom()->action('after_post'); ?>
    
              <?php atom()->template('meta'); ?>
    
              <?php atom()->action('after_primary'); ?>
    
            </div>
          </div>
          <!-- /primary content -->
    
          <?php atom()->template('sidebar'); ?>
    
        </div>
      </div>
    </div>
    <!-- /main content -->
    
    <?php atom()->template('footer'); ?>

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

  6. LucP
    Member
    Posted 2 years ago #

    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">
    and
    <!-- primary content -->

    So that would make:

    <div id="mask-1">
      <?php
    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...

  7. phalancs
    Member
    Posted 1 year ago #

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

  8. mpgillespie
    Member
    Posted 1 year ago #

    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.

    Thanks!

    Mark

Topic Closed

This topic has been closed to new replies.

About this Topic