WordPress.org

Ready to get started?Download WordPress

Forums

Adding a <span></span> in the title_li (14 posts)

  1. erik5388
    Member
    Posted 5 years ago #

    Hey PressSmarties,
    I am fairly new to php and don't quite yet understand the logic. In this expression <?php wp_list_pages('title_li='); ?> how would I successfully add an opening <span> and a closing </span> on the outsides of what normally forms and renders this html ,

    <ul>    
    
    <li class="page_item page-item-2">
    <a href="#" title="About">About</a>
    </li>
    
    <li class="page_item page-item-3">
    <a href="#" title="#">LinkTwoPageTwo</a>
    </li>
    
    </ul>

    My goal is to achieve this here,

    <ul>
    <li class="page_item page-item-2">
    <a href="#" title="About"><span>About</span></a>
    
    <li class="page_item page-item-3">
    <a href="#" title="#"><span>LinkTwoPageTwo</span></a>
    
    </ul>

    ^^ with the span tags outlining the link.

    Thanks for the support,
    <3 WordPress

  2. erik5388
    Member
    Posted 5 years ago #

    bump

  3. terriann
    Member
    Posted 5 years ago #

    Closest I can find is the link_before and link_after parameter
    http://codex.wordpress.org/Template_Tags/wp_list_pages

    Would make this <?php wp_list_pages('title_li=link_before=<span>&link_after=</span>'); ?>

    Unfortunately these parameters are Version 2.7.0 or newer.

    Would display something like:

    <ul>
    <li class="page_item page-item-2">
    <span><a href="#" title="About">About</a></span></li>
    <li class="page_item page-item-3">
    <span><a href="#" title="#">LinkTwoPageTwo</a></span></li>
    </ul>
  4. erik5388
    Member
    Posted 5 years ago #

    I will try this... Thank you (=

  5. erik5388
    Member
    Posted 5 years ago #

    Unfortunately this is not processing correctly.
    I do have the latest version of WordPress.

    Was this expression written correctly?

    <?php wp_list_pages('title_li=link_before=<span>&link_after=</span>'); ?>
  6. erik5388
    Member
    Posted 5 years ago #

    bump

  7. erik5388
    Member
    Posted 5 years ago #

    bump

  8. erik5388
    Member
    Posted 5 years ago #

    bump

  9. jbjweb
    Member
    Posted 5 years ago #

  10. Dap1
    Member
    Posted 5 years ago #

    Terrian was close to being correct. The code below works.

    <?php wp_list_pages('title_li=<span>&link_after=</span>'); ?>

    The post by jbjweb is full of errors. I do not suggest using that technique.

  11. Justin Tadlock
    Member
    Posted 5 years ago #

    Maybe not the best way to do it, but this will work:

    <ul>
    <?php
    	$pages = wp_list_pages('echo=0&title_li=');
    	$pages = str_replace('">', '"><span>', $pages);
    	$pages = str_replace('<span><a', '<a', $pages);
    	$pages = str_replace('</a>', '</span></a>', $pages);
    	echo $pages;
    ?>
    </ul>

    It'll give you list items like this:

    <li><a href="" title=""><span>Link</span></a></li>
  12. erik5388
    Member
    Posted 5 years ago #

    wow good responses,
    I'll let you know. Thanks (=

  13. ErasmusCSS
    Member
    Posted 5 years ago #

    Hello, I don't know if still someone is interested in this issue, but i figured out, that it only works if you put "title_li" at the end, and not
    in the beginning as terriann suggested. What Dap1 proposed puts only one <span> at the begin and one at the end but not arround every link.

    Here the code that works:

    <?php wp_list_pages('link_before=<span>&link_after=</span>&title_li='); ?>
    
  14. ErasmusCSS
    Member
    Posted 5 years ago #

    Well, maybe I got the question wrong, my code gives you a <span> arround every element (also subpages), maybe the question was only how to put a <span> arround the title element as <h2>Pages</h2>

Topic Closed

This topic has been closed to new replies.

About this Topic