Ready to get started?Download WordPress


Link Category Titles using get_bookmarks (2 posts)

  1. apatheticresistance
    Posted 3 years ago #

    Hi everyone,

    I'm trying to do some custom formatting for WordPress' Links (aka bookmark links). Using get_bookmarks() I can do most of what I want, but I can't get it to give me the name of each Link Category.

    According to The Codex I thought I should be able to get the category title out of any bookmark link (see Return Values). But it's always blank. So I tried the following code:

    $bookmarks = get_bookmarks();
    	foreach($bookmarks as $bm) {
    		echo $bm->link_id . ' id';
    		echo $bm->link_url . ' url';
    		echo $bm->link_name . ' name';
    		echo $bm->link_image . ' image';
    		echo $bm->link_target . ' target';
    		echo $bm->link_category . ' category';
    		echo $bm->link_description . ' description';
    		echo $bm->link_visible . ' visible';
    		echo $bm->link_owner . ' owner';
    		echo $bm->link_rating . ' rating';
    		echo $bm->link_updated . ' updated';
    		echo $bm->link_rel . ' rel';
    		echo $bm->link_notes . ' notes';
    		echo $bm->link_rss . 'rss';

    And nothing shows up for link_category. Same if I run print_r on $bm, link_category doesn't appear in the array at all.

    Can anyone help me figure out what's going on? Am I misinterpreting how to use get_bookmarks()? I'm no expert when it comes to using arrays.


  2. brasofilo
    Posted 3 years ago #

    i think if print_r does not prints something it's because it isn't there...

    using this idea, i solved it this way:

    $ritorna = "";
    $taxonomy = 'link_category';
    $args ='';
    $terms = get_terms( $taxonomy, $args );
    if ($terms) {
    	foreach($terms as $term) {
    		if ($term->count > 0) {
    			$ritorna .= "<h3>Category - ".$term->name."</h3>";
    			$bookmarks = get_bookmarks( array(
    							'orderby'        => 'name',
    							'order'          => 'ASC',
    							'category_name' => $term->name
    			foreach ( $bookmarks as $bm ) {
    			 		$ritorna .= sprintf( '<a class="relatedlink" href="%s">%s</a><br />', $bm->link_url, __($bm->link_name) );
    echo $ritorna;

Topic Closed

This topic has been closed to new replies.

About this Topic