Languages: English • 日本語 (Add your language)
This function returns an array of bookmarks found in the Administration > Links > Edit panel. This Template Tag allows the user to retrieve the bookmark information directly.
<?php get_bookmarks( $args ); ?>
<?php $args = array( 'orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => '', 'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0, 'include' => '', 'exclude' => '', 'search' => '' ); ?>
By default, the usage gets:
- Create a link category named "Related Sites"
- Create a few links, adding them to the "Related Sites" category
You may use the following code in your templates to retrieve the links:
<?php
$bookmarks = get_bookmarks( array(
'orderby' => 'name',
'order' => 'ASC',
'category_name' => 'Related Sites'
));
// Loop through each bookmark and print formatted output
foreach ( $bookmarks as $bookmark ) {
printf( '<a class="relatedlink" href="%s">%s</a><br />', $bookmark->link_url, $bookmark->link_name );
}
?>
- Create posts from Blogroll or Bookmark Items, useful if you want to migrate any of them before Blogrolls are no longer supported.
// Create posts from blogroll items
// set $test to true so we don't actually create posts
$test = true;
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'limit' => -1,
'hide_invisible' => 1,
'show_updated' => 0,
'include' => '',
'exclude' => '',
'search' => '' );
$thelist = get_bookmarks( $args );
echo "<PRE>";
//print_r($thelist);
$my_status = 'publish';
$post_type = 'clients';
$errors = array();
$k = 0;
foreach ($thelist as $item) {
$link_category = $item->link_category;
//echo "postarr $k\n";
//print_r($postarr);
$k++;
$link_url = $item->link_url;
$link_id = $item->link_id;
$link_name = $item->link_name;
$link_description = $item->link_description;
$postarr = array(
'post_type' => $post_type,
'post_content' => $link_description,
'post_title' => $link_name,
'post_excerpt' => $link_description,
'menu_order' => $link_id,
'post_status' => $my_status,
);
// see if there is an existing post?
$there_is_one_already = get_page_by_title( $link_name, OBJECT , $post_type );
if ( $there_is_one_already) {
echo "there_is_one_already: $link_name, so we are skipping...\n";
print_r($there_is_one_already);
continue;
}
$newpost_id = '';
if (!$test) {
//if ($k>1) {continue;} // only do first
$newpost_id = wp_insert_post( $postarr);
if (!$newpost_id) {$errors[] = $link_name; continue;}
echo "created $post_type id $new_post_id\n";
//create a custom field with the link_url
add_post_meta( $newpost_id, 'link_url', $link_url );
}
}
print_r($errors);
Since: 2.1.0
get_bookmarks() is located in wp-includes/bookmark.php.
get_bookmark(), get_bookmark_field(), get_bookmarks(), wp_list_bookmarks()