Solved

wordpress - is parent page

Posted on 2011-03-16
4
1,016 Views
Last Modified: 2012-05-11
How do I change the below code to say...

if parent page is ...

instead of if page is ...

<?php if (is_page(array('my-knowledge' ,'clients', 'skills'))) { ?>
      
                                    <h1 class="entry-title"><?php the_title(); ?></h1>

                              <?php } else { ?>
0
Comment
Question by:petewinter
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
meb_santoso earned 250 total points
ID: 35160607
wait... what ?
what do you want to do exactly?

from what I can understand you want to do something like this:

IF the parent page IS one of these pages: my knowledge, clients, or skills
THEN display the title from the child page
ELSE display whatever

is that correct?

if so, you can do the following (among 1000 other ways to do it)
-. get current post's parent
-. cross check the current page's parent ID against the predefined IDs
-. return true or false
-. use the return value to do whatever you need to do

# make a function first, put in functions.php

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

Open in new window


# do some checking

<?php
if(is_child(123) || is_child(456) ) {
echo "This is a child page of some parent";
} else {
echo .....etc.........
?>

Open in new window

0
 
LVL 31

Assisted Solution

by:gwkg
gwkg earned 250 total points
ID: 35173926
Didn't test this...

$find = array('my-knowledge' ,'clients', 'skills')
if (in_array($post->post_parent,$find)) {
    <h1 class="entry-title"><?php the_title(); ?></h1>
<?php } else { ?>
0
 
LVL 31

Expert Comment

by:gwkg
ID: 35173930
semi-colon after the first line
0
 

Author Closing Comment

by:petewinter
ID: 35180796
many thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question