• Hi can any one help me i have one issue i have service page under that page two more pages child-1 and child-2 i want that two child page should be display on different hyper links but the problem is two are display to both the pages when i click on one image link one page has to display if i click on different image hyper link another page has to display but both the links are displaying for both pages

    1st link code

    <figure>
    <img />" alt="img26"/>
    <figcaption>
    <h4> ​​​ <a href="<?php 
     $args = [
    'child_of' => get_the_top_ancestor_id(),
    'title_li' => '',
    ];
    wp_list_pages( $args ); ?>
    ​​</a>​​</h4>
    <p class="description">DATACENTER OPTIMIZATION SERVICES</p>
    </figcaption>

    2nd link code

    	<figure>
    		<img />" alt="img25"/>
    			<figcaption>
    				<h4> ​​​ <a href="<?php 
    					 $args = [
    					'child_of' => get_the_top_ancestor_id(),
    					'title_li' => '',
    					];
    				wp_list_pages( $args ); ?>
    	   			​​</a>​​</h4>
    				<p class="description">INFRASTRUCTURE IMPLEMENTATION</p>
    			</figcaption>			
    	</figure>
    • This topic was modified 5 years, 6 months ago by bcworkz. Reason: code fixed
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Both codes are on the same template, right? Use the 'number' arg to limit pages returned to 1. Use the 'echo' arg to collect the return into a variable instead of immediately echoing out. You can then extract the page’s ID from the first <li> element’s class attributes. After getting the ID you can echo out the HTML.

    Use the ID extracted from the first as the 'exclude' arg value in the second along with the same 'number' arg so the only the second child page is returned. This time you don’t need to collect the return into a variable.

    Thread Starter banothuthiru

    (@banothuthiru)

    can you give sample code how to do that

    Moderator bcworkz

    (@bcworkz)

    As a first, untested attempt (don’t expect it to work perfectly, but it ought to be a good start), try this:

    <figure>
    <img />" alt="img26"/>
    <figcaption>
    <h4> ​​​ <a href="<?php 
     $args = [
    'child_of' => get_the_top_ancestor_id(),
    'title_li' => '',
    'number'=> 1,
    'echo'=> false,
    ];
    $list = wp_list_pages( $args );
    // extract post ID from list 
    preg_match('/<li.*menu-item-([0-9]+).*>/', $list, $matches); ?>
    echo $list;
    ​​</a>​​</h4>
    <p class="description">DATACENTER OPTIMIZATION SERVICES</p>
    </figcaption>
          <figure>
    		<img />" alt="img25"/>
    			<figcaption>
    				<h4> ​​​ <a href="<?php 
    					 $args = [
    					'title_li' => '',
                                            'number'=> 1,
                                            'include'=> $matches[1],
    					];
    				wp_list_pages( $args ); ?>
    	   			​​</a>​​</h4>
    				<p class="description">INFRASTRUCTURE IMPLEMENTATION</p>
    			</figcaption>			
    	</figure>
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Parent-child page’ is closed to new replies.