Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Order Pages and Categories in navigation WordPress

  • REFUNDED

Hello,

I am using both pages and categories in my navigation


<ul class="sf-menu">
<?php wp_list_pages('sort_column=menu_order&title_li=&exclude=34'); ?>
<?php wp_list_cats('sort_column=name&exclude=7,10'); ?>
</ul>

The problem is I want the categories and pages actually integrated so possibly something like this...

Home | Category 1 | Category 2 | Page 1 | Page 2 | Page 3 | Category 3 | Page 4

Please advise

**UPDATE - I have answered the problem myself, talked the client into a few things, and just hard-coded the home page before the categories then placed the categories after the pages.


<ul class="sf-menu">
<li><a href="/">Home</a></li>
<?php wp_list_cats('sort_column=name&exclude=7,10'); ?>
<?php wp_list_pages('sort_column=menu_order&title_li=&exclude=3'); ?>
</ul>

Answers (6)

2010-03-31

Nathan Parikh answers:

You might want to try this plugin:
http://wordpress.org/extend/plugins/wordpress-navigation-list-plugin-navt/


Nathan Parikh comments:

If you don't want to use a plugin, then the easiest option you have is to code the nav items yourself into the header...but I'm assuming you don't want to do that?

2010-03-31

Dan Davies answers:

Upgrade to the WordPress 3.0 beta and utilise the upcoming menu feature. It'll be out in a matter of weeks anyway, so if you don't want to use the beta, you could just wait. Then you'll be able to do exactly what you need, plugin-free.

http://wpengineer.com/wordpress-3-0-menu-update/

2010-03-31

Andrzej answers:

the best plugin here I'd say is Menubar http://wordpress.org/extend/plugins/menubar/ also integrates nicely with Superfish

2010-04-01

Colin Pool answers:

This code will give you the opportunity to combine the page and categories list in one menu. I created a function with the list_page and list_cats functions in one new function. Maybe its what you are looking for?


<!-- First create the function -->
<?php
function wp_list_pagecats( $args = '' ) {
$defaults = array(
'show_option_all' => '', 'orderby' => 'name',
'order' => 'ASC', 'show_last_update' => 0,
'style' => 'list', 'show_count' => 0,
'hide_empty' => 1, 'use_desc_for_title' => 1,
'child_of' => 0, 'feed' => '', 'feed_type' => '',
'feed_image' => '', 'exclude' => '', 'exclude_tree' => '', 'current_category' => 0,
'hierarchical' => true, 'title_li' => __( '' ),
'echo' => 1, 'depth' => 0
);

$r = wp_parse_args( $args, $defaults );

if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
$r['pad_counts'] = true;
}

if ( isset( $r['show_date'] ) ) {
$r['include_last_update_time'] = $r['show_date'];
}

if ( true == $r['hierarchical'] ) {
$r['exclude_tree'] = $r['exclude'];
$r['exclude'] = '';
}

extract( $r );

$categories = get_categories( $r );

$output = '';
if ( $title_li && 'list' == $style )
$output = '<li class="categories">' . $r['title_li'] . '<ul>';

if ( empty( $categories ) ) {
if ( 'list' == $style )
$output .= '<li>' . __( "No categories" ) . '</li>';
else
$output .= __( "No categories" );
} else {
global $wp_query;

if( !empty( $show_option_all ) )
if ( 'list' == $style )
$output .= '<li><a href="' . get_bloginfo( 'url' ) . '">' . $show_option_all . '</a></li>';
else
$output .= '<a href="' . get_bloginfo( 'url' ) . '">' . $show_option_all . '</a>';

if ( empty( $r['current_category'] ) && is_category() )
$r['current_category'] = $wp_query->get_queried_object_id();

if ( $hierarchical )
$depth = $r['depth'];
else
$depth = -1; // Flat.

$output .= walk_category_tree( $categories, $depth, $r );
}

if ( $title_li && 'list' == $style )
$output .= '';

$output = apply_filters( 'wp_list_categories', $output );

if ( $echo )
echo $output;
else
return $output;

$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );

$output = '';
$current_page = 0;

// sanitize, mostly to keep spaces out
$r['exclude'] = preg_replace('/[^0-9,]/', '', $r['exclude']);

// Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array)
$exclude_array = ( $r['exclude'] ) ? explode(',', $r['exclude']) : array();
$r['exclude'] = implode( ',', apply_filters('wp_list_pages_excludes', $exclude_array) );

// Query pages.
$r['hierarchical'] = 0;
$pages = get_pages($r);

if ( !empty($pages) ) {
if ( $r['title_li'] )
$output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';

global $wp_query;
if ( is_page() || is_attachment() || $wp_query->is_posts_page )
$current_page = $wp_query->get_queried_object_id();
$output .= walk_page_tree($pages, $r['depth'], $current_page, $r);

if ( $r['title_li'] )
$output .= '</ul></li>';
}

$output = apply_filters('wp_list_pages', $output, $r);

if ( $r['echo'] )
echo $output;
else
return $output;
} ?>

<!-- Shows the menu -->
<?php wp_list_pagecats(''); ?>


Chad Mueller comments:

By using this, can I exclude some pages, and how do I order categories - I know there is the page order, but is there a category order?

2010-04-04

Martin answers:

I would just use the page nav and then install the plugin <em>Page Links To</em>, then what you do is create a page and name it after a category then use the <em>Page Links To</em> options to redirect to the category you want.

Done this before on one of my old sites.

Page Link To:
http://txfx.net/wordpress-plugins/page-links-to/

2010-04-07

Merne Asplund answers:

If you have a specific order that you want things, I would say hard-code it into your theme. You can do a combination of hard-coded links and dynamic links. For example:


<ul class="sf-menu">
<li><a href="<?php bloginfo($url); ?>">Home</a></li>
<li><a href="<?php bloginfo($url); ?>/Cat1">Category 1</a></li>
<li><a href="<?php bloginfo($url); ?>/Cat2">Category 2</a></li>
<?php wp_list_pages('sort_column=menu_order&title_li=&exclude=34'); ?>
<?php wp_list_cats('sort_column=name&exclude=1,2,7,10'); ?>
</ul>


This way you have a dynamic and static menu. Just an FYI, in WP 3.0 you will be able to make your own custom sidebar menus and use them as you please!