Support » Themes and Templates » Customising Links (removing “li” etc..)

  • I’m looking to edit the code so that I can display links without
    “li” tags around them. I am assuming the code I need to edit is…

    function wp_list_pages($args = '') {
    	$defaults = array(
    		'depth' => 0, 'show_date' => '',
    		'date_format' => get_option('date_format'),
    		'child_of' => 0, 'exclude' => '',
    		'title_li' => __('Pages'), 'echo' => 1,
    		'authors' => '', 'sort_column' => 'menu_order, post_title'
    	);
    
    	$r = wp_parse_args( $args, $defaults );
    	extract( $r, EXTR_SKIP );
    
    	$output = '';
    	$current_page = 0;
    
    	// sanitize, mostly to keep spaces out
    	$r['exclude'] = preg_replace('[^0-9,]', '', $r['exclude']);
    
    	// Allow plugins to filter an array of excluded pages
    	$r['exclude'] = implode(',', apply_filters('wp_list_pages_excludes', explode(',', $r['exclude'])));
    
    	// Query pages.
    	$r['hierarchical'] = 0;
    	$pages = get_pages($r);
    
    	if ( !empty($pages) ) {
    		if ( $r['title_li'] )
    			$output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
    
    		global $wp_query;
    		if ( is_page() || $wp_query->is_posts_page )
    			$current_page = $wp_query->get_queried_object_id();
    		$output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
    
    		if ( $r['title_li'] )
    			$output .= '</ul></li>';
    	}
    
    	$output = apply_filters('wp_list_pages', $output);
    
    	if ( $r['echo'] )
    		echo $output;
    	else
    		return $output;
    }

    So I can see where the UL is etc… but I cant figure out how they create the code for each link and add the “li” tags etc… Can anyone help?

Viewing 4 replies - 1 through 4 (of 4 total)
  • It will be in yout theme’s function.php file.

    for example mine has this:
    (note the “before_widget” => & “after_widget” => bits)

    <?php
    if ( function_exists('register_sidebar') )
        register_sidebar(array(
            'before_widget' => '<li id="%1$s" class="widget %2$s">',
            'after_widget' => '</li>',
            'before_title' => '<h2 class="widgettitle">',
            'after_title' => '</h2>',
        ));
    ?>

    I would change it to this:

    <?php
    if ( function_exists('register_sidebar') )
        register_sidebar(array(
            'before_widget' => '<div>',
            'after_widget' => '</div>',
            'before_title' => '<h2 class="widgettitle">',
            'after_title' => '</h2>',
        ));
    ?>

    Or whatever you want to change the <li></li> tags to.

    Thread Starter sp303

    (@sp303)

    Nice one Kalon, cheers 🙂

    is there some way to do this without widgets?

    Here’s my nav (site uses pages only)

    <ul id="mainnavs">
    <?php wp_list_pages('title_li=&include=27'); ?>
    <?php wp_list_pages('title_li=&include=29'); ?>
    <?php wp_list_pages('title_li=&include=5'); ?>
    <?php wp_list_pages('title_li=&include=7'); ?>
    <?php wp_list_pages('title_li=&include=9'); ?>
    <?php wp_list_pages('title_li=&include=11'); ?>
    </ul>

    I want this image tag to appear INSIDE the <li></li> tags

    <img src="<?php bloginfo('template_directory'); ?>/sharedimages/navStar.png" class="navstar" />

    Any ideas?

    I would use css to set either background or bullet image to

    • .
    • If you really want <img> tags, you can set echo=0 and change the output:

      <?php
      $find= '<a href';
      $replace = '<img src="' . get_bloginfo('template_directory') . '/sharedimages/navStar.png" class="navstar" /><a href'; ?>
      
      <ul id="mainnavs">
      <?php echo str_replace($find, $replace, wp_list_pages('title_li=&include=27&echo=0')); ?>
      <?php echo str_replace($find, $replace, wp_list_pages('title_li=&include=29&echo=0')); ?>
      ...
      ...

      Btw, is there any particular reason for you calling multiple wp_list_pages instead of doing wp_list_pages('title_li=&include=27,29,5,7,9,11');?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Customising Links (removing “li” etc..)’ is closed to new replies.