I have created a static frontpage where I load in the content of all my pages. Now I have a normal custom menu, but the links refer to the pages, for example: http://mysite.com/about
Now the I want to have the link directed to the page itself with http://mysite.com/#about.
Now I have a custom walker that I use, and I have tried the following code:
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( get_bloginfo('url').'#'.$item->title ) .'"' : '';
Now this works ok, except for the home link itself. The home links to http://mysite.com/#home, but that one just needs to link to http://mysite.com/#
Is there something different I could use then $item->title to append.
--
If you want to know the method that I use to create the single page:
Creating the modern 'single page' html5 css3 layout in wordpress
=============== Update ===================
Just wanted to tell you guys what i did, maybe it helps someone.
Pages are structured like this:
Home (public) -> cutom menu item -> [link:#][label:home]
portfolio (private) -> cutom menu item -> [link:#portfolio][label:portfolio]
contact (private) -> cutom menu item -> [link:#contact][label:contact]
blog (public) -> page menu item -> [link:blog][label:blog]
Home and blog will be indexed and visible. portfolio and contact are loaded in home which is a front_page.php.
Note that I use relative links, and not absolute, html output will be href="#contact".
Now having it like this will conflict on the blog page, the links will become http://mysite.com/blog/#contact. We don't want that, we want just http://mysite.com/#contact
In my default walker I am going to edit edit in the absolute path. I do it here just to make the template a little more dynamic.
if($item->object == 'custom'){
$attributes .= ! empty( $item->url ) ? ' href="' .
esc_attr(get_bloginfo('url').'/'.$item->url ) .'"' : '';
}else{
$attributes .= ! empty( $item->url ) ? ' href="' .
esc_attr( $item->url ) .'"' : '';
}
Source to the complete walker can be found here: Menu items description?
Now the next thing is 1) to have a nice scroll effect (jquery scrollto) when the links are clicked on the frontpage 2) be redirected to the blog when the blog link is clicked 3) be redirected back to the right section when a hashlink is clicked on the blogpage.
Script for jQuery
$(document).ready(function() {
$('.menu-item-object-custom a').bind('click', function(e) {
e.preventDefault();
var parts = ($(this).attr("href")).split("#");
var target = '#' + parts[1];
if($('body.home').length){
var moveto = $(target).length ? $(target).offset().top : 0;
$('html, body').stop().animate({ scrollTop: moveto }, 1500, function() {
location.hash = target;
});
return false;
}else{
window.location = $(this).attr("href");
}
});
});
Note that the url in the browser is also changed, so the back button works also, and there is easy bookmarking.
Thanks for all the suggestions and inspiration bellow!! And I hope someone can use this.
