wordpress怎么获取指定某篇文章

wordpress可以通过get_post()这个函数来获取指定文章
用法:
参数$post_id,即文章id

get_post($post_id);

案例:
1.获取id等于29的文章标题

<?php echo get_post(29)->post_title;?>

2.获取id等于29的文章链接

<?php echo get_post(29)->guid;?>

3.获取id等于29的文章内容

<?php echo get_post(29)->post_content;?>

除了能获取文章标题、链接、内容还可以获取文章的其它字段
可以把get_post()获取到的结果打印出来,就可以看到有哪些字段了

<?php
  $res = get_post(29);
  echo '<pre>';
  print_r($res);                      
?>

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: