Sorry if the title seems confusing or anything... I can't figure out what to put..
I'm actually a newbie but I've tried building a simple website in php before but back then I was just copying my navigation code to my every page and put 'current' to it so everytime, for example you are in the HOME page, the menu HOME in the nav bar is highlighted... now I tried following this tutorial to build my nav bar>http://dbwebb.se/kod-exempel/dynamic_php_menu/
I've got it but my problem is I don't know how to display my other pages when clicking the menu item...
I tried changing the 'url' to product.php (my products page)
<?php
$menu = array(
'home' => array('text'=> '<img class="brighten"; src="style/images/home-hover.png"/>', 'url'=>'?p=home'),
'products' => array('text'=>'Products', 'url'=>'products.php'),
'about' => array('text'=>'About', 'url'=>'about.php'),
);
?>
It displays the product page but the menu item 'Products' is not highlighted
btw my navigation bar is a separate php file and I just 'include' it in my other pages...
So how can I highlight the current choice while navigating to my 'Products' page?
I apologize if my question and explanation of the problem is confusing..
You can do it by simply check the file you pass as variable to select thr page. And if the current page is products for example. You add this class (I didn't viewed the link you gave, that's just the way I do it ..
Related
I have created html pages and trying to convert into wordpress theme,how to link html one page to other page in wordpress menu bar
sample code :
Features
this code is not working,it 's showing page not found.how to make this link in wordpress using php code.
Firstly Create Page "Features" from wp-admin.
Create template for this page.
http://codex.wordpress.org/Stepping_into_Templates
To set this page in menu Go in "Menu" section in WordPress.
http://codex.wordpress.org/Appearance_Menus_Screen
To view this menu in fronted use wp_nav_menu()
Take example template from your theme.
This is file in theme ending with -page.
Change template name in head of a file.
Then remember about the_loop all should be inside a loop to work correctly with many pages.
Put html there, also in header.php attach css to this html.
Page structure is like, header in the up, then page and then footer.
Remember to preserve good html structure - divs beginning and ending.
Then you create a page with content ( which is presented in the_loop ) , which has its own url address.
You can set url naming of pages in settings -> permalinks, you may need to write to .htaccess file.
Then you have direct url to page. You can use it in code like this:
echo bloginfo('url'). 'nameofpage';
All to do is create a template and assign it to page ( on page edit page template option ).
You can use pages or posts for this, i prefer pages.
Create new pages or posts and get their ID.
For linking its:
Get link with this:
get_permalink( $yourPostOrPageID ); // only get; not echo
Otherwise
Wordpress homepage link:
get_bloginfo('home');
Category or custom taxonomy term link:
get_term_link( $term, $taxonomy );
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
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.
}
I have a website with the following setup:
overview.php
hotel1.php
hotel2.php
hotel3.php
Where overview has a sidebar with links to hotels 1, 2 and 3 and each hotel page has a sidebar with links to the other two hotels (excluding itself) along with the overview page.
At the minute, I am hard coding the sidebar in each php page, as they are all slightly different.
I am wondering if there is a way I can code one sidebar in a separate file (sidebar.php) with links to each of the four pages and add the sidebar with a php include() function.
Then, depending on the page (which will have an identifier), show all the links, except the link to itself.
Problem is, I'm not sure how to do it, or if it can be done.
The site is php and html (with css and javascript).
And if it is relevant, I have about 100 folders containing an overview and then multiple hotels which I would like to implement this on.
The easiest way to do it is to wrap your sidebar code in a function.
sidebar.php
<?php
function print_all_sidebar_links_except_self($self = NULL){
$hotels_text = array(
"hotel1" => "Gryffindor Tower",
"hotel2" => "Ravenclaw Tower",
"hotel3" => "Slytherin Dungeons"
);
if (isset($self)){
unset($hotels_text[$self]);
}
foreach ($hotels_text as $page => $name){
echo "<a href='".$page.".php'>".$name."</a>";
}
}
?>
overview.php: print_all_sidebar_links_except_self();
hotel1.php: print_all_sidebar_links_except_self('hotel1');
hotel2.php: print_all_sidebar_links_except_self('hotel2');
hotel3.php: print_all_sidebar_links_except_self('hotel3');
Bit of a tough one to explain here, but I'll do my best.
I have this page template, which you can view here: http://goo.gl/y088X. The template firstly lists all the pages that are children of the category 'Exhibitions Archive' at the top as a sub menu, then the page outputs the attachments of these pages (images) on the page and uses some JS for presentation etc.
Currently, the submenu (the list of the child pages) items link to the pages, which is the obvious thing to do.
However, what I'd like to be able to do is keep everything on one page and have the sub menu items link to the post on the page and to scroll down to that section on the page (essentially, using anchor links). If you clicked on a exhibition title link in the sub menu, it would scroll to the title of the exhibition further down the page.
I have most of it set up, but I need to be able to do this dynamically. The titles down the pages marking the start of each section would need be be an anchor tag with the id tag referencing the sub-menu item, so when the sub menu item is clicked it'll scroll to that location with the sub menu item having the #anchor as the href, rather than a permalink to that page.
Is this at all possible?
This is what I'm using to list the items in the sub-menu, so I need a way of it dynamically creating a #anchor as the href rather than the permalink, and then the <h1> title down the pages marking each section to have the corresponding id.
Hope this makes sense, and hope you can help. I'll give some mega reputation for anyone who works this out :)
Thanks in advance,
R
<?php wp_list_pages('title_li=&child_of=155'); ?>
instead of using wp_list_page() you could try writing your own sub nav using get_pages()
http://codex.wordpress.org/Function_Reference/get_pages
once you build out your nav you can create and link to your content further down the page anyway you want..
<?php
if( is_page(155) ){
$args = array( 'child_of' => 155,
'sort_order' => ASC,
'sort_column' => post_date,
'parent' => 155,
'hierarchical' => 0
);
$mypages = get_pages($args);
?>
<ul>
<?php foreach( $mypages as $page ) {
?>
<li><?php echo $page->post_title; ?></li>
<?php
}
?>
</ul>
<?php
}
?>
hopefully that helps?
Marty