Search code examples
wordpressposts

How to display post names by News category


I want to display post names by News category. I am using following code but not working

<?php
    query_posts(array('&category_name=News&showposts=5'));
    while (have_posts()) : the_post();
        the_title();
    endwhile;
?>

Solution

  • Try This.

      <?php
    
           $args = array('cat' => 5);  //pass news category Id.
    
            // The Query
            query_posts( $args );
    
            // The Loop
            while ( have_posts() ) : the_post();
                echo '<li>';
                the_title();
                echo '</li>';
            endwhile;
    
            // Reset Query
            wp_reset_query();
    ?>