I'm having a hard time figuring out how to display the title of the childpages as the id of a div. Assuming that 'news' & 'othernews' are siblings of the parent page home (39)

I want something like this:

<div class="wrapper" id="news">
<div class="wrapper" id="othernews">

This is my function for my shortcode:

function content_block( $atts, $content = null ){

extract( shortcode_atts( array(
    'type'          =>      'white'

), $atts));

$childArgs = array(
    'post_type'         =>      'page',
    'parent_page'       =>      39

$child = new WP_Query($childArgs);

if ($child->have_posts()) {

    while ($child->have_posts()) {


        if ($type == 'white') {
            $return .= '<div class="col-white">';
                $return .= '<div class="wrap" id="'. get_the_title() .'">';
                    $return .= do_shortcode($content);
                $return .= '</div>';
            $return .= '</div>';

        } else
        if ($type == 'grey') {
            $return .= '<div class="col-grey">';
                $return .= '<div class="wrap" id="'. get_the_title() .'">';
                    $return .= do_shortcode($content);
                $return .= '</div>';
            $return .= '</div>';

        return $return;

  • there is no parent_page, it's post_parent. and you reset the query and return inside of your while loop, so it can't possibly run for more than 1 iteration before exiting.
    – Milo
    Nov 20, 2014 at 16:35
  • Thanks for the reply, I figured it out. Thanks anyways :) Nov 21, 2014 at 15:01

1 Answer 1


May I suggest you provide details as to the exact problem, and what the results are of your example code?

Also, it seems like you are saying that the pages you want to get the titles of are siblings of the parent, which is the home page, so in fact, they are not children at all (An interesting plot for a TV drama, perhaps).

In any case, instead of using the title for your ID, I would suggest using the slug (post_name) instead:

$current_id = get_the_id();
$post = get_post($current_id);

Using the title might results in spaces in your ID, which could result in an array of IDs, not just one.

  • Siblings, childs, parents.. english ain't my best skill, but this is my structure: home -news -morenews -- item 1 -- item 2 Nov 20, 2014 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.