In this tutorial of php code for beginners we will show you how to show the posts of perticular category in WordPress
The below code will show only posts of category id 1.
The below code will show only posts of category id 1.
<ul>
<?php
global $post;
$args = array('category' => 1); //specify category ID
$selectedposts = get_posts( $args );
foreach( $selectedposts as $post ) : setup_postdata($post); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; wp_reset_postdata(); ?>
</ul>
Hope this php tutorial is useful for you. Keep following www.phpcodeforbeginner.blogspot.in for more help.<?php
global $post;
$args = array('category' => 1); //specify category ID
$selectedposts = get_posts( $args );
foreach( $selectedposts as $post ) : setup_postdata($post); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; wp_reset_postdata(); ?>
</ul>
No comments:
Post a Comment