Skip to main content
Code readability
Source Link
TheDeadMedic
  • 36.6k
  • 9
  • 68
  • 102
 <?php 

$child_pages = $wpdb->get_results("SELECT 
 *   "SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT'  
);    ?>
<?php  
if ( $child_pages ) :
    foreach ( $child_pages as $pageChild ) : 
 setup_postdata(       setup_postdata( $pageChild );
        
        ?> 

        <div class="comparison-post-block"><divblock">
 class="wrapper"><div           <div class="wrapper">
                <div class="top-5-image">
                    <?php echo get_the_post_thumbnail( $pageChild->ID, 'thumbnail' ); ?>
                </div><div>
            </div>
            <div class="comparison-top5-text">
                <div class="wrapper"><divclass="wrapper">
                    <div class="top-5-title"><ptitle">
                        <p class="comparisontitle">
                            <a class="comparisontitle" href="<?php echo  get_permalink( $pageChild->ID ); ?>" rel="bookmark" title="<?php echo $pageChild->post_title;>post_title ?>"><>">
                                <?php echo $pageChild->post_title;>post_title ?><>
                             </a>
                        </p>
                    </div><div>
                </div>
                <div class="wrapper"><divclass="wrapper">
                    <div class="comparison-content"><divcontent">
                        <div class="comparisonexcerpttext">
                            <?php echo  get_the_excerpt($pageChild->ID); ?>
                        </div><div>
                    </div><div>
                </div><div>
            </div><div>
        </div>
        
    <?php endforeach ?>
<?php endif ?>
<?php  

if ( is_page() ) {:
    global $post; 
    
    $args = array( 
        'tax_query' => array(
            array(
                'taxonomy' => 'top5',
                'field' => 'name',
                'terms' => $post->post_title
            ),
        ),
    );
    
    $My_Query = new WP_Query( $args ); 

?>
    
<?php    if ( $My_Query->have_posts() ) : ?>
<?php rewind_posts(); ?>
    <?php  while ( $My_Query->have_posts() ) :
            $My_Query->the_post();
            ?>
            
            <div class="comparison-stories"><div id="comparison-container_division">stories">
                <div class="comparison-post-block"><divblock">
                    <div class="wrapper">
                        <div class="top-5-image">
                            <?php the_post_thumbnail( 'medium' ); ?><>
                        </div><div>
                    </div>
                    <div class="comparison-top5-text">
                        <div class="wrapper"><divclass="wrapper">
                            <div class="top-5-title"><ptitle">
                                <p class="comparisontitle">
                                    <a class="comparisontitle" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><>">
                                        <?php the_title(); ?><>
                                    </a><a>
                                </p>
                            </div>
                        </div>  
                        <div class="wrapper"><divclass="wrapper">
                            <div class="comparison-content"><divcontent">
                                <div class="comparisonexcerpttext">
                                    <?php the_excerpt(); ?></div><>
                                </div><div>
                            </div><div>
                        </div><div>
                    </div><div>
                </div>
            <?php/div>
 endwhile; ?>          
        <?php else:endwhile ?>
// Your fallback content here
?>
    <?php endif;wp_reset_postdata() ?>
    <?php wp_reset_postdata();else : ?>
    
    <?php wp_reset_query();endif ?>
<?php }endif ?>
 <?php
$child_pages = $wpdb->get_results("SELECT *    FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT' );    ?>
<?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata(      $pageChild ); ?>
<div class="comparison-post-block"><div class="wrapper"><div class="top-5-image">
<?php echo get_the_post_thumbnail($pageChild->ID, 'thumbnail'); ?>
  </div></div>
  <div class="comparison-top5-text">
        <div class="wrapper"><div class="top-5-title"><p class="comparisontitle">
 <a class="comparisontitle" href="<?php echo  get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>"><?php echo $pageChild->post_title; ?></a>
 </p> </div></div>
 <div class="wrapper"><div class="comparison-content"><div class="comparisonexcerpttext">
 <?php echo  get_the_excerpt($pageChild->ID); ?>
 </div></div></div></div></div>
<?php 
if ( is_page() ) {
global $post;  
   $args = array( 
'tax_query' => array(
    array(
        'taxonomy' => 'top5',
        'field' => 'name',
        'terms' => $post->post_title
    )
)
);

$My_Query = new WP_Query( $args ); 

?>

<?php if ( $My_Query->have_posts() ) : ?>
<?php rewind_posts(); ?>
    <?php while ( $My_Query->have_posts() ) : $My_Query->the_post(); ?>
<div class="comparison-stories"><div id="comparison-container_division">
        <div class="comparison-post-block"><div class="wrapper">
<div class="top-5-image">
<?php the_post_thumbnail('medium'); ?></div></div>
<div class="comparison-top5-text">
        <div class="wrapper"><div class="top-5-title"><p class="comparisontitle">
<a class="comparisontitle" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>           </div>     </div>  
<div class="wrapper"><div class="comparison-content"><div class="comparisonexcerpttext">
<?php the_excerpt(); ?></div></div></div></div></div></div>
    <?php endwhile; ?>
    <?php else:
// Your fallback content here
?>
<?php endif; ?>
    <?php wp_reset_postdata(); ?>
<?php wp_reset_query(); ?>
<?php } ?>
<?php 

$child_pages = $wpdb->get_results( 
    "SELECT * FROM $wpdb->posts WHERE post_parent = $post->ID AND post_type = 'page' ORDER BY menu_order" 
);
 
if ( $child_pages ) :
    foreach ( $child_pages as $pageChild ) : 
        setup_postdata( $pageChild );
        
        ?> 

        <div class="comparison-post-block">
            <div class="wrapper">
                <div class="top-5-image">
                    <?php echo get_the_post_thumbnail( $pageChild->ID, 'thumbnail' ) ?>
                </div>
            </div>
            <div class="comparison-top5-text">
                <div class="wrapper">
                    <div class="top-5-title">
                        <p class="comparisontitle">
                            <a class="comparisontitle" href="<?php echo get_permalink( $pageChild->ID ) ?>" rel="bookmark" title="<?php echo $pageChild->post_title ?>">
                                <?php echo $pageChild->post_title ?>
                             </a>
                        </p>
                    </div>
                </div>
                <div class="wrapper">
                    <div class="comparison-content">
                        <div class="comparisonexcerpttext">
                            <?php echo get_the_excerpt() ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
    <?php endforeach ?>
<?php endif ?>
<?php  

if ( is_page() ) :
    global $post; 
    
    $args = array( 
        'tax_query' => array(
            array(
                'taxonomy' => 'top5',
                'field' => 'name',
                'terms' => $post->post_title
            ),
        ),
    );
    
    $My_Query = new WP_Query( $args );
    
    if ( $My_Query->have_posts() ) :
        while ( $My_Query->have_posts() ) :
            $My_Query->the_post();
            ?>
            
            <div class="comparison-stories">
                <div class="comparison-post-block">
                    <div class="wrapper">
                        <div class="top-5-image">
                            <?php the_post_thumbnail( 'medium' ) ?>
                        </div>
                    </div>
                    <div class="comparison-top5-text">
                        <div class="wrapper">
                            <div class="top-5-title">
                                <p class="comparisontitle">
                                    <a class="comparisontitle" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
                                        <?php the_title(); ?>
                                    </a>
                                </p>
                            </div>
                        </div>  
                        <div class="wrapper">
                            <div class="comparison-content">
                                <div class="comparisonexcerpttext">
                                    <?php the_excerpt() ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
        <?php endwhile ?>
    
    <?php wp_reset_postdata() ?>
    <?php else : ?>
    
    <?php endif ?>
<?php endif ?>
added 2574 characters in body
Source Link

The child page code:

 <?php
$child_pages = $wpdb->get_results("SELECT *    FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT' );    ?>
<?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata(      $pageChild ); ?>
<div class="comparison-post-block"><div class="wrapper"><div class="top-5-image">
<?php echo get_the_post_thumbnail($pageChild->ID, 'thumbnail'); ?>
  </div></div>
  <div class="comparison-top5-text">
        <div class="wrapper"><div class="top-5-title"><p class="comparisontitle">
 <a class="comparisontitle" href="<?php echo  get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>"><?php echo $pageChild->post_title; ?></a>
 </p> </div></div>
 <div class="wrapper"><div class="comparison-content"><div class="comparisonexcerpttext">
 <?php echo  get_the_excerpt($pageChild->ID); ?>
 </div></div></div></div></div>

The custom taxonomy code:

<?php 
if ( is_page() ) {
global $post;  
   $args = array( 
'tax_query' => array(
    array(
        'taxonomy' => 'top5',
        'field' => 'name',
        'terms' => $post->post_title
    )
)
);

$My_Query = new WP_Query( $args ); 

?>

<?php if ( $My_Query->have_posts() ) : ?>
<?php rewind_posts(); ?>
    <?php while ( $My_Query->have_posts() ) : $My_Query->the_post(); ?>
<div class="comparison-stories"><div id="comparison-container_division">
        <div class="comparison-post-block"><div class="wrapper">
<div class="top-5-image">
<?php the_post_thumbnail('medium'); ?></div></div>
<div class="comparison-top5-text">
        <div class="wrapper"><div class="top-5-title"><p class="comparisontitle">
<a class="comparisontitle" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>           </div>     </div>  
<div class="wrapper"><div class="comparison-content"><div class="comparisonexcerpttext">
<?php the_excerpt(); ?></div></div></div></div></div></div>
    <?php endwhile; ?>
    <?php else:
// Your fallback content here
?>
<?php endif; ?>
    <?php wp_reset_postdata(); ?>
<?php wp_reset_query(); ?>
<?php } ?>

As far as I am aware I have copied all of the code into here,

Sorry this is my first post so not exactly sure how you would like the code, so essentially I would like to combine these two pieces of code!

Thanks again!

The child page code:

 <?php
$child_pages = $wpdb->get_results("SELECT *    FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT' );    ?>
<?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata(      $pageChild ); ?>
<div class="comparison-post-block"><div class="wrapper"><div class="top-5-image">
<?php echo get_the_post_thumbnail($pageChild->ID, 'thumbnail'); ?>
  </div></div>
  <div class="comparison-top5-text">
        <div class="wrapper"><div class="top-5-title"><p class="comparisontitle">
 <a class="comparisontitle" href="<?php echo  get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>"><?php echo $pageChild->post_title; ?></a>
 </p> </div></div>
 <div class="wrapper"><div class="comparison-content"><div class="comparisonexcerpttext">
 <?php echo  get_the_excerpt($pageChild->ID); ?>
 </div></div></div></div></div>

The custom taxonomy code:

<?php 
if ( is_page() ) {
global $post;  
   $args = array( 
'tax_query' => array(
    array(
        'taxonomy' => 'top5',
        'field' => 'name',
        'terms' => $post->post_title
    )
)
);

$My_Query = new WP_Query( $args ); 

?>

<?php if ( $My_Query->have_posts() ) : ?>
<?php rewind_posts(); ?>
    <?php while ( $My_Query->have_posts() ) : $My_Query->the_post(); ?>
<div class="comparison-stories"><div id="comparison-container_division">
        <div class="comparison-post-block"><div class="wrapper">
<div class="top-5-image">
<?php the_post_thumbnail('medium'); ?></div></div>
<div class="comparison-top5-text">
        <div class="wrapper"><div class="top-5-title"><p class="comparisontitle">
<a class="comparisontitle" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>           </div>     </div>  
<div class="wrapper"><div class="comparison-content"><div class="comparisonexcerpttext">
<?php the_excerpt(); ?></div></div></div></div></div></div>
    <?php endwhile; ?>
    <?php else:
// Your fallback content here
?>
<?php endif; ?>
    <?php wp_reset_postdata(); ?>
<?php wp_reset_query(); ?>
<?php } ?>

As far as I am aware I have copied all of the code into here,

Sorry this is my first post so not exactly sure how you would like the code, so essentially I would like to combine these two pieces of code!

Thanks again!

Source Link

Child Pages and Custom Taxonomies

I have been stressing over this for a while. I have figured out how to call pages in a loop using custom taxonomies. I have also figured out how to call child pages of a parent page in a loop. However, what I would like to do is call the child pages, then filter out the child pages that belong to a custom taxonomy, as to only show these ones.

Thanks in advance for any help,

I can offer any more information needed,