• Resolved phyllis

    (@phyllis)


    I have a category called “Urgent Announcements.” The idea is to have posts in this category show up at the top of my index page. I have had success, thus far, in getting it to show the post title from the category. However, using <?php the_content(); ?> does not render the content of the post in that category, but the content of the whole blog.

    Thus, how can I show the actual content of a post that resides in a given category. In case it would be useful, here is the snip of code I am using to call the Title:

    <?php
    $postlist = get_posts('category=2&numberposts=5');
    foreach ($postlist as $post) :
    ?>
    <div id=\"urgent-news\">
    <a href=\"<?php the_permalink(); ?>\"><?php the_title(); ?></a>
    </div>
    <?php endforeach; ?>

    What I want is the content from that category as well as the title.

    Thanks for any help.

Viewing 1 replies (of 1 total)
  • Thread Starter phyllis

    (@phyllis)

    I solved this myself by using a method suggested by the asides. href=”http://codex.wordpress.org/Adding_Asides#Displaying_Asides_on_the_Sidebar”&gt;

    My final snippet looked like the following:

    <!– Begin Urgent Announcements Loop –>

    <?php
    if ($posts) : foreach ($posts as $post) : start_wp();
    ?>
    <?php if (in_category(14)) { ?>
    <div class=\\"asides_sidebar\\">
     <?php echo $post->post_excerpt ?> <?php the_content(); ?>
     <small><?php comments_popup_link(__('#'), __('(1)'), __('(%)')); ?>
       <?php edit_post_link('Edit', ' — '); ?></small>
    </div>
    <?php } ?>
    <?php endforeach; else: ?>
    <?php _e('Sorry, no posts matched your criteria.'); ?>
    
    <?php endif; ?>
    
    <!-- End Urgent Announcements Loop -->
    
    <!-- Begin Main Content, Excluding Urgent Announcements Category -->
    
    <?php rewind_posts(); ?>
    
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <!-- If the post is in the category we want to exclude, we simply pass to the next post. -->
    
    <!-- insert data here -->
    
    <?php endwhile; ?>
    <?php else : ?>
    <h2 class=\\"center\\">Not Found</h2>
    <p class=\\"center\\">Sorry, but you are looking for something that isn't here.</p>
    <?php endif; ?>
    
    <!-- End Main Content -->

    For brevity’s sake, I did not post all of the things that should come within the loop. I did, however, place a comment where those things should be placed.

Viewing 1 replies (of 1 total)

The topic ‘Display Post from a Particular Category’ is closed to new replies.