• 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.

Viewing 15 replies - 1 through 15 (of 16 total)
  • Thread Starter callender

    (@jimcallender)

    The code should be <li><a><span>link title</span></a></li>.

    Thread Starter callender

    (@jimcallender)

    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.php

    etc

    Thread Starter callender

    (@jimcallender)

    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: https://codex.www.ads-software.com/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>
    Thread Starter callender

    (@jimcallender)

    Thats not really what I’m after – at least i dont think so.

    Here is the link to the page in question:
    https://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">

    Thread Starter callender

    (@jimcallender)

    Great, that bit it clear, but I think i will need to add a span to the dynamic code of the menu?

    https://codex.www.ads-software.com/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

    Thread Starter callender

    (@jimcallender)

    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

    Thread Starter callender

    (@jimcallender)

    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….

    https://codex.www.ads-software.com/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?

    Thread Starter callender

    (@jimcallender)

    yep that worked indeed! many thanks!! you rock!! ??

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Add spans to generated menu’ is closed to new replies.