wordpress 当前页面的子页面 获取

2019年12月14日07:22:28 发表评论 热度332 ℃

定制wordpress企业主题的时候,很多人喜欢不去设置页面的侧栏菜单,想直接通过设置页面的父子级关系来自动显示wordpress 当前页面的子页面名和链接,其实是可以的,方法很简单,将以下代码插入到你页面的侧栏位置即可实现!

  1. <?php  
  2. if($post->post_parent)  
  3.     $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");  
  4. else  
  5.     $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");  
  6. if ($children) {  
  7.     echo '<ul>';  
  8.         echo $children;  
  9.     echo '</ul>';  
  10. } ?>  

实现方法很简单,需要的朋友可以试试!

瓜皮猪

发表评论

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