这是一个简单而快速的Metabox+jQuery+纯文本解决方案。
如果要将下拉列表分为多个类别,请查看文档get_bookmarks
.
这也可能有用:add_meta_box
.
这是result:
以及code:
add_action( \'add_meta_boxes\', \'wpse_42440_add_custom_box\' );
add_action( \'admin_head\', \'wpse_42440_script_direct_print\' );
function wpse_42440_add_custom_box()
{
add_meta_box(
\'wpse_42440_sectionid\',
__( \'Blogroll\' ),
\'wpse_42440_blogroll_box\',
\'page\'
);
add_meta_box(
\'wpse_42440_sectionid\',
__( \'Blogroll\' ),
\'wpse_42440_blogroll_box\',
\'post\'
);
}
function wpse_42440_blogroll_box()
{
$bookmarks = get_bookmarks( array(
\'orderby\' => \'name\',
\'order\' => \'ASC\'
));
echo \'<div class="element" id="container-1">
<select name="bookmarks_dropdown" id="bookmarks_dropdown">
<option value="">- Select -</option>\';
/**
* Values contained in each $link
* link_id, link_url, link_name, link_image, link_target, link_description, link_visible, link_owner, link_rating, link_updated, link_rel, link_notes, link_rss
*/
foreach($bookmarks as $link) {
echo \'<option value="\'.$link->link_url.\'">\'.$link->link_name.\'</option>\';
}
echo \'</select>
<input type="checkbox" name="colores" id="new-window" value="">New window?
<br /><br />Plain link:<br /><input type="text" name="url1" id="plain-link" size="33" value="">
<br />Full link:
<br /><input type="text" name="url2" id="full-link" size="33" value="">
</div>\';
}
function wpse_42440_script_direct_print()
{
global $pagenow;
$post_types = array( \'post-new.php\', \'post.php\');
// Not our types. Quit.
if ( !in_array( $pagenow, $post_types ) )
return;
?>
<script type="text/javascript">
jQuery(document).ready(function($)
{
$(\'#bookmarks_dropdown\').on(\'change\', function()
{
// define vars
var target_window = $(\'#new-window\').attr(\'checked\') ? \' target="_blank"\' : \'\';
var full_link = \'<a href="\'+$(this).val()+\'"\'+target_window+\'>\'+$(\'#bookmarks_dropdown option:selected\').text()+\'</a>\';
// fill input text fields
$(\'#plain-link\').val($(this).val());
$(\'#full-link\').val(full_link);
});
});
</script>
<?php
}