2017-04-04 1 views
0

https://wordpress.org/plugins/if-menu/을 사용하여 특정 페이지에 상위 페이지와 하위 페이지를 표시하는 조건을 만듭니다.WordPress if-menu 조건

add_filter('if_menu_conditions', 'my_new_menu_condition'); 

function my_new_menu_condition($conditions) { 

global $post; 

$conditions[] = array(
    'name' => 'Condition Name', // name of the condition 
    'condition' => function($item) {   // callback - must return TRUE or FALSE 
     return is_page('Parent Page') || is_page('Parent Page') && $post->post_parent > 0; 
    } 
); 

    return $conditions; 
} 

나는 많은 행운이 없다. 누구든지이 플러그인에 대한 경험이 있고 이것이 가능한지 알고 있습니까?

고마워요.

+0

http://wordpress.stackexchange.com/ – mkaatman

+0

이 추가? 항상 '부모 페이지'라는 페이지를 평가합니다. 당신이 원하는 조건은 무엇입니까? 그게 문제가있는 곳인 것처럼 보입니다. –

+0

답장을 보내 주셔서 감사합니다. 도시 이름을 나타내는 여러 페이지가 있습니다. 각 도시 이름에는 커뮤니티 하위 페이지가 있습니다. nav에 도시를 표시하여 해당 페이지에만 표시하고 싶습니다. 현재 문제없이 부모에게 보여 주지만 하위 페이지로 이동하면 부모 링크가 탐색에 표시되지 않습니다. 말이된다? –

답변

0

다른 사람에게이 문제가 발생합니다. 여기 나를 위해 일한 것이 있습니다.

당신이 확인하고자하는 것을 말할 어려운 조건에서 당신의 functions.php

add_filter('if_menu_conditions', 'my_new_menu_condition'); 


function my_new_menu_condition($conditions) { 
    $conditions[] = array(
    'name' => 'insertpagename', // name of the condition 
    'condition' => function(){ 
     global $post; 
     $pages = get_pages(); 
     $post_parent = get_post($post->post_parent); 
     foreach ($pages as $page) { 
      if (is_page('insertpagename') || $post_parent->post_name == 'insertpagename') { 
       return is_page(); 
      } 
     } 
     } 
); 

    $conditions[] = array(
     'name' => 'insertpagename2', // name of the condition 
     'condition' => function(){ 
      global $post; 
      $pages = get_pages(); 
      $post_parent = get_post($post->post_parent); 
      foreach ($pages as $page) { 
       if (is_page('insertpagename2') || $post_parent->post_name == 'insertpagename2') { 
        return is_page(); 
       } 
      } 
      } 
); 
    return $conditions; 
}