最近又在折腾自己的wordpress博客,突然想把之前博客调用置顶文章的区块改成调用指定ID文章,于是便寻思着如何实现。

在网上搜了搜,发现利用WordPress函数get_post(),能够调用指定ID的文章链接、标题及内容。

下面是调用文章ID为1的文章:

<?php
$post_id = 1; // 文章ID
echo get_post( $post_id )->post_content; // 输出文章的内容
echo get_post( $post_id )->post_title; // 输出文章的标题
?>

 

下面是调用文章ID为1,2,3的文章:

<?php
$postsl = get_posts(\"numberposts=4&post_type=any&include=1,2,3\");
if($postsl) : foreach( $postsl as $post ) : setup_postdata( $post );
?>
<li><a href=\"<?php the_permalink(); ?>\" rel=\"external nofollow\" ><?php the_title();?></a></li>
<?php endforeach; endif; ?>

 

 

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。