动态wordpress侧边栏

时间:2013-10-07 11:23:49

标签: php wordpress

我正在尝试在我的wordpress网站上实现一个侧边栏,它目前是静态的,但我希望它是动态的。

我想要的是页面检查'页面加载'是否该特定页面是否有子页面。如果是,那么它应该在右边显示一个侧边栏,显示当前页面下的所有子页面。

我可以在普通的PHP中实现它。但是,我不知道如何在wordpress中做。

我是wordpress的新手。所以,我真的不知道怎么回事。

这是我想要显示的侧边栏:

<div class="sidebar">
  <h2>In This Section</h2>
  <ul>
    <li style="list-style:none"><h3><a href="#">Sub Page 1</a></h3></li>
    <li style="list-style:none"><h3><a href="#">Sub Page 2</a></h3></li>
    <li style="list-style:none"><h3><a href="#">Sub Page 3</a></h3></li>
  </ul>
  <br />
</div>

2 个答案:

答案 0 :(得分:0)

您正在寻找的功能是wp_list_pages

该页面甚至在Listing sub pages上有一整节。

答案 1 :(得分:0)

<?php
add_Action('init','any_name'); // call any_name function on initialize 
function any_name(){
global $post;     // if outside the loop

if ( is_page() && $post->post_parent ) {
    // This is a subpage

} else {
    // This is not a subpage you can do here whatever you want 
    // get sidebar
    get_sidebar(); // this will include sidebar.php
     // or something specific 

     get_sidebar('custom'); // this will include sidebar-custom.php
}

}     ?&GT;

相关问题