The MU forums have moved to WordPress.org

Calling Posts from a Specific Category (12 posts)

  1. boatwizard
    Member
    Posted 14 years ago #

    I just want to display posts per one category (e.g. cat_ID=8).

    Have tried:

    <?php if (is_page()) { query_posts('cat_ID=8'); } ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    And...

    <?php query_posts('cat_ID=8'); ?>

    <?php if (is_page()) { query_posts("cat_ID=8"); } ?>

    <?php if(is_category('8')) continue; ?>

    <?php if (have_posts()) : ?>

    <?php query_posts(array('category__and' => array(8,1))); ?>

    <?php query_posts('cat=8''); ?>

    Stuck! Shows blank white page when it's wrong, currently it is showing all posts.

  2. boatwizard
    Member
    Posted 14 years ago #

    Full page code if it helps:

    <?php
    /**
    * @package WordPress
    * @subpackage Default_Theme
    */
    /*
    Template Name: Charter Posts
    */
    get_header(); ?>
    <div id="content_charter">
    <h1>Charter Articles</h1>

    <?php query_posts('cat_ID=8'); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="post">
    " rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?>
    <?php the_excerpt_reloaded(100, '', 'none', TRUE, '(Read more...)', TRUE, 1, TRUE); ?>
    </div>
    <?php endwhile; ?>
    <div class="navigation">
    <div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
    </div>
    <?php else : ?>
    <h2 class="center">Not Found</h2>
    <?php include (TEMPLATEPATH . '/searchform.php'); ?>
    <?php endif; ?>
    </div>
    <?php get_footer(); ?>

  3. dsader
    Member
    Posted 14 years ago #

    First, a whitescreen may mean there will be an error reported in your error_log. Very useful as it will pinpoint which line/function/file is throwing the error. Check your error logs.

    Following the examples here
    http://codex.wordpress.org/Template_Tags/query_posts#Category_Parameters

    Example:
    query_posts('cat=8');

    Therefore

    <h1>Charter Articles</h1>
    
    <?php query_posts('cat8'); ?>
    <?php if (have_posts()) : ?>

    Your examples above contain typo errors ... there is no cat_ID parameter. cat_ID is ignored and all posts are listed.

    query_posts('cat=8''); should generate an error for the extra '

    Try the examples listed in the codex, without the the_excerpt_reloaded plugin (try just the_excerpt(); ) till you know you are getting the display you want, then turn the plugin back on.

  4. boatwizard
    Member
    Posted 14 years ago #

    Strange. Can't see error logs and Firefox Console doesn't give anything away.

    If I don't use the line

    <?php if (is_page()) { query_posts('cat=8'); } ?>

    I get a link to the page, obviously because WP sees pages as posts. this page used as a template is post ID = 81.

    <div id="content_charter">
    <h1>Charter Articles</h1>

    <?php if (have_posts()) : ?>
    <?php if (is_page()) { query_posts('cat=8'); } ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <span class="title">" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></span>
    <span class="date"><?php the_time('F jS Y') ?></span>
    <?php the_excerpt_reloaded(100, '', 'none', TRUE, 'Read more...', TRUE, 1, TRUE); ?>

    </div>
    <?php endwhile; ?>
    <div class="navigation">
    <div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
    </div>

    <?php else : ?>
    <h2 class="center">Not Found</h2>
    <p class="center">Sorry, but you are looking for something that isn't here.</p>
    <?php include (TEMPLATEPATH . "/searchform.php"); ?>
    <?php endif; ?>
    </div>
    <?php get_footer(); ?>

  5. boatwizard
    Member
    Posted 14 years ago #

    Your examples above contain typo errors ... there is no cat_ID parameter. cat_ID is ignored and all posts are listed.

    It MPMU it says "cat_ID" though!

  6. andrea_r
    Moderator
    Posted 14 years ago #

    There's a flaw in your logic - in most cases, pages CANNOT have a category assigned to them.

  7. dsader
    Member
    Posted 14 years ago #

    "It MPMU it says "cat_ID" though"

    Official Template Tags WP=WPMU: http://codex.wordpress.org/Template_Tags/

    cat_ID if in admin, yes. But you are designing a Template, therefore, template tags.

    "Can't see error_logs"? I'd fix that ASAP. They should be accessible via FTP amongst your WPMU installed files/folders. Really in the dark otherwise, IMHO.

  8. boatwizard
    Member
    Posted 14 years ago #

    Got rid of white pages. In settings > reading I set to show Front Page as a new template created. For posts I set it to display in new template.

    Template has:

    <?php if (is_page()) { query_posts("cat=8"); } ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <span class="title">" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></span>
    <span class="date"><?php the_time('F jS Y') ?></span>
    <?php the_excerpt_reloaded(100, '', 'none', TRUE, 'Read more...', TRUE, 1, TRUE); ?>

    </div>
    <?php endwhile; ?>
    <div class="navigation">
    <div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
    </div>

    which all seems to work fine except showing posts per one category. Used "cat=8" and "category_name=Charter Yachts" but neither work. It is showing all posts, not from the one category as I want.

    Why can't pages have a category assigned to them? Why would we not want to show a page which lists all posts form one category and another page with posts from another category?

  9. andrea_r
    Moderator
    Posted 14 years ago #

    Why would we not want to show a page which lists all posts form one category and another page with posts from another category?

    Because you don't use Pages or Page template sin that case.

    You use the category archives templates. Because they deal with category archives. When presented to the user, they look like a page, but aren't.

  10. boatwizard
    Member
    Posted 14 years ago #

    I wanted to show featured articles and therefore call them from a category called "featured". Have done this in WP, can't see why it won't work in WMPU.

  11. dsader
    Member
    Posted 14 years ago #

    is_page() "refers to WordPress Pages, not any generic webpage from your blog."

    http://codex.wordpress.org/Pages

    http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page

    Change this
    <?php if (is_page()) { query_posts("cat=8"); } ?>
    into
    '<?php query_posts("cat=8"); ?>'

  12. boatwizard
    Member
    Posted 14 years ago #

    Hi dsader,

    I forgot to thank you - your solution worked a treat :-)

    Thanks.

About this Topic

  • Started 14 years ago by boatwizard
  • Latest reply from boatwizard