最近又主题君官网大改版,突然想把之前博客调用置顶文章的区块改成调用指定ID文章,于是便寻思着如何实现。
在网上搜了搜,发现利用Wo󠄐󠄹󠅀󠄪󠄢󠄡󠄦󠄞󠄧󠄣󠄞󠄢󠄡󠄦󠄞󠄣󠄨󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄥󠄦󠄩󠄠󠄦󠄨󠄧󠄡󠄬󠅒󠅢󠄟󠄮rdPress函数get_post(),能够调用指定ID的文章链接、标题及内容。
下面是调用文章ID为1的文章:
<?php$post_id =1;// 文章IDecho 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;?>
精选优质免费WordPress主题模板,分享最新WordPress实用建站教程!
暂无评论内容