Wordpress Code Gurus' Please Help Me

Discussion in 'WordPress' started by sami1255, Dec 2, 2007.

  1. #1
    I'll now suicide if i cant find this.. :mad: it has taken my whole day to sort this out

    Problem

    Wordpress Page sorting in header.php of my theme

    the only code i found out in the whole template regarding page menu is in the header.php

    <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>
    PHP:
    Right now the pages are sorted in the menu by name. I simply want them to be sorted on page ID or page Order basis

    Guys please help me out on this :(
     
    sami1255, Dec 2, 2007 IP
  2. Blonde Jon

    Blonde Jon Active Member Affiliate Manager

    Messages:
    745
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Blonde Jon, Dec 2, 2007 IP
  3. Crimsonc

    Crimsonc Peon

    Messages:
    616
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thats a horrible way to get your menu.

    <?php
    wp_list_pages('sort_column=menu_order'); ?>

    That will do it for you and put it in page order not by name.
     
    Crimsonc, Dec 2, 2007 IP
  4. sami1255

    sami1255 Well-Known Member

    Messages:
    835
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    125
    #4
    couldnt agree more buddy.. i didnt wrote this theme and i never wanted to use such theme.. but the theme itself looks great.. ill try your way but right now i dont think so it will work coz the theme guy wrote all this shit to highlight a selected page..

    any more gurus around? :rolleyes:
     
    sami1255, Dec 3, 2007 IP
  5. sami1255

    sami1255 Well-Known Member

    Messages:
    835
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    125
    #5
    well, here you go.. am a guru myself.. :D

    posting here coz it may help other guys.. ;)

    all i had to do was.. change this

    $pages = get_pages();
            if ($pages) {
                foreach ($pages as $page) {
    PHP:
    to, this;

    $pages = get_pages('sort_column=menu_order');
            if ($pages) {
                foreach ($pages as $page) {
    PHP:
    wordpress tags can be tricky.. :p
     
    sami1255, Dec 3, 2007 IP