• Hi,

    I have a WordPress site with a lot of pages. I’m loading this in the sidebar:

    <?php
    if($post->post_parent) {
    $children = wp_list_pages("depth=2&&title_li=&child_of=".$post->post_parent."&echo=0");
    $titlenamer = get_the_title($post->post_parent);
    }
    
    else {
    $children = wp_list_pages("depth=2&title_li=&child_of=".$post->ID."&echo=0");
    $titlenamer = get_the_title($post->ID);
    }
    if ($children) { ?>

    You see, to keep the overview, I’m using the ‘&depth=2‘.
    Now I want to do something and I’ll try to explain this.

    I want to echo a code what I’ve written in PHP, in the code:
    $children = wp_list_pages("depth=2&title_li=&child_of=".$post->ID."&echo=0");

    The code what I want to echo is:
    <?php $exclude = ''; if($_GET['page_id'] == 33 ) $exclude='&exclude=17,38'; ?>

    So, to echo the code, I have to put the code
    <?php echo $exclude;?>
    somewhere in the ‘&children‘ code.

    Something like this:
    $children = wp_list_pages("depth=2<?php echo $exclude;?>&title_li=&child_of=".$post->post_parent."&echo=0");

    But, as I had expected, this doesn’t work.

    My question: how can I echo PHP in the WordPress code? Of course I know I can use the ‘exclude’ code in the &children, but I want to exclude some pages ONLY when I load 1 page (when I load Page ID 33).

    Thanks for helping!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You just want to exclude certain pages from being selected?
    $children = wp_list_pages("depth=2" . $exclude . "&title_li=&child_of=".$post->post_parent."&echo=0");

    Sorry, I just re-read your post and realize my answer is wrong..

    You mean when $post -> ID is 33 you want to exclude some pages..?

    Something like

    $query = "depth=2&title_li=&child_of=".$post->ID;
    if($post -> ID == 33)
    {
        $query .= "&exclude=1,2,3";
    }
    $children = wp_list_pages($query);

    I hope that was better?

    Thread Starter martenaardbei

    (@martenaardbei)

    Yes, that’s what I want.
    Now my PHP skills is not going that far to add this in my code.
    Can you do that for me please?
    Thanks!

    <?php
    				  if($post->post_parent) {
    				  $children = wp_list_pages("depth=2<?php echo $exclude;?>&title_li=&child_of=".$post->post_parent."&echo=0");
    				  $titlenamer = get_the_title($post->post_parent);
    				  }
    
    				  else {
    				  $children = wp_list_pages("depth=2&title_li=&child_of=".$post->ID."&echo=0");
    				  $titlenamer = get_the_title($post->ID);
    				  }
    				  if ($children) { ?>
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘echo php in <?php wp_list_pages( $args ); ?>’ is closed to new replies.