Skip to main content
details
Source Link
Valentin
  • 43
  • 2
  • 10

My need is to check if a page is subpage of a page (with ID).

I try to get this code working but it doesn't.

function is_child($pageID) {
  global $post;
  echo $post->post_parent; // display the right ID!
  if( is_page() && $post->post_parent == $pageID ) {
    return true;
  } else {
    return false;
  }
}

It returns always false while $post->post_parent returns the right ID!

Testing code (which always returns no while $post->$post_parent echoes the good ID in the function):

if(is_child(2310)) {
    echo 'yes';
} else {
    echo 'no';
}

This function takes place in my functions.php file and its purpose is to load CSS through a condition statement (load a particular CSS file if page is X or child of X).

This code can be found on many sites around there but was produced in 2012-2013.

Thanks a lot for any help.

Sources of unworking codes : https://bavotasan.com/2011/is_child-conditional-function-for-wordpress/ https://www.kevinleary.net/wordpress-is_child-for-advanced-navigation/

My need is to check if a page is subpage of a page (with ID).

I try to get this code working but it doesn't.

function is_child($pageID) {
  global $post;
  echo $post->post_parent; // display the right ID!
  if( is_page() && $post->post_parent == $pageID ) {
    return true;
  } else {
    return false;
  }
}

It returns always false while $post->post_parent returns the right ID!

Testing code (which always returns no while $post->$post_parent echoes the good ID in the function):

if(is_child(2310)) {
    echo 'yes';
} else {
    echo 'no';
}

This code can be found on many sites around there but was produced in 2012-2013.

Thanks a lot for any help.

Sources of unworking codes : https://bavotasan.com/2011/is_child-conditional-function-for-wordpress/ https://www.kevinleary.net/wordpress-is_child-for-advanced-navigation/

My need is to check if a page is subpage of a page (with ID).

I try to get this code working but it doesn't.

function is_child($pageID) {
  global $post;
  echo $post->post_parent; // display the right ID!
  if( is_page() && $post->post_parent == $pageID ) {
    return true;
  } else {
    return false;
  }
}

It returns always false while $post->post_parent returns the right ID!

Testing code (which always returns no while $post->$post_parent echoes the good ID in the function):

if(is_child(2310)) {
    echo 'yes';
} else {
    echo 'no';
}

This function takes place in my functions.php file and its purpose is to load CSS through a condition statement (load a particular CSS file if page is X or child of X).

This code can be found on many sites around there but was produced in 2012-2013.

Thanks a lot for any help.

Sources of unworking codes : https://bavotasan.com/2011/is_child-conditional-function-for-wordpress/ https://www.kevinleary.net/wordpress-is_child-for-advanced-navigation/

testing code
Source Link
Valentin
  • 43
  • 2
  • 10

My need is to check if a page is subpage of a page (with ID).

I try to get this code working but it doesn't.

function is_child($pageID) {
  global $post;
  echo $post->post_parent; // display the right ID!
  if( is_page() && ($post->post_parent == $pageID) ) {
    return true;
  } else {
    return false;
  }
}

It returns always false while $post->post_parent returns the right ID!

Testing code (which always returns no while $post->$post_parent echoes the good ID in the function):

if(is_child(2310)) {
    echo 'yes';
} else {
    echo 'no';
}

This code can be found on many sites around there but was produced in 2012-2013.

Thanks a lot for any help.

Sources of unworking codes : https://bavotasan.com/2011/is_child-conditional-function-for-wordpress/ https://www.kevinleary.net/wordpress-is_child-for-advanced-navigation/

My need is to check if a page is subpage of a page (with ID).

I try to get this code working but it doesn't.

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

It returns always false while $post->post_parent returns the right ID!

This code can be found on many sites around there but was produced in 2012-2013.

Thanks a lot for any help.

Sources of unworking codes : https://bavotasan.com/2011/is_child-conditional-function-for-wordpress/ https://www.kevinleary.net/wordpress-is_child-for-advanced-navigation/

My need is to check if a page is subpage of a page (with ID).

I try to get this code working but it doesn't.

function is_child($pageID) {
  global $post;
  echo $post->post_parent; // display the right ID!
  if( is_page() && $post->post_parent == $pageID ) {
    return true;
  } else {
    return false;
  }
}

It returns always false while $post->post_parent returns the right ID!

Testing code (which always returns no while $post->$post_parent echoes the good ID in the function):

if(is_child(2310)) {
    echo 'yes';
} else {
    echo 'no';
}

This code can be found on many sites around there but was produced in 2012-2013.

Thanks a lot for any help.

Sources of unworking codes : https://bavotasan.com/2011/is_child-conditional-function-for-wordpress/ https://www.kevinleary.net/wordpress-is_child-for-advanced-navigation/

include tests I've done
Source Link
Valentin
  • 43
  • 2
  • 10

My need is to check if a page is subpage of a page (with ID).

I try to get this code working but it doesn't.

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

It returns always false butwhile $post->post_parent returns the right ID is really the one I can get on the subpage (with modified testing code).!

This code can be found on many sites around there but was produced in 2012-2013.

My need is to check if a page is subpage of a page (with ID).

Thanks a lot for any help.

Sources of unworking codes : https://bavotasan.com/2011/is_child-conditional-function-for-wordpress/ https://www.kevinleary.net/wordpress-is_child-for-advanced-navigation/

I try to get this code working but it doesn't.

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

It returns always false but the ID is really the one I can get on the subpage (with modified testing code). This code can be found on many sites around there but was produced in 2012-2013.

My need is to check if a page is subpage of a page (with ID).

Thanks a lot for any help.

Sources of unworking codes : https://bavotasan.com/2011/is_child-conditional-function-for-wordpress/ https://www.kevinleary.net/wordpress-is_child-for-advanced-navigation/

My need is to check if a page is subpage of a page (with ID).

I try to get this code working but it doesn't.

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

It returns always false while $post->post_parent returns the right ID!

This code can be found on many sites around there but was produced in 2012-2013.

Thanks a lot for any help.

Sources of unworking codes : https://bavotasan.com/2011/is_child-conditional-function-for-wordpress/ https://www.kevinleary.net/wordpress-is_child-for-advanced-navigation/

Source Link
Valentin
  • 43
  • 2
  • 10
Loading