WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Using a variable in an array? (3 posts)

  1. jennybeaumont
    Member
    Posted 2 years ago #

    Hi there,

    I'm looking for some basic php help trying to use the get_bookmarks function, but with a variable in the place of the category_name.

    I'm starting with this code that I found in the codex:

    <?php
    $bookmarks = get_bookmarks( array(
    				'orderby'        => 'name',
    				'order'          => 'ASC',
    				'category_name'  => 'Related Sites'
                              ));
    
    // Loop through each bookmark and print formatted output
    foreach ( $bookmarks as $bm ) {
        printf( '<a class="relatedlink" href="%s">%s</a><br />', $bm->link_url, __($bm->link_name) );
    }
    ?>

    But instead of 'category_name' => 'Related Sites'
    I'd like to do use something to the equivelant of 'category_name' => 'the_title()'

    Which of course doesn't work. This only displays the title without allowing it to be used as the variable.

    Yes, each page will have the same name as the link category. And no, I feel there are too many categories to use an if/else statement - also because I would like to be able to add link categories and pages without having to touch this code.

    Can anyone help?
    thanks!
    -jennyb

  2. Oleg Dudkin
    Member
    Posted 2 years ago #

    Hi,
    you can try something like

    $bookmarks = get_bookmarks( array(
    				'orderby'        => 'name',
    				'order'          => 'ASC',
    				'category_name'  => get_the_title()
                              ));
  3. jennybeaumont
    Member
    Posted 2 years ago #

    OMG - Oleg, you are awesome!! Thank you so much!
    *does a little happy dance*
    -jennyb

Topic Closed

This topic has been closed to new replies.

About this Topic