WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [PHP HELP] Display the child pages in a specific order? (3 posts)

  1. KACramer
    Member
    Posted 2 years ago #

    You can see the page here: http://www.hotribscooljazz.org/activities/

    Here is my issue... It displays the truncated content, featured image, and title for each child page, BUT the order in which it displays this content seems to be the order in which each page was created. I need to be able to control the order in which these pages is displayed, but even if I change the "published on date" in word press the order is unaffected.

    What is driving the order in which these pages are being displayed? How can I edit the code below to display child pages based on the numeric value given in each pages "order" field?

    <?php
    /**
     * Template Name: Activites Landing Page
     * Description:
     *
     * @package WordPress
     * @subpackage Jazz_Rib_2012
     * @since Jazz and Rib Fest 2012 WordPress Theme
     */
    
    get_header(); ?>
    <div id="pageContent">
        <table class="pageContentTable">
        	<tr class="spacing">
            </tr>
            <tr class="regularRow">
                <td class="sidebar" valign="top" >
               			<div class="sidebar_wrapper">
                            <?php if ( !function_exists('dynamic_sidebar')
                            || !dynamic_sidebar('primary-sidebar') ) : ?>
                            <?php endif; ?>
                        </div>
    			</td>
    
                <td class="main_page_content" valign="top">
    
                    <div id="ContentInset">
                        <!---Places Page Title---->
                        <?php if (have_posts()) : while (have_posts()) : the_post();?>
                        <h1><?php the_title(); ?></h1>
                        <?php endwhile; endif; ?>
    
                        <!---Places Page Content---->
                        <?php if (have_posts()) : while (have_posts()) : the_post();?>
                        <?php the_content(); ?>
                        <?php endwhile; endif; ?>
                        <?php
    					$current_page = $post->ID;
    					$querystr = "
    						SELECT * from $wpdb->posts
    						WHERE post_type = 'page'
    						AND post_parent = $current_page
    						";
    
    					$child_pages = $wpdb->get_results($querystr, OBJECT);
    					if ($child_pages):
    					foreach($child_pages as $post) :
    					setup_postdata($post); ?>
                        	<table class="activityList">
                            	<tr>
                                	<td class="activity_logo_cell">
                                    	<a href="<?php the_permalink();?>"><?php the_post_thumbnail('Activity_Logo_Small');?></a>
                                    </td>
                                	<td class="activity_content_cell">
                                		<h2><?php the_title(); ?></h2>
                                        <?php
                                        $thecontent = $post->post_content;
                                        $getlength = mb_strlen($thecontent);
                                        $thelength = 350;
                                        echo substr(strip_tags($thecontent), 0, $thelength);
                                        if ($getlength > $thelength) echo "&hellip;";
                                        ?>
                                        <a href="<?php the_permalink();?>"><?php _e('[Read More]');?></a>
                            		</td>
                            	</tr>
                            </table>
                            <h4></h4>
    					<?php endforeach; ?>
    					<?php else : ?>
    					No additional information about activities is currently available.  Check back soon!
    					<?php endif; ?>
    					<?php rewind_posts(); ?>
    
                    </div>
                </td>
            </tr>
    
        </table>
    </div>    
    
    </div> <!---Main Content Wrapper---->
    
    <?php get_footer(); ?>
  2. KACramer
    Member
    Posted 2 years ago #

    Okay so I figured out that is I add
    ORDER BY post_title

    to the code above in the query it will sort it by the page's title... is there something like "post_order" that would order it by the page attribute order?

    Here is the updated code:

    <?php
    /**
     * Template Name: Activites Landing Page
     * Description:
     *
     * @package WordPress
     * @subpackage Jazz_Rib_2012
     * @since Jazz and Rib Fest 2012 WordPress Theme
     */
    
    get_header(); ?>
    <div id="pageContent">
        <table class="pageContentTable">
        	<tr class="spacing">
            </tr>
            <tr class="regularRow">
                <td class="sidebar" valign="top" >
               			<div class="sidebar_wrapper">
                            <?php if ( !function_exists('dynamic_sidebar')
                            || !dynamic_sidebar('primary-sidebar') ) : ?>
                            <?php endif; ?>
                        </div>
    			</td>
    
                <td class="main_page_content" valign="top">
    
                    <div id="ContentInset">
                        <!---Places Page Title---->
                        <?php if (have_posts()) : while (have_posts()) : the_post();?>
                        <h1><?php the_title(); ?></h1>
                        <?php endwhile; endif; ?>
    
                        <!---Places Page Content---->
                        <?php if (have_posts()) : while (have_posts()) : the_post();?>
                        <?php the_content(); ?>
                        <?php endwhile; endif; ?>
                        <?php
    					$current_page = $post->ID;
    					$querystr = "
    						SELECT * from $wpdb->posts
    						WHERE post_type = 'page'
    						AND post_parent = $current_page
    						ORDER BY post_title
    						";
    
    					$child_pages = $wpdb->get_results($querystr, OBJECT);
    					if ($child_pages):
    					foreach($child_pages as $post) :
    					setup_postdata($post); ?>
                        	<table class="activityList">
                            	<tr>
                                	<td class="activity_logo_cell">
                                    	<a href="<?php the_permalink();?>"><?php the_post_thumbnail('Activity_Logo_Small');?></a>
                                    </td>
                                	<td class="activity_content_cell">
                                		<h2><?php the_title(); ?></h2>
                                        <?php
                                        $thecontent = $post->post_content;
                                        $getlength = mb_strlen($thecontent);
                                        $thelength = 350;
                                        echo substr(strip_tags($thecontent), 0, $thelength);
                                        if ($getlength > $thelength) echo "&hellip;";
                                        ?>
                                        <a href="<?php the_permalink();?>"><?php _e('[Read More]');?></a>
                            		</td>
                            	</tr>
                            </table>
                            <h4></h4>
    					<?php endforeach; ?>
    					<?php else : ?>
    					No additional information about activities is currently available.  Check back soon!
    					<?php endif; ?>
    					<?php rewind_posts(); ?>
    
                    </div>
                </td>
            </tr>
    
        </table>
    </div>    
    
    </div> <!---Main Content Wrapper---->
    
    <?php get_footer(); ?>
  3. KACramer
    Member
    Posted 2 years ago #

    Figured it out... Just had to change "ORDER BY post_title" to "ORDER BY menu_order"

Topic Closed

This topic has been closed to new replies.

About this Topic