Monday, May 3, 2010

How to show post from a particular category widget

<?php $my_query = new WP_Query('category_name=mycategory&showposts=1'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a><br /><?php the_content(); ?><?php endwhile; ?>



===================================
<?php      $args=array(        'cat' => 1,        'posts_per_page'=>5,        'caller_get_posts'=>1      ); 
$my_query = new WP_Query($args); if( $my_query->have_posts() ) {

echo '5 recent Posts from category 1'; while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?></a></p>
<?php endwhile; } //if ($my_query) wp_reset_query();
// Restore global post data stomped by the_post(). ?>

No comments:

Post a Comment