<?php
$linkdata = array(
"link_id" => 0, // integer, if updating, the ID of the existing link
"link_url" => \'\', // varchar, the URL the link points to
"link_name" => \'\', // varchar, the title of the link
"link_image" => \'\', // varchar, a URL of an image
"link_target" => \'\', // varchar, the target element for the anchor tag
"link_description" => \'\', // varchar, a short description of the link
"link_visible" => \'Y\', // varchar, Y means visible, anything else means not
"link_owner" => \'\', // integer, a user ID
"link_rating" => 0, // integer, a rating for the link
"link_updated" => \'0000-00-00 00:00:00\', // datetime, when the link was last updated
"link_rel" => \'\', // varchar, a relationship of the link to you
"link_notes" => \'\', // text, an extended description of or notes on the link
"link_rss" => \'\', // varchar, a URL of an associated RSS feed
"link_category" => \'\' // int, the term ID of the link category. if empty, uses default link category
);
?>
此函数不创建链接类别,它只将链接分配给您指定的类别(使用类别id),因此您需要先创建所有链接类别,然后运行代码进行插入。
我只需要设置所有要导入数组的链接,然后使用foreach循环遍历它们。
$links = array(
\'Link Title\' => array(\'http://example.org\', 23 ),
\'Another Link Title\' => array( \'http://domain.org\', 17),
);
foreach ( $links as $key => $value ) {
wp_insert_link( array( \'link_name\' => $key, \'link_url\' => $value[0], \'link_category\' => $value[1] ) );
}