Add spans to generated menu
-
Hi,
I want to have the resulting code:
<li><a href=""><span>link title</span></a></li>I have generated the menu and require the
<span>to be inserted.I have seen posts on here for editing post-template.php and inserting:
link_before=<span>&link_after=</span>However I do not know where to add it!
I am a novice php dev.
Thanks for any help,
Jim C.
-
The code should be
<li><a><span>link title</span></a></li>.It’s basically so i can add rounded corners to a menu on a web site. has to be supported in IE so can’t be CSS3.
you need to wrap your code around
<?php the_title(); ?>calls in the loops on whichever templates you want it to appear ie:index.php
single.php
category.phpetc
Many thanks for your comment.
This is the index file – please could you provide an example?
Thank you, Jim.
===
<?php /** * The main template file. * * This is the most generic template file in a WordPress theme * and one of the two required files for a theme (the other being style.css). * It is used to display a page when nothing more specific matches a query. * E.g., it puts together the home page when no home.php file exists. * Learn more: http://codex.wordpress.org/Template_Hierarchy */ ?> <?php get_header(); ?> <div id="container"> <div id="content" role="main"> <?php /* Run the loop to output the posts. * If you want to overload this in a child theme then include a file * called loop-index.php and that will be used instead. */ get_template_part( 'loop', 'index' ); ?> </div><!-- #content --> </div><!-- #container --> <?php get_sidebar(); ?> <?php get_footer(); ?>Is there loop-index.php in the template as well? you need to post the code from that instead.
you want to look for something like:
<h2><a href="<?php echo get_permalink() ?>"><?php the_title(); ?></a></h2>and modify to your requirements:
<li><span><a href="<?php echo get_permalink() ?>"><?php the_title(); ?></a></span></li>Thats not really what I’m after – at least i dont think so.
Here is the link to the page in question:
http://testbed.callendercreates.com/chase/Need a span to put rounded corners on right hand side of menu/nav.
Thanks again for your help.
Oh, I was confused as you were mentioning ‘link title’ I assumed you meant the posts title not the header navigation. So what you need to do is add the styling to the menu navigation in header.php inside the following div:
<div class="menu-header">Great, that bit it clear, but I think i will need to add a span to the dynamic code of the menu?
http://codex.wordpress.org/Template_Tags/wp_list_pages
your menu in header.php is generated using wp_list_pages correct?
What’s that bit of code? thats where the link before and link after stuff can be used
Hi Voodoo,
link_before=<span>&link_after=</span>?I am not sure how implement this, correct – this is the piece of code i need to insert.
Fine with coding, but not with PHP.. Could you show me the exact code..
Many thanks for any advice. š
that’s why I was asking for the bit of code from your theme that generates your menu. Then someone can pop what you need into what you have already
I’m using WP3.0 RC.
Which file should i be looking at?
wp-includes/post-template.php?
function wp_link_pages($args = '') { $defaults = array( 'before' => '<p>' . __('Pages:'), 'after' => '</p>', 'link_before' => '', 'link_after' => '', 'next_or_number' => 'number', 'nextpagelink' => __('Next page'), 'previouspagelink' => __('Previous page'), 'pagelink' => '%', 'echo' => 1 );ooohohhhhh…..
yer using the 2010 theme that ships with 3.0 eh?
That’ll take me a bit longer, I’m just diving into the menu system on that theme…..not real familiar with it….
you dont wanna edit wp-includes/post-template.php or any core files, just theme files. You just wanna edit what’s in the actual theme….
http://codex.wordpress.org/Function_Reference/wp_nav_menu
<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?>in header.php is what outputs your nav menu from the 2010 theme
looks like we can still use the link before and link after to add in your span stuff…..
<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'menu-header', 'theme_location' => 'primary', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>might work?
yep that worked indeed! many thanks!! you rock!! š
The topic ‘Add spans to generated menu’ is closed to new replies.