Title: Please Help Me Find Page Sorting Code
Last modified: August 18, 2016

---

# Please Help Me Find Page Sorting Code

 *  Resolved [sarmadhassan](https://wordpress.org/support/users/sarmadhassan/)
 * (@sarmadhassan)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/please-help-me-find-page-sorting-code/)
 * Buddies, Please help me find the code in my theme which determines page sorting..
 * Theme name: Alexified
 *     ```
       <div id="menu">
       	<ul>
       		<li><a <?php if (is_home()) echo "class=\"active\""; ?> href="<?php bloginfo('url'); ?>"><span>Home</span></a></li>
       		<?php
       		$pages = get_pages();
       		if ($pages) {
       			foreach ($pages as $page) {
       				$page_id = $page->ID;
          				$page_title = $page->post_title;
          				$page_name = $page->post_name;
          				if ($page_name == "archives") {
          					(is_page($page_id) || is_archive() || is_search() || is_single())?$selected = ' class="active"':$selected='';
          					echo "<li><a".$selected." href=\"".get_page_link($page_id)."\"><span>Archives</span></a></li>\n";
          				}
          				elseif($page_name == "about") {
          					(is_page($page_id))?$selected = ' class="active"':$selected='';
          					echo "<li><a".$selected." href=\"".get_page_link($page_id)."\"><span>About</span></a></li>\n";
          				}
          				elseif ($page_name == "contact") {
          					(is_page($page_id))?$selected = ' class="active"':$selected='';
          					echo "<li><a".$selected." href=\"".get_page_link($page_id)."\"><span>Contact</span></a></li>\n";
          				}
          				elseif ($page_name == "about_short") {/*ignore*/}
                  	 	else {
                   		(is_page($page_id))?$selected = ' class="active"':$selected='';
                   		echo "<li><a".$selected." href=\"".get_page_link($page_id)."\"><span>$page_title</span></a></li>\n";
                   	}
           		}
           	}
       		?>
       	</ul>
       </div>
       ```
   
 * right now its sorting the pages by name, i want to reorder them via page order
   or page id
 * Please Help me !

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [timethief](https://wordpress.org/support/users/timethief/)
 * (@timethief)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/please-help-me-find-page-sorting-code/#post-661728)
 * Hello there,
    Please go here -> Presentation -> Widgets Locate your Pages widget
   and click on it to open it. Inside you will find these options: Title: ** Sort
   by:**(drop down menu) ->Page Title ->Page Order ->**Page ID** Exclude: Page IDs,
   separated by commas.
 * I believe this is what you are looking for.
    Happy blogging 🙂
 *  [theapparatus](https://wordpress.org/support/users/theapparatus/)
 * (@theapparatus)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/please-help-me-find-page-sorting-code/#post-661731)
 * The poster appears to be looking at a Page bar such as long the top of a blog,
   not the sidebar.
 * See that bit there near the top?
 * `$pages = get_pages();`
 * Not a 100% sure but from looking at the [code](http://trac.wordpress.org/browser/trunk/wp-includes/post.php#L1065),
   I’d say it operates the same as the get_posts Template tag.
 * Reference:
    [Template_Tags/get_posts](http://codex.wordpress.org/Template_Tags/get_posts)
 * Try changing it to something like:
 * `$pages = get_pages('orderby=ID');`
 *  Thread Starter [sarmadhassan](https://wordpress.org/support/users/sarmadhassan/)
 * (@sarmadhassan)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/please-help-me-find-page-sorting-code/#post-661772)
 * theapparatus, thanks for the helping reply buddy.. your approach was great but
   it doesnt seem to work. Kindly help me sort out this mess ;(
 *  Thread Starter [sarmadhassan](https://wordpress.org/support/users/sarmadhassan/)
 * (@sarmadhassan)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/please-help-me-find-page-sorting-code/#post-661777)
 * ok.. iam a hero myself.. lol posting here coz it may help anybody else
 * just like theapparatus said, it had something to do with get_pages.. the actual
   code for it becomes
 * `$pages = get_pages('sort_column=menu_order');`
 * and youll get it sorted out by order.. Enjoy !

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Please Help Me Find Page Sorting Code’ is closed to new replies.

## Tags

 * [Page ID](https://wordpress.org/support/topic-tag/page-id/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [sarmadhassan](https://wordpress.org/support/users/sarmadhassan/)
 * Last activity: [18 years, 6 months ago](https://wordpress.org/support/topic/please-help-me-find-page-sorting-code/#post-661777)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
