• Resolved Runtheball

    (@eisenbart)


    While the list of sibling pages normally displays without showing the currently active sibling, on one page the current page does show on the sibling list. This page has the same parent, and uses the same template as its siblings, but with some conditional code. I don’t understand why the conditional coding causes the active page to show on the sibling list.
    https://dev.dekalbpeds.com.php53-13.ord1-1.websitetestlink.com/about-our-practice/providers/

    <?php
    get_header(); ?>
    
    <div class="units-row units-split page-main">
    	<!-- this is not a sidebar, no reason to put it below content. Display:none on mobile -->
    	<div class="unit-25">
    		<?php if( $post->post_parent == '11') { //resources
    			$id = wp_get_post_parent_id( $post_ID ); ?>
    			<h2> <?php echo get_the_title( $id ); ?> </h2>
    			<hr>
    			<?php
    			echo do_shortcode('[child_pages siblings="true" cols="1" id="$id" link_titles="true" class="cp-list" list="true"]');
    		} elseif( $post->post_parent == '13') { //pediatric
    			$id = wp_get_post_parent_id( $post_ID ); ?>
    			<h2> <?php echo get_the_title( $id ); ?> </h2>
    			<hr>
    			<?php
    			echo do_shortcode('[child_pages siblings="true" cols="1" id="$id" link_titles="true" class="cp-list" list="true"]');
    		}  elseif( $post->post_parent == '15') { //services
    			$id = wp_get_post_parent_id( $post_ID ); ?>
    			<h2> <?php echo get_the_title( $id ); ?> </h2>
    			<hr>
    			<?php
    			echo do_shortcode('[child_pages siblings="true" cols="1" id="$id" link_titles="true" class="cp-list" list="true"]');
    		} elseif( $post->post_parent == '17') { //about
    			$id = wp_get_post_parent_id( $post_ID ); ?>
    			<h2> <?php echo get_the_title( $id ); ?> </h2>
    			<hr>
    			<?php
    			echo do_shortcode('[child_pages siblings="true" cols="1" id="$id" link_titles="true" class="cp-list" list="true"]');
    		} ?>
    	</div>
    	<div class="unit-75 page-content unit-push-right">
    		<?php if( is_page(23)){
    			//Are we on the Providers page? It behaves differently within the CC-Childpages plugin
    			if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    					<h1><?php the_title(); ?></h1>
    					<p><?php the_content(); ?></p>
    					<?php if(have_rows('provider') ): ?>
    						<?php while(have_rows('provider') ) : the_row(); ?>
    							<div class="units-row end provider ">
    								<div class="unit-20 provider-pic">
    									<img class="thumb" src="<?php the_sub_field('provider_pic'); ?>" width="175" height="250">
    								</div>
    								<div class="unit-75">
    									<h3><?php the_sub_field('provider_name'); ?>, <?php the_sub_field('provider_credentials'); ?></h3>
    									<p><?php the_sub_field('provider_bio'); ?></p>
    								</div>
    							</div>
    						<?php endwhile; ?>
    					<?php endif; ?>
    				<?php endwhile; ?>
    				<?php else : ?>
    			<?php endif; ?>
    		<?php } else { ?>	
    
    			<?php if ( have_posts() ) : ?>
    				<?php /* Start the Loop */ ?>
    				<?php while ( have_posts() ) : the_post(); ?>
    					<h1><?php the_title(); ?></h1>
    					<div class="alignright">
    						<?php
    							if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
    								the_post_thumbnail('medium');
    							}
    							else{
    								echo '<img class="alignright" alt="image unavailable" src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/thumb-temp.jpg" />';
    							}
    						?>
    					</div>
    					<?php the_content(); ?>
    				<?php endwhile; ?>
    				<?php else : ?>
    			<?php endif; ?>
    		<?php }; ?>
    		</div>
    	</div>
    </div>
    <?php get_footer(); ?>

    Maybe this is the same issue as discussed here?

    https://www.ads-software.com/plugins/cc-child-pages/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author caterhamcomputing

    (@caterhamcomputing)

    The “issue” discussed in the thread you linked to is effectively a feature request, and is not relevant here.

    Without access to your site, it is hard to say exactly what is different about the “Providers” page … but I can see that the issue affects the title for the column too – which is output by:

    $id = wp_get_post_parent_id( $post_ID ); ?>
    <h2> <?php echo get_the_title( $id ); ?> </h2>

    … and not the shortcode.

    I think you need to work out why wp_get_post_parent_id returns the current page for the “Providers” page … if you can correct that, get_the_title and my shortcode will both output what you expect them to.

    Also, you do not need to specify the id parameter in the shortcode when using the siblings parameter as it will not be used.

    I would also suggest the code might be easier for you to maintain using PHP switch statement, as you have a lot of repeated code all doing the same thing:

    switch ( $post->post_parent ) {
        case '11':
        case '13':
        case '15':
        case '17':
    	$id = wp_get_post_parent_id( $post_ID ); ?>
    	<h2> <?php echo get_the_title( $id ); ?> </h2>
    	<hr>
    	<?php
    	echo do_shortcode('[child_pages siblings="true" cols="1" link_titles="true" class="cp-list" list="true"]');
            break;
    }

    See https://php.net/manual/en/control-structures.switch.php

    Let me know if this helps.

    Thread Starter Runtheball

    (@eisenbart)

    Thanks very much for the advice and code! I’ll keep looking into why that one sibling is being treated differently. At first it had its own template, but no longer. I reset permalinks but that had no effect. I’ll keep digging.

    Plugin Author caterhamcomputing

    (@caterhamcomputing)

    If you would like me to have a quick look, I would be happy to … even if it is just to double-check that it isn’t anything to do with my plugin.

    If you do want me to, I’d suggest setting up a new user so that it can be dropped once it is no longer needed.

    Obviously, don’t post any logins here as it is a public forum – you can contact me via my web site at https://caterhamcomputing.net/

    Tim Lomas

    Plugin Author caterhamcomputing

    (@caterhamcomputing)

    Thank you for your email confirming that the problem is sorted, and was not a problem with the plugin.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Active sibling shows in sibling list – on one page only’ is closed to new replies.