teknohippy
Forum Replies Created
-
Forum: Themes and Templates
In reply to: Custom Menus on Different PagesGlad you’ve got it working, even happier you came to it yourself. You learn more that way.
Cheers
IForum: Themes and Templates
In reply to: Custom Menus on Different PagesIt can depend on the theme, but it would invariably be found in header.php.
What theme are you using?
Forum: Themes and Templates
In reply to: Custom Menus on Different PagesErr. I’m trying to remember what site I had to do this for!
…Time passes…
Okay found it, we’ll use it as an example.
If you look at the homepage (https://gigajam.com/) you’ll see the site needed four main sections, one for each of guitar, bass, keyboard and drums. Now when you get into those sections I wanted a different main menu for each of the instruments. This is the tabbed menu right at the top. If you go into any of the instrument “schools” you’ll see it change.
Now the code we’ve been discussing that outputs the menu is a function called wp_nav_menu. You’re theme will probably already have a call to this function in your header file.
You can learn more about wp_nav_menu on its codex page.
What is happening with the code as discussed above is that I am adding the following parameters to the wp_nav_menu call that was already in my header.
`’menu’ => get_post_meta( $post->ID, ‘MenuName’, true)
If you compare that to the codex page you can see that I’m passing something into the menu argument. What’s being passed in is the result of the call to get_post_meta(), which in pulling the value of MenuName out of the custom field for any given post/page.
Forum: Themes and Templates
In reply to: Custom Menus on Different PagesCustom fields are added in a posts edit page.
If you can’t see them check “screen options” at the top of the edit page.
You’ll see any existing custom fields there as above, although you will most likely not have any.
Just click “Add Custom Field” button to create a new one.
Use “MenuName” for the Key and the value should be the name of the Menu you want to use, the name you gave the menu in the “Appearances -> Menus” section
Forum: Themes and Templates
In reply to: Custom Menus on Different PagesIt’d work for any theme_location.
Glad you’ve found a solution.
Cheers
IainForum: Themes and Templates
In reply to: Custom Menus on Different PagesMark…
This code is in the header file:
<?php wp_nav_menu( array( 'container' => 'none', 'container_class' => 'menu-header', 'theme_location' => 'primary', 'menu' => get_post_meta( $post->ID, 'MenuName', true) ) ); ?>
Then in the admin site you can add new menus under the appearance section. These menus you add will have names.
Then if you require a different menu on a given page you need to make sure first that you can see the Custom Fields section of the page. Check the Screen Options link at the top to make sure you can see it.
Then create a new custom field called MenuName and give it a value matching the name of the menu you want that page to use.
Forum: Themes and Templates
In reply to: Custom Menus on Different PagesIf I don’t add a custom field for a menu then it seems to just default back to the one assigned to that location in the Appearance -> Menus.
I was quite pleased to see that happen without me having to code anything. *grins*
Forum: Themes and Templates
In reply to: Custom menus/headers for different categoriesI’ve just done this by combining the new building menu menus with a custom field.
In the theme I have:
<?php wp_nav_menu( array( ‘container’ => ‘none’, ‘container_class’ => ‘menu-header’, ‘theme_location’ => ‘primary’, ‘menu’ => get_post_meta( $post->ID, ‘MenuName’, true) ) ); ?>
Then in the page I simply have a custom field called “MenuName”, which is set to match the name of the wordpress nav_menu I want used on that page.
If a custom MenuName is not defined then it will fall back to the nav_menu assigned to that theme_location.
Forum: Themes and Templates
In reply to: Custom Menus on Different PagesI’ve been needing the same thing, a different menu for particular pages. I wanted to avoid having to have named pages in conditional statements though so have gone for something different, that means I don’t have to change the theme to add a new page/menu pair.
In the theme I have:
<?php wp_nav_menu( array( ‘container’ => ‘none’, ‘container_class’ => ‘menu-header’, ‘theme_location’ => ‘primary’, ‘menu’ => get_post_meta( $post->ID, ‘MenuName’, true) ) ); ?>
Then in the page I simply have a custom field called “MenuName”, which is set to match the name of the wordpress nav_menu I want used on that page.
If a custom MenuName is not defined then it will fall back to the nav_menu assigned to that theme_location.
Forum: Fixing WordPress
In reply to: different menus on different pagesI want different menus on different pages as well, I’ve just solved it with the new nav_menus and a little bit of theme tweaking. It’s worked out nicely as I won’t have to fiddle with the theme to add a new page and menu combination.
In the theme I have:
<?php wp_nav_menu( array( ‘container’ => ‘none’, ‘container_class’ => ‘menu-header’, ‘theme_location’ => ‘primary’, ‘menu’ => get_post_meta( $post->ID, ‘MenuName’, true) ) ); ?>
Then in the page I simply have a custom field called “MenuName”, which is set to match the name of the wordpress nav_menu I want used on that page.
If a custom MenuName is not defined then it will fall back to the nav_menu assigned to that theme_location.
Forum: Developing with WordPress
In reply to: Wrong order for get_posts using custom typeMy problem was a type, should be “orderby” of course.
Forum: Developing with WordPress
In reply to: Wrong order for get_posts using custom typeSimilar problem here with a custom post type.
$args = array( 'post_type' => 'cyclepanel', 'numberposts' => -1, 'category_name' => get_post_meta( $post->ID, 'CyclepanelCategory', true), 'order_by' => 'menu_order', 'order' => 'ASC' ); $cyclepanels = get_posts($args); if ($cyclepanels) { foreach ($cyclepanels as $cyclepanel) {