函数 - parent 和 child 的 if 语句

functions - if statement for parent and child

我有以下 php 功能:

if ( ! function_exists('meteorite_sitebranding') ):
function meteorite_sitebranding() {
    $logo_light = get_theme_mod( 'logo_light', '' );
    $has_custom_logo = has_custom_logo();

    if ( $has_custom_logo || $logo_light) {
        if ( function_exists( 'the_custom_logo' ) && has_custom_logo() && is_front_page() || is_home() ) {          
            the_custom_logo();
        }
        elseif ( function_exists( 'the_custom_logo' ) && has_custom_logo() ) {
            echo '<a href="' . esc_url( home_url( '/' ) ) . '" rel="home"><img src="logo_color.png" class="custom-logo" alt="Auplo" itemprop="logo" /></a>';
        }

        elseif ( $logo_light ) {
            echo '<a href="' . esc_url( home_url( '/' ) ) . '" title="' . esc_attr(get_bloginfo('name')) . '"><img class="site-logo light" src="' . esc_url($logo_light) . '" alt="' . esc_attr(get_bloginfo('name')) . '" /></a>'; 
        }
    } else {
        echo '<div class="site-brand">';
        if ( is_front_page() && is_home() ) :
            echo '<h1 class="site-title"><a href="' . esc_url( home_url( '/' ) ) . '" rel="home">' . get_bloginfo('name', 'display') . '</a></h1>';
        else :
            echo '<p class="site-title"><a href="' . esc_url( home_url( '/' ) ) . '" rel="home">' . get_bloginfo('name', 'display') . '</a></p>';
        endif;
        echo '<p class="site-description">' . get_bloginfo('description', 'display') . '</p>';
        echo '</div>'; // /.site-brand
    }
}
endif;

该功能运行良好。但我想微调一下。我的问题与部分有关:

if ( function_exists( 'the_custom_logo' ) && has_custom_logo() &&
is_front_page() || is_home() )

如何将 OR is_page('destination') 的条件添加为语句的一部分并包含该页面的所有子项?所以例如我有第

目的地 + 纽约 + 华沙 + 都柏林 + 迪拜

我想涵盖所有这些页面。我试过做类似的事情:

|| is_page('destination') || is_child('destination') but simply it doesnt work..

谢谢!

你可以用这个

function is_child($pageID) { // In functions.php
  global $post; 
  if( is_page() && ($post->post_parent==$pageID) ) {
           return true;
  } else { 
           return false; 
  }
}

if(is_child(123)) { // in your template
 echo "Child page of 123";
}