0

I would like a navigation something like this.

Home - People - About - Services - Contact

Home, About, Services and Contact are all pages.

People DOES NOT have a page, I would like to use this link to open a second Navigation.

Is it possible to add a link in wp_list_pages that doesn't link to a page.

Is it also possible to add a id to this link that doesn't have a page.

I would like the code to look something like this.

    <ul>
      <li><a href="Wordpress link">Home</a></li>
      <li id="people"><a href="No Page">People</a></li>
      <li><a href="Wordpress link">About</a></li>
      <li><a href="Wordpress link">Services</a></li>
      <li><a href="Wordpress link">Contact</a></li>
    </ul>  

1 Answer 1

1

I don't know what you mean by "open a second navigation". That could mean several things. But to get an "empty" link you have a couple of choices:

Option #1-- aka, easy but kind-of a hack

Add a menu item with the "Custom Links" form. You have to provide an URL but you can delete the URL after the item is added to the menu. You will end up with <a>People</a> in the menu. You can't add an id but you can add a class from the menu item's dialog.

Option #2-- Filter wp_list_pages

function prepend_to_page_walker_wpse_103936($output) {
  $pattern = '|<ul>|';
  $output = preg_replace($pattern,'<ul><li id="people"><a href="No Page">People</a></li>',$output,1);
  return $output;
}
add_filter('wp_list_pages', 'prepend_to_page_walker_wpse_103936');

Option #3-- Write a walker


Option #1 is obviously easier if you can use it, but it sounds like you aren't. Thought I would through it in though.

Option #2 should work. preg_replace with the fourth limit parameter should only replace the first occurrence of <ul>.

Option #3 would give you the most flexibility but it looks like you'd need to replace a significant method to do it (or this one), and I don't see the point of that effort. It is possible that I am missing something though.

1
  • Hi s_ha_dum, I have a number of pages with post thumbnails, I have these post thumbnails under the main navigation, they are hidden when the page loads, this is the second navigation. When the People link is clicked I show the post thumbnails. I think Option2 will work. Commented Jun 23, 2013 at 20:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.