Support » Themes and Templates » Recent posts (Show category name & Exclude a category)

  • Resolved atdheh


    Hello, I’m showing recent posts with this:

    <ul><li><h2>Recent posts</h2><ul>
    <?php wp_get_archives('title_li=&type=postbypost&limit=15'); ?>

    This code to me only display my 15 recent post titles (linked):


    Now I want to display category name too, example:
    category – postname1
    category – postname2

    category – postname3

    How to exclude posts from a category, example to exclude posts from category 88.

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • MichaelH


    This might be easier:

          'category__not_in' => array(88),
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          echo '15 recent Posts';
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <p> <?php the_category(', '); ?> -
          <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        } //if ($my_query)
      wp_reset_query();  // Restore global post data stomped by the_post().


    MichaelH thank you, its working perfectly.

    But I have one question more:
    Its anyway to add this in sidebar?



    That could go in the sidebar template (probably sidebar.php) or even in a PHP Code Widget

    Is there an easy way for a non PHP guy like me to exclude post from certain categories while showing the recent posts of another category in the sidebar?

    I appreciate all the help you can provide.

    ~ John

    Is this what atdheh is asking ?

    trefethen may also be asking the same question I have – in the Recent Posts sidebar widget is it possible to exclude posts of a specified category?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Recent posts (Show category name & Exclude a category)’ is closed to new replies.