WordPress.org

Ready to get started?Download WordPress

Forums

How To Add Pipe ( | ) To php get_links code (15 posts)

  1. darrentunstall
    Member
    Posted 3 years ago #

    Here is what I am facing on my footer.php page at http://realtylms.com/:

    At the bottom in the footer I am using the following php code:

    <?php get_links(21, '<span>', '</span>', ' | ', TRUE, 'url', FALSE); ?>

    It works fine, except I want to separate each city using the PIPE (|) character so that the cities displayed will like this:

    Allied Gardens | Bay Park | Carmel Valley | Chula Vista | Clairemont | College | College Grove | etc.

    This is meant to be a navigation for featured communities in the footer.

    Open to Suggestions, please.

  2. <?php get_links(21, '<span>', '</span>', ' | ', TRUE, 'url', FALSE); ?> maybe? Have you tried other characters to make sure it's actually being parsed at all?

  3. Oh ... Stupid code. & #124; (without the space)

  4. darrentunstall
    Member
    Posted 3 years ago #

    I have not tried other characters. You have to forgive me, I am very green at PHP and have learned a ton, from people like you, in the past few weeks:

    Where do I add &#124 in the code?
    <?php get_links(21, '<span>', '</span>', ' | ', TRUE, 'url', FALSE); ?>
    Thanks again.

  5. In place of | - It's the ascii code for it :)

  6. darrentunstall
    Member
    Posted 3 years ago #

    Tried it and stays the same. Nothing changes. Any other thoughts?

  7. Put something else in. ANYTHING else :) Like a o or just any character.

  8. darrentunstall
    Member
    Posted 3 years ago #

    Just tried that and few other things. Nothing works. Is my code written correctly?

  9. That's what I was wondering ;) Actually get_links is deprecated.

    try http://codex.wordpress.org/Function_Reference/wp_list_bookmarks instead.

  10. darrentunstall
    Member
    Posted 3 years ago #

    I did see that, but every time I suse the wp_list_bookmarks code, it list each of my links on a separate line vs. they way I have it now.

  11. David Calhoun
    Member
    Posted 3 years ago #

    I'd agree with Ipstenu. Using deprecated functions can cause you a lot of headache.

    When using wp_list_bookmarks(), why not float the elements if you need them to be on the same line? What is the HTML that wp_list_bookmarks() is outputting? <li>'s?

    The solution I used incorporated wp_list_bookmarks(). http://wordpress.org/support/topic/adding-special-characters-between-bookmark-links-using-wp_list_bookmarks?replies=4#post-1313855

  12. darrentunstall
    Member
    Posted 3 years ago #

    Here's what happens when I add the following code:

    <?php $links = wp_list_bookmarks('title_li=&categorize=0&sort_column=menu_order&echo=0');
    $bookmarks = explode('</li>', $links); //create array from string returned by wp_list_bookmarks
    array_pop($bookmarks); //pop last element off array
    echo implode('<span class="divider"> | </span>', $bookmarks); ?>

    Allied Gardens |
    Bay Park |
    Carmel Valley |
    Chula Vista |
    Clairemont |
    College |
    College Grove |
    Coronado |

    I did try this:

    <?php get_links(21, '<span class="divider"> | </span>', ' | ', TRUE, 'url', FALSE); ?>

    Works, except it looks like this now (adds pipe before and after and adds description:

    | Allied Gardens1Allied Gardens of San Diego County | | Bay Park1Bay Park of San Diego | | Carmel Valley1Carmel Valley of San Diego

  13. David Calhoun
    Member
    Posted 3 years ago #

    Darren, have you tried using CSS to float the <li>'s inline?

  14. alchymyth
    Forum Moderator
    Posted 3 years ago #

    if you explode the string at the </li> position, don't forget to add the </li> into the implode code as well (the links that you followed to get your code have missed that);

    example:

    echo implode('<span class="divider"> | </span></li>', $bookmarks); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic