WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Please Help Me Find Page Sorting Code (5 posts)

  1. sarmadhassan
    Member
    Posted 6 years ago #

    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 !

  2. timethief
    Member
    Posted 6 years ago #

    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 :)

  3. theapparatus
    Member
    Posted 6 years ago #

    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, I'd say it operates the same as the get_posts Template tag.

    Reference:
    Template_Tags/get_posts

    Try changing it to something like:

    $pages = get_pages('orderby=ID');

  4. sarmadhassan
    Member
    Posted 6 years ago #

    theapparatus, thanks for the helping reply buddy.. your approach was great but it doesnt seem to work. Kindly help me sort out this mess ;(

  5. sarmadhassan
    Member
    Posted 6 years ago #

    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 !

Topic Closed

This topic has been closed to new replies.

About this Topic