WordPress.org

Ready to get started?Download WordPress

Forums

Using pipe (' | ') to separate nav links [update] (3 posts)

  1. prionkor
    Member
    Posted 3 years ago #

    Hi, i was checking for a suitable function for listing the pages with pipes in footer. I have found a useful post here

    The last guy used the method for string replacing. Some how his function is not suitable for me because it was still echoing the li. So i modified the code placed it in a function. The topic was closed. So, i post it here. You might found this useful.

    function page_list_with_pipe(){
    	// wp_page_list with separator element
    	$args = array(
    		'title_li' => '',
    		'exclude'		=> '120,121',
    		'child_of'	=> 0,
    		'parent'		=> 0,
    		'exclude_tree'	=> '',
    		'hierarchical'	=> 1,
    		'echo' => 0 );
    
    	$pgl=wp_list_pages( $args );
    	$sep=' | '; //  separator
    	$rep1='<li';
    	$rep1by='<span'; // replacing the <li with <span
    	$rep2='</li>';
    	$rep2by=$sep.'</span>'; // replacing </li> with </span>
    	$pgl=str_replace($rep1,$rep1by,$pgl);
    	$pgl=str_replace($rep2,$rep2by,$pgl);
    	if($sep!='') :
    	$pgl=strrev($pgl); $sep=strrev($sep); // this is needed for removing the last separator
    	$pgl=explode($sep,$pgl,2); // this is needed for removing the last separator
    	$pgl=implode('',$pgl); $pgl=strrev($pgl); // this is needed or removing the last separator
    	endif;
    	echo $pgl; // echo pagelist
    }
    ?>

    In my personal opinion this kinds of function should be include in wordpress (or may be there is and i don't know!) anyone can post upgraded code. Thanks!

  2. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    You don't need a function to list pages with |. You can achieve this using pure CSS.

  3. prionkor
    Member
    Posted 3 years ago #

    Yes i know. Adding this function outputs the lists with span around instead of li so less time i have to mass around with css.

Topic Closed

This topic has been closed to new replies.

About this Topic