• hi i have a question! this is my sidebar, it displays the most recent posts but im wondering if i can get it to only display the posts from a certain category? im using the template nautica magazine. this is my sidebar code:
    ‘<!– Right link column –>

    <div class=”floatRight width25 lightBlueBg horzPad”>

    <h3>About <span class=”dark”>the site</span></h3>

    <ul class=”submenu2″>

    • Write something about your site here.
    • <h3>Recent <span class=”dark”>articles</span></h3>

      <ul class=”submenu2″>

      <?php get_archives(‘postbypost’, ’10’, ‘custom’, ‘

    • ‘, ‘
    • ‘); ?>

      </div>

      <!– Right links column end –>

      thanks!

Viewing 1 replies (of 1 total)
  • You could do it by using the query_posts function.

    <?php query_posts('category_name=CATEGORYNAME'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    <?php endwhile; ?><?php endif; ?>

    where CATEGORYNAME is the actual name of the category. You could also call the category by ID. Instead of using category_name= you would use cat= such as…

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

    where X is the numerical ID of the category.

    You’ll have to use your theme’s styling to make it look right.

    Here is another option using the get_posts function.

    <?php
    global $post;
    $myposts = get_posts('numberposts=5&category=4');
    foreach($myposts as $post) :
    ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>

    This will dislay 5 entries from the category whose numerical ID is 4.

Viewing 1 replies (of 1 total)

The topic ‘Sidebar- Displaying Certain Catefories’ is closed to new replies.