PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 8, 2022

[FIXED] How to display post names by News category

 July 08, 2022     posts, wordpress     No comments   

Issue

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();
?>


Answered By - Dev Danidhariya
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing