If category/page in wp_nav_menu exist - php

I need your help
I have three custom menu(wp_nav_menu) which I customize via admin menu section.
<!-- first menu ->
<?php companyMenu(); ?>
<!-- second menu ->
<?php servicesMenu(); ?>
<!-- third menu ->
<?php partnersMenu(); ?>
I want to show only one nav menu to which opened post/page/category belongs
For example: when I'm on home page click "Contacts" in menu it redirects me to "Contacts" page and because this page defined (with other menu links) in companyMenu() wp_nav_menu function it shows

It would really depend on how many pages you would need to check against for my solution to be viable- the fewer pages the better.
You could wrap your menu code in if statements and use the is_page wordpress function to check if you are on that page. See the link below for more information.
http://codex.wordpress.org/Function_Reference/is_page
Code Example
if(is_page( 'Contact' )){
servicesMenu();
}
As a general rule the wordpress codex has a great wealth of knowledge which I found really helpful when starting wordpress development

Related

Convert html to wordpress & provide link to menu inside panel

I have an HTML template which I am trying to convert into PHP for WordPress.
The homepage has been converted and is shown properly. Next, the menu in navbar is about, the page that needs to be converted in PHP.
I have just added get_header() at the top and get_footer() below. In between these two I have added the HTML content for my entire page.
Then I tried to provide the link for the menu that I created, but the content of about page is not visible.
Do I need to add any other line for that page apart from get_header and get_footer? Or is something wrong with the link?
Clearly I can't understand what your are trying to say. I think you want to create a page that will show your about menu content.
So in your theme directory create a page name page.php and use get_header(); in first and below get_footer and where you want to show page content write the_content();. like this
<?php
get_header(); ?>
<div><?php the_content(); ?></div>
<?php get_footer(); ?>
after that follow the url of # Sajid Anwar. because for dynamic data you have to create pages(home,about etc) from wordpress dashboard and in menu section add these pages as navigation menu to menu.

Wordpress - Display Content on page and its children

I am trying to implement a submenu into my page.php. It shall be dynamic so the different pages of my site have different submenus displayed on a certain place.
This is what I got so far:
<?php if (is_page(unternehmen || $post->post_parent==unternehmen)): ?> <!-- Unternehmen /postID 553 -->
<?php wp_nav_menu( array('menu' => 'Unternehmen Submenu' )); ?>
<?php endif; ?>
But with this solution the submenu here called "Unternehmen Submenu" will be displayed on every page that uses the page.php. I need a solution that displays the menu only on the respective page defined in the if-statement and its children. The best solution would be if the code fetches the main menu into this. It's an easy menu with one sublevel.
I searched for this specific problem here but didn't found a solution.

Conditionally display menu for page type in Wordpress

I am relatively unfamiliar with Wordpress and I am creating a custom theme for a client. I would like to either display or remove the main menu depending on the page type. I have researched several options like removing the navigation from header.php and referencing it separately and also making the menu conditional which is preferable.
I have a custom page type in my theme called 'landing page' on which I would like the menu to be never be displayed, though it will be on every other page. Ultimately there will be a lot of these and I would rather I didn't have to intervene.
I would rather not duplicate my header.php file but I can only find reference to displaying the menu conditionally like below by page name or ID which seems ridiculous.
<?php
if (is_page('contact')){
<?php include(TEMPLATEPATH.'/headerA.php'); ?>
}
elseif (is_page('gallery')){
<?php include(TEMPLATEPATH.'/headerB.php'); ?>
}
else {
<?php include(TEMPLATEPATH.'/headerA.php'); ?>
}
?>
Rather than including files as above, I will put the whole thing into my header and just make the navigation conditional. Does anyone know how I should approach this using my custom page type landing page rather than by page name so every page created with that type will never have a menu?
Thanks
Are you talking about a Custom Post Type (CPT) or a page called landing-page?
They are completely different. See http://codex.wordpress.org/Post_Types
In any event, this will work for a custom post type or a page:
if ( !is_singular( 'custom-post-type-name-or-page-slug-here' ) ) {
get_template_part('menu');
}
It says: "If this page is not a single page or a CPT, load the file menu.php from the theme folder."
See also http://codex.wordpress.org/Include_Tags:
The get_template_part() tag includes the file {slug}.php or
{slug}-{name}.php from your current theme's directory, a custom
Include Tags other than header, sidebar, footer.

In Wordpress, how can I change the destinations of my links dependent on what page user is on?

I have the problem that I am using a theme where the navigation is simply 'scrolling' to a given part (eg. #contact) when pressed. However, I have implemented some seperate subpages that exits this scrollable page and thus renders the navigation ineffective.
My question is, how can I change the destination of my links or maybe change the menu entirely when users are on these subpages?
I should clarify that all the pages that need 'the new' navigation use a different page template called full_width.php. But since it is using an include header function I can't just replace the navigation.
Thank you for your time!
Here is simple solution based on templates.
if ( is_page_template('full_width.php') ) {
//menu for full width page
} else {
// Returns false when 'full_width.php' is not being used.
wp_nav_menu( $args );//read for args in codex to make menu you want.
}

WordPress Category Question

I cannot figure out how to use the wp_list_categories function to do what I need it to:
<?php if(is_category() or is_page('realisations') or is_single()) { ?>
<ul id="subpage">
<?php wp_list_categories('child_of=3&title_li=<h4>Les secteurs</h4>'); ?>
</ul>
<?php }; ?>
I have it set up so that all of the project categories are child categories of the a main category (child_of=3) This is to avoid conflicts with the news section of the site.
The problem is that I need the category the post is in to highlight when viewing the single.php page template, but I don't know how to accomplish that. When on a category page the category view highlights correctly because I styled the class that WordPress adds into the generated list .current-cat.
I answered my own question! This wonderful plugin has the function that I didn't need to write myself: http://www.screenshine.net/blog/1474_wordpress-plugin-show-active-category
It sets a filter to add into the wp_list_categories() function, the only thing I dislike about it is that it sets a css class on the anchor instead of the list item, which is inconsistent with WordPress functionality. It works in a pinch though, which is what I am in. You can stick it in your functions.php to prepackage the plugin and do minor edits.

Categories