WordPress.org

Ready to get started?Download WordPress

Forums

Customising Links (removing "li" etc..) (5 posts)

  1. SP303
    Member
    Posted 6 years ago #

    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?

  2. Kalon
    Member
    Posted 6 years ago #

    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.

  3. SP303
    Member
    Posted 6 years ago #

    Nice one Kalon, cheers :)

  4. syncbox
    Member
    Posted 5 years ago #

    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?

  5. yoshi
    Member
    Posted 5 years ago #

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

  6. .

    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');?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags