• 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.

    Thanks!

Viewing 1 replies (of 1 total)
  • 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;

Viewing 1 replies (of 1 total)
  • The topic ‘Link Category Titles using get_bookmarks’ is closed to new replies.