Add Static links To Pages Menu
-
We all know that the pages menu is created dynamically – however I would like to add a ‘Home’ link to the top of the menu that is created – does anyone know how I could do this.
Thankyou
-
I know I’ve answered this a couple of times but I couldn’t find the threads by quick search. So, here you go:
<ul>
<li><a href="<?php bloginfo('url'); ?>">Home</a></li>
<?php wp_list_pages('title_li='); ?>
</ul>
The important part is that title_li parameter with empty string as its value (it won’t generate ul tags), also that is why you need to add the tags manually. If you already have parameters in your wp_list_pages call just add/edit title_li accordingly.Hi thanks for the reply
But when I add it like that I get the menu like this
Home
Pages
About
Contact UsAs you can see the pages should be above the home as ‘Pages’ is the section title.
If you mean similar to the layout here:
…Notice the (pages) menu on the right:
FAQs (5 Main ~ 37 total)
==================
HOME
I: Installation
II: Quality and Performance:
III: Usage
IV: Errors
V: Links and more!…is this what you have in mind?
My ‘Home’ page (controlled via the ‘Page to Front’ plugin), is just like any other page of the main topic pages group, meaning it has no parent. [Main Page – (no parent)]
I use the ‘wp_list_pages’ function to build the menu, and excludes to hide any I don’t want, depending on which topic is currently being used.
The way the names for the topic pages are crafted forces ‘Home’ to the top…move thru the various topics and notice how they expand on entry, etc.
I can also make a link anywhere on the site, that calls that page (or also simply to the site url, of course). I try to utilize page_id’s as much as possible.
Any questions, let me know.
Ken
here’s the code too
<ul>
<li><a href="<?php bloginfo('url'); ?>">Home</a></li><?php wp_list_pages('title_li=<h2>' . __('Pages') . '</h2>' ); ?>
<li>
<h2><?php _e('Archives'); ?></h2>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul>
</li>I want everything as standard apart from to add a link to the homepage at the top of the dynamic pages menu that gets created.
My issue is as the menu is dynamically created where abouts can I place the code to make this work .
ghecko:
>My issue is as the menu is dynamically created where abouts can I place the code to make this work .
Depends on your layout, actually. Which theme? If it is same as mine (default wp 1.5), do you want it in the same location as mine?
If so, you want to add the code to the file ‘sidebar.php’ – …something like this:
<?php wp_list_pages('title_li=<h2>' . __('Pages') . '</h2>' ); ?>
This will list all pages, with links.
Yeah I have the code to list the pages – my issue is I want a link back to the main homepage like https://www.mysite.com so i have to place this static link somewhere in the wp_list_pages but dont know how to.
If i place the static link above the wp_list_pages it comes out above the section heading and below it comes out at the bottom. I guess I need a way to edit the wp_list_pages and place the static link in there.
Why don’t you put the section heading (
<h2>Pages</h2>
or something) outside the function call and put the rest as in my code example up there?ghecko:
>so i have to place this static link somewhere in the wp_list_pages but dont know how to.
Static link?
I use a page, and live linking, and it goes right to the top of the site. I use crafted page titles to keep this one at the top at all times. There are various ways to force the sorting, and this one worked easy for me.
Sorry, but I don’t see why you need a static link…?
Including a link to the main page at the top — or bottom, for that matter — of the page list requires some extra coding and inserting the link itself before or after the wp_list_pages function call. Thus the name “static link” (not going to debate correct terminology here — as long as people get understood).
The title_li needs to have an empty value because otherwise the page links will be wrapped in
<ul>
tags and adding a<li>
with the home link before the other pages will break validation. And because you can’t have the section header as the value of title_li you need to add it manually.>Including a link to the main page at the top — or bottom, for that matter — of the page list requires some extra coding….
Not on mine…again, it’s just another page, and the way the title is written, it’s always at the top.
<?php /* If this is home */ } elseif (is_page()) { ?>
<?php wp_list_pages('exclude=74,22,85&title_li=<h2>' . __('FAQs (5 Main ~ 37 total)') . '</h2>' ); ?>…works for me, validates and can be located anywhere on the sidebar.
What am I doing wrong that makes it right?
Kmtcn, you said you’re using “Page to Front” plugin. That’s why it works. But ghecko doesn’t need a plugin just to get that one little link in there.
>But ghecko doesn’t need a plugin just to get that one little link in there.
Seems ghecko does ??
Nooooo. I have Home link as the first thing of my page link list and I’m not using any plugins for that. I have that tiny little code snippet I pasted in my 1st reply. That’s it.
Let’s wait for ghecko’s reply now.
hi guys
I’m a little lost now ?? so many potential fixes.
I gues the easiest way we be if there was a way to create a Link as a page that way it would just show up automatically within the pages menu. i cant see any way to do this though.
I am basically trying to create a simple navigation strucutre as a menu and all of the other links are fine because they are actual pages ‘About us’ – Contact us ‘ etc however I want purely a link (I call it static in the sense of it isn’t auto generated) to my homepage like you see on lots of other sites.
The code from the first post looks good but it places the ‘Home’ link above the ‘Pages’ section title – I need some way for it to create the Section Title – then insert the static link and then insert the rest of the auto generated menu.
I’m trying to do as one of the later replies suggested creating my own ‘pages’ title and then add the menu but the css is all over the place at the mo as I use the
<li>
command and
<ul>
in the formatting.
- The topic ‘Add Static links To Pages Menu’ is closed to new replies.