首页 论坛 WordPress调用全站置顶文章和分类置顶文章代码
帖子详情

WordPress调用全站的置顶文章代码:

<?php $query_post = array(
 'posts_per_page' => 5,
 'post__in' => get_option('sticky_posts'),
 'caller_get_posts' => 1
);
query_posts($query_post);
?>
<?php while(have_posts()):the_post(); ?>

  <li class="li1"><a href="<?php the_permalink() ?>">
  <img src="<?php echo get_first_image(); ?>" width="197px" height="145px" /><span><?php the_title(); ?></span></a></li>

  <?php endwhile; ?>
 <?php wp_reset_query();?>

WordPress调用指定分类下的置顶文章代码:

<?php
$args = array(
'post_type' => 'post',
'showposts' => 3,
//'orderby' => 'rand',
'post__in' => get_option('sticky_posts'),//获取置顶文章
'cat' => array(8),//指定分类id
);
?>
<?php
$catquery = new WP_Query($args);
while($catquery->have_posts()) : $catquery->the_post();

?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php wp_reset_query();?>

版权:言论仅代表个人观点,不代表官方立场。转载请注明出处:https://www.52diyhome.com/forum/65553.html

发表评论
暂无评论
  • 0 +

    访问总数

  • 0 +

    会员总数

  • 0 +

    资源总数

  • 0 +

    今日发布

  • 0 +

    本周发布

  • 0 +

    运行天数

资源在于分享,创作来源想象