• Resolved notreallysure

    (@notreallysure)


    Hey guys

    I’m pretty new to wordpress and my PHP experience is limited. I’ve been dancing around this and unfortunately can’t find my exact answer in the Codex.

    I have assigned a specific category (I call it Featured) and it has a cat_id of 44. I want to grab any post that is checked in the featured category and display it within in my set div.

    I have looked over the get_the_category and haven’t been able to make it happen, it just displays the array I tried to call.

    <?php
    global $post;
    $categories = get_the_category($post->ID);
    var_dump($categories);
    ?>

    (I realize this is probably because I haven’t assigned the variable $categories but again, not really sure…

    Not really sure… any help is greatly appreciated. Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • get_the_category simply returns a list of categories that a given post has been assigned to. So it’s not suitable for your purposes.

    query_posts might be better.

    You want a The Loop to do that.

    A get_posts loop with something like this to display 8 posts in category 44, date order, newest date first

    <?php
    $cat = 44
    $args = array(
      'orderby' => 'date',
      'order' => 'DESC',
      'post_type' => 'post',
      'numberposts' => 8,
      'category__in' => array($cat)
      );
    $posts=get_posts($args);
    if ($posts) {
      foreach($posts as $post) {
        setup_postdata($post);
        ?>
        <p><?php the_time('m.d.y') ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php }
      }
    }
    ?>

    What if 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))); ?>

    Stuck! Using WPMU 2.7.1

    query_posts('cat=8')

    Just cat, not cat_name, not cat_id, just plain old cat… 🙂 …

    Odd, just gave me a blank white page. Needs cat_ID to display! This is what I have (but shows posts from both categories):

    <?php query_posts(‘cat_ID=8’); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    This shows a blank white page;

    <?php query_posts(‘cat=8’); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    Probably have other problems with your theme, but the second set of code, as t31os_ explained, is correct.

    Also let me point out the MU support forums:
    http://mu.wordpress.org/forums

    Thanks, I have a post on other forum – just need to get as much awareness to this to fix it and thought WP Forum would do it! Theme seems to work otherwise – using basic theme although created new template using one from theme as basis.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Calling Posts from a Specific Category’ is closed to new replies.