DotDragnet
May 23, 2012, 09:42:43 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: follow us on twitter @dotdragnet
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Individual Menu in Wordpress  (Read 856 times)
Barney McGrew
Sr. Member
****
Posts: 257


Resident Firefighter


View Profile WWW Awards
« on: October 23, 2010, 12:05:58 AM »

Having spent the past few days on WordPress, I have worked most of the stuff out, in fact I am very impressed. However, one thing I cant seem to master is creating an individual menu for each page.

I have created 6 or 7 parent pages which all show in the horizontal menu. I have also downloaded a plug in that allows me to create a page and exclude it from this list. However, I have a section called Fire Safety of which Fire Safety is the Parent Page. I have under this parent page 20 child pages which are listed as a drop down in the horizontal menu on the main page, fine. What I want to do is when a visitor clicks on the Fire Safety section, they are presented with a sidebar menu, just with the 20 child pages allowing them to browse the section without too much difficulty. I feel I may just be missing something here, even if its just a plugin, but with 1000s of them, I am no t sure which is a good one.

Appreciate it if anyone can help ?
Logged
Mr Anderson
DDN Contribs
Hero Member
*****
Posts: 2267



ap4a.uk ap4a
View Profile WWW Awards
« Reply #1 on: October 23, 2010, 12:31:27 AM »

You need to use the new custom menus feature:
http://codex.wordpress.org/Function_Reference/wp_nav_menu
http://justintadlock.com/archives/2010/06/01/goodbye-headaches-hello-menus
Logged

Barney McGrew
Sr. Member
****
Posts: 257


Resident Firefighter


View Profile WWW Awards
« Reply #2 on: October 23, 2010, 01:59:20 AM »

 dontgetit
Logged
Mr Anderson
DDN Contribs
Hero Member
*****
Posts: 2267



ap4a.uk ap4a
View Profile WWW Awards
« Reply #3 on: October 23, 2010, 11:02:26 AM »

It's pretty straightforward, the first link outlines the code that's used and the second explains how to use it. For example, on a site we're working on now we have the following:

1. Register the menu(s) in the Theme Functions file (functions.php):

Code:
// register the navigation menus
if (function_exists('register_nav_menus')) {
register_nav_menus(
array(
  'top_nav' => 'Top Nav Menu',
  'side_nav' => 'Sidebar Menu'
)
);
}

2. Call the menu(s) in the template file(s) containing them (eg. header.php or sidebar.php) - so for eg. the top_nav menu:

Code:
<div id="topnav">
<?php wp_nav_menu( array('theme_location' => 'top_nav''container' => '''menu_id' => 'nav''menu_class' => 'nav''fallback_cb' => 'wp_page_menu' )); ?>
</div><!-- end of topnav -->


This code calls the top_nav which was registered in the Theme Functions file with the code at the top. It sets a class and an ID on the menu (both set to nav here), and sets a fall back menu option for redundancy.

Once you've done that you, in your WP admin panel, can go to Appearance --> Menus and directly edit your menu. You can select which pages or categories appear in a menu, you can add in a link to any other page on the internet so that you're not confined to just pages on your own site, and you can set it to automatically add new top level pages to a menu if you want to.

Once you've selected what you want in the menu you can drag and drop to reorder them, and establish sub-menu items by indenting a menu item beneath another item. You can also change the link text used by any item so that you're not restricted to the page title, and so on.
Logged

Matt
DDN Contribs
Hero Member
*****
Posts: 1710



View Profile WWW Awards
« Reply #4 on: October 23, 2010, 08:36:13 PM »

Having spent the past few days on WordPress, I have worked most of the stuff out, in fact I am very impressed. However, one thing I cant seem to master is creating an individual menu for each page.

I have created 6 or 7 parent pages which all show in the horizontal menu. I have also downloaded a plug in that allows me to create a page and exclude it from this list. However, I have a section called Fire Safety of which Fire Safety is the Parent Page. I have under this parent page 20 child pages which are listed as a drop down in the horizontal menu on the main page, fine. What I want to do is when a visitor clicks on the Fire Safety section, they are presented with a sidebar menu, just with the 20 child pages allowing them to browse the section without too much difficulty. I feel I may just be missing something here, even if its just a plugin, but with 1000s of them, I am no t sure which is a good one.

Appreciate it if anyone can help ?


If you want to just show the child pages of the current parent page use this code:

Code:
<!-- Displays Child Pages if they are present -->

<?php
  
if($post->post_parent)
  
$children wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
  else
  
$children wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
  if (
$children) { ?>

  

<img src="http://www.wolverley.worcs.sch.uk/wp-content/images/also.png" title="Also in this Section">
  <ul><?php echo $children?></ul>

  <?php ?>



This displays the child pages of the current pages parent page.
Logged

Barney McGrew
Sr. Member
****
Posts: 257


Resident Firefighter


View Profile WWW Awards
« Reply #5 on: October 24, 2010, 12:30:43 AM »

Cheers Matt, worked a treat. Had no idea which page to add it to or amend. Sarah sent us a link http://codex.wordpress.org/Function_Reference/wp_list_pages which coupled with your code, I managed to implement into my sidebar.php to give me the menu.

Much appreciated.

As a side note. I am just playing at the moment and have purchased a simple clean template to give me a little more than the basic template to play with. Are there many templates that are created so that they pass the valid html tests. The one I have throws up some simple errors such as alt tags missing which I suppose is easily rectified. There are some other errors I have no idea about. In saying all this, you would think that if someone is going to create a template, then something as simple as alt tags would be a must ?.

I have looked around and cant seem to find many that do validate.
Logged
sarahA
DDN Contribs
Hero Member
*****
Posts: 2184



View Profile WWW Awards
« Reply #6 on: October 24, 2010, 09:00:35 AM »

Unfortunately there are plenty of themes out there which aren't well coded. To be fair, WP themes aren't usually too bad but I've still seen a nice designed theme, installed it and discovered how much it breaks or fails on validation. You'll find a lot are coded to XHTML transitional which isn't the best doctype to be coding to. It's not hard to get it up to strict standards, but you just need to bear in mind, a lot of these theme developers are actually just designers who aren't full time front end developers, they just know how to put web pages together, doesn't mean the code is good!

If the theme is nice and the validation fixes aren't too bad, I would just fix them up (post up here if there are some you're not sure of!). I recently grabbed a quite popular theme off there (I'm sure it wasn't when I got it!) and my whole pages menu disappeared, couldn't for the life of me work out where it was besides off screen somewhere, but with a bit of food bribery Mr A came to the rescue and got it showing again wink

On a side note, the custom menu that Mr A mentioned would be very useful for your top horizontal menu, as you can have complete control of that then, mix and match links to pages, post categories, individual posts (if you wish), external links etc. Your horizontal menu at present is probably wp_list_pages() for the top level pages only (depth of 1) which means you're needing this extra plugin to hide specific pages, whereas with the custom menu you would simply control which pages displayed.

You could still use the sub page code to display the sub pages in the sidebar as per Matt's code and the link I emailed, although I recently had to get some code that would cover all ancestor pages (child, grandchild etc) which I found at http://cssglobe.com/post/5812/wordpress-find-pages-top-level-parent-id.

Also, a second sidenote, if you've used a theme from WordPress, be aware that unless any changes you make to the actual theme are done in a child theme (a second theme directory that's told that it's the child theme of the original parent theme), then if/when the theme developer decides to upgrade their theme at all you will get notified of an upgrade for it. You don't have to upgrade so just be aware of this because if you do, all of your changes instantly lost! Hence the reason for the child theme approach to be better (although whilst I know this, I rarely follow my own advice!)
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!