• Resolved vicchi

    (@vicchi)


    Hi,

    I’m using v1.1 of Next/Previous Page Link Plus, on a self hosted WP v3.4.2 installation. My rationale behind using the plugin is to cut down on the need to navigate between ‘chapters’ of my plugin’s documentation on my site.

    I’ve got previous and next page navigation working well in a custom page template and I’m specifying order_by to be menu_order but this appears to be ignored and the default behaviour of order_by (post_title) seems to be used regardless.

    You can see this on my site here: https://www.vicchi.org/codeage/wp-biographia/bending-wp-biographia-to-your-will-a-configuration-guide/

    The previous link, by menu order should be https://www.vicchi.org/codeage/wp-biographia/ (the parent), the next link, by menu order, should be https://www.vicchi.org/codeage/wp-biographia/hacking-wp-biographias-appearance-with-css/.

    But instead, it looks like the order is by post title alphabetically. Unless I’m drastically mis-reading what menu_order should do.

    I’ve gone through the usual sort of checks, reverting my theme back to a stock TwentyTen and seeing if the fun recurs, as well as deactivating all other plugins … but the fun still recurs.

    Taking a cue from a previous support thread, I uncommented line 137 in the plugin’s source and the query being run is this …

    SELECT DISTINCT p.* FROM wp_posts AS p WHERE ( p.menu_order < 0 OR p.post_title < 'Bending WP Biographia To Your Will; A Configuration Guide' AND p.menu_order = 0 ) AND p.post_type = 'page' AND p.post_status = 'publish' ORDER BY p.menu_order DESC, p.post_title DESC LIMIT 1
    SELECT DISTINCT p.* FROM wp_posts AS p WHERE ( p.menu_order > 0 OR p.post_title > 'Bending WP Biographia To Your Will; A Configuration Guide' AND p.menu_order = 0 ) AND p.post_type = 'page' AND p.post_status = 'publish' ORDER BY p.menu_order ASC, p.post_title ASC LIMIT 1

    You can see the way in which I’m using Next/Previous Page Link Plus in the page template’s source over on GitHub – https://github.com/vicchi/twentyten-vicchi/blob/master/page-documentation.php – but the TL;DR version is this …

    if (function_exists ('previous_page_link_plus') && function_exists ('next_page_link_plus')) {
    	$prev_format = '←%link';
    	$next_format = '%link→';
    	$args = array ('format' => $prev_format,
    		'loop' => true,
    		'order_by' => 'menu_order',
    		'return' => 'output');
    	$content = array ();
    	$content[] = '<div id="page-links">';
    	$content[] = '<span class="prev-page-link">';
    	$content[] = previous_page_link_plus ($args);
    	$content[] = '</span>';
    	$content[] = '<br />';
    	$args['format'] = $next_format;
    	$content[] = '<span class="next-page-link">';
    	$content[] = next_page_link_plus ($args);
    	$content[] = '</span>';
    	$content[] = '</div>';
    	echo implode (PHP_EOL, $content);
    }

    As a side note, I’m also using the Exclude Pages From Navigation plugin to keep the navigation menu my theme generates from getting out of control. My first thought was that there may be some unforeseen side effect of suppressing certain pages from the navigation menu but the problem still recurs regardless of whether this plugin is active or not.

    Any thoughts on what I’m doing wrong?

    -Gary

    https://www.ads-software.com/extend/plugins/ambrosite-nextprevious-page-link-plus/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter vicchi

    (@vicchi)

    I’ve managed to work around the problem by using a custom field called page-order associated with my pages and by setting order_by to numeric and meta_key to page-order. That seems to work as I expected. Oddly, I first set order_by to custom and it didn’t work as expected.

    Not sure whether this is of any help or not. On the one hand, I really want to get the previous/next links up and running properly on my site, but on the other hand, manually setting a custom field each time I create a page isn’t ideal either … so I’d really like to try and get this problem, if it is a problem, solved.

    -Gary

    Plugin Author ambrosite

    (@ambrosite)

    What method are you using to set the menu_order for your pages? Are you using a plugin like Post Types Order to do it, or are you manually setting it via the Order field on the Edit Page screen?

    Thread Starter vicchi

    (@vicchi)

    I’m not using any plugins to set menu order. The theme is a child theme derived from TwentyTen, so the menu order is, I believe, whatever wp_nav_menu generates by default. The order field for each page is the default of 0. My assumption is that the menu order would be as shown from the Dashboard under All Pages which is mirrored in the menu that the theme produces? I’m probably showing my ignorance here, but does this mean that I have to explicitly set the menu order field?

    -Gary

    Plugin Author ambrosite

    (@ambrosite)

    The menu_order is a field that is attached to each post/page in the database. The Order field in the editor shows you the value of menu_order. The default value is zero unless you set it to something else, either manually or via a plugin. The wp_nav_menu has nothing to do with it; the data for the navigation menus is stored separately in the database.

    As you can see from the SQL queries you printed out, the pages are ordered by menu_order first, and post_title second. If each page does not have a unique menu_order value, then they are sorted on post_title instead.

    Bottom line: Yes, you have to set the menu_order for each page. It has always been that way. The purpose of the Order field in the editor is to allow you to set it. If you don’t want to set each one individually, you can use a plugin like Post Types Order to set them all at once:

    https://www.ads-software.com/extend/plugins/post-types-order/

    Thread Starter vicchi

    (@vicchi)

    Ok. I understand now. The problem is not with your plugin, the problem is with my understanding (and assumptions) on what your plugin did. Apologies for that.

    But before I put this to rest, here’s the scenario I really want to solve …

    Let’s say I have 5 pages, call them A, B, D, E and C. They’re all ‘top level pages’ with the exception of D and E, which has page B as a parent.

    What I want is for the next page links to follow an alphabetical order, until a child page is detected and then follow alphabetical order within the parent/child hierarchy and then jump back to the top level where we left off.

    Using my notional pages, the next page links would look as follows …

    1. Page A, next page = B
    2. Page B, next page = D (enter child hierarchy)
    3. Page D, next page = E (still in child hierarchy)
    4. Page E, next page = C (exit from child hierarchy)
    5. Page C, next page = A (assuming I have loop set to true)

    … with the reverse happening for the previous page links. This is the behaviour I currently have with (manually) setting a custom field and using order_by as numeric and setting meta_key to point to the custom field.

    So as the moment, my use of a custom field works, but I guess my question is, can your plugin emulate this behaviour (which is how the menu generated by my theme appears and is also the order shown in All Pages on the Dashboard) without the need for me to explicitly set menu order or to use custom fields?

    If it can, then how? If it can’t then I’ve still learnt a bit more about how WordPress works which is not a bad thing anyway.

    Thanks for your time and patience on this … I really appreciate it.

    -Gary

    Plugin Author ambrosite

    (@ambrosite)

    No, the plugin cannot walk a page hierarchy that way. It might be possible but it would require a complete rewrite of the plugin code.

    You are not the only person to run into this problem. Page reordering plugins are extremely popular because they fill a very real hole in the core WordPress functionality, as you have discovered. Have you tried Post Types Order? It would be much easier for you than using the custom field workaround. If PTO doesn’t work for you, try CMS Tree Page View:

    https://www.ads-software.com/extend/plugins/cms-tree-page-view/

    Thread Starter vicchi

    (@vicchi)

    Oh well. Thanks for all the help, support and patience. I’ve learnt a whole lot more about WordPress over the past few days. I’ll give Post Types Order and CMS Tree View a go on my local install but if they don’t help I’ve still got the custom field workaround up and running which does do what I wanted in the first place.

    Thanks again.

    -Gary

    I am having the same problem. I am using cms tree page view but it is still ordering pages by the title not the menu order. Here is my code.

    <?php next_page_link_plus( array(
    'order_by' => 'menu_order',
    'loop' => true,
    'format' => '%link &raquo;',
    'link' => '%title',
    'tooltip' => '%title',
    'in_same_parent' => false,
    'in_same_author' => false,
    'in_same_meta' => false,
    'ex_pages' => '',
    'in_pages' => '',
    'before' => '',
    'after' => '',
    'num_results' => 1,
    'return' => ''
    ) ); ?>
    Plugin Author ambrosite

    (@ambrosite)

    holli.elizabeth,

    This type of error usually means that the menu_order field has not been set properly in the database. If you want to sort the pages on menu_order, then each page must have a unique value in that field. The following query will tell you how many of your pages have menu_order set to zero (the default value):

    select count(*) from wp_posts where post_type=”page” and
    post_status=”publish” and menu_order=0;

    If the query returns any number greater than one, there is a problem in your database, and you will need to talk to the developer of your page ordering plugin to find out why it is not setting the menu_order field for all of your pages.

    Hi, I have used your cool plugin to display pages. I have 9 page templates all same custom name and value. I put next and previous into all my page templates based on menu_order as I am using cms tree page view plugin. All my pages are displaying the page 7 as prev and next as page 8. I am not an expert in coding, so please guide me where am I doing wrong.

    <div class="navigation">
    				<span class="nav-next"><?php next_page_link_plus('order_by=menu_order&order_by=custom&meta_key=custommenuname&loop=1&format=%link &raquo'); ?></span>
    				<span class="nav-previous"><?php previous_page_link_plus( 'order_by=menu_order&order_by=custom&meta_key=custommenuname&loop=1&format=%link &laquo'); ?></span>
    			</div><!-- navigation -->

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Ordering By Menu Order Seems To Be Ignored’ is closed to new replies.