2013-10-07 2 views
0

내 워드 프레스 웹 사이트에 사이드 바를 구현하려고하는데, 현재 정적이지만 동적으로하고 싶습니다.동적 워드 프레스 사이드 바

내가 정확히 원하는 것은 특정 페이지에 하위 페이지가 있는지 여부를 '페이지로드시'확인하는 것입니다. 그렇다면 오른쪽에 현재 페이지 아래의 모든 하위 페이지를 보여주는 사이드 바를 표시해야합니다.

일반 PHP로 구현할 수 있습니다. 그러나, 나는 워드 프레스에서하는 방법을 모른다.

저는 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> 

답변

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 
} 

} ?>

관련 문제