如何利用wordpress自带的函数显示所有的友情链接,下面web建站小编给大家简单介绍一下wp_list_bookmarks 函数的运用方法!
具体调用:
<?php wp_list_bookmarks('title_li=&category_before=&category_after='); ?>
函数源码:
function wp_list_bookmarks( $args = '' ) {
$defaults = array(
'orderby' => 'name',
'order' => 'ASC',
'limit' => -1,
'category' => '',
'exclude_category' => '',
'category_name' => '',
'hide_invisible' => 1,
'show_updated' => 0,
'echo' => 1,
'categorize' => 1,
'title_li' => __( 'Bookmarks' ),
'title_before' => '<h2>',
'title_after' => '</h2>',
'category_orderby' => 'name',
'category_order' => 'ASC',
'class' => 'linkcat',
'category_before' => '<li id="%id" class="%class">',
'category_after' => '</li>',
);
$parsed_args = wp_parse_args( $args, $defaults );
$output = '';
if ( ! is_array( $parsed_args['class'] ) ) {
$parsed_args['class'] = explode( ' ', $parsed_args['class'] );
}
$parsed_args['class'] = array_map( 'sanitize_html_class', $parsed_args['class'] );
$parsed_args['class'] = trim( implode( ' ', $parsed_args['class'] ) );
if ( $parsed_args['categorize'] ) {
$cats = get_terms(
array(
'taxonomy' => 'link_category',
'name__like' => $parsed_args['category_name'],
'include' => $parsed_args['category'],
'exclude' => $parsed_args['exclude_category'],
'orderby' => $parsed_args['category_orderby'],
'order' => $parsed_args['category_order'],
'hierarchical' => 0,
)
);
if ( empty( $cats ) ) {
$parsed_args['categorize'] = false;
}
}
if ( $parsed_args['categorize'] ) {
// Split the bookmarks into ul's for each category.
foreach ( (array) $cats as $cat ) {
$params = array_merge( $parsed_args, array( 'category' => $cat->term_id ) );
$bookmarks = get_bookmarks( $params );
if ( empty( $bookmarks ) ) {
continue;
}
$output .= str_replace(
array( '%id', '%class' ),
array( "linkcat-$cat->term_id", $parsed_args['class'] ),
$parsed_args['category_before']
);
$catname = apply_filters( 'link_category', $cat->name );
$output .= $parsed_args['title_before'];
$output .= $catname;
$output .= $parsed_args['title_after'];
$output .= "\n\t<ul class='xoxo blogroll'>\n";
$output .= _walk_bookmarks( $bookmarks, $parsed_args );
$output .= "\n\t</ul>\n";
$output .= $parsed_args['category_after'] . "\n";
}
} else {
// Output one single list using title_li for the title.
$bookmarks = get_bookmarks( $parsed_args );
if ( ! empty( $bookmarks ) ) {
if ( ! empty( $parsed_args['title_li'] ) ) {
$output .= str_replace(
array( '%id', '%class' ),
array( 'linkcat-' . $parsed_args['category'], $parsed_args['class'] ),
$parsed_args['category_before']
);
$output .= $parsed_args['title_before'];
$output .= $parsed_args['title_li'];
$output .= $parsed_args['title_after'];
$output .= "\n\t<ul class='xoxo blogroll'>\n";
$output .= _walk_bookmarks( $bookmarks, $parsed_args );
$output .= "\n\t</ul>\n";
$output .= $parsed_args['category_after'] . "\n";
} else {
$output .= _walk_bookmarks( $bookmarks, $parsed_args );
}
}
}
$html = apply_filters( 'wp_list_bookmarks', $output );
if ( $parsed_args['echo'] ) {
echo $html;
} else {
return $html;
}
}
参数说明:
| 参数名 | 描述 |
|---|---|
| order | 升序 ASC 或 降序 DESC,默认 ASC。 |
| limit | -1 表示全部,1+整数表示要显示的个数。 |
| category | 以逗号分隔的类别ID列表,其中包含来自的链接。 |
| category_name | 要按名称检索链接的类别。 |
| hide_invisible | 是否显示或隐藏标记为“不可见”的链接。接受1|true或0|false。默认值1|true。 |
| show_updated | 是否显示书签上次更新的时间。接受1|true或0|false。默认值0|false。 |
| echo | 是回显还是返回格式化的书签。接受1|true(回显)或0|false(返回)。默认值1|true。 |
| categorize | 是显示按类别列出的链接,还是显示单列中的链接。接受1|true(按类别)或0|false(一列)。默认值1|true。 |
| show_description | 是否显示书签说明。接受1|true或0|false。默认值0|false。 |
| title_li | 链接出现之前要显示的内容。默认的“书签”。 |
| title_before | 要在$title_li字符串前附加的HTML或文本。默认值 |
| title_after | 要附加到$title_li字符串中的HTML或文本。默认。 |
| class | 用于$title_li的CSS类或类数组。默认“linkcat”。 |
| category_before | 如果$category为true,则在$title_before之前要准备的HTML或文本。字符串必须包含“%id”和“%class”,才能继承类别id和用于设置主题格式的$class参数。默认
|
| category_after | 如果$category为true,则要附加到$title_after的HTML或文本。默认。 |
| category_orderby | 如果$category为true,如何根据术语方案对书签类别进行排序。默认的“名称”。 |
| category_order | 如果$category为true,则按升序还是降序排列类别。接受“ASC”(升序)或“DESC”(降序)。默认为“ASC”。 |
WordPress版本如何使用str_starts_with和str_ends_with函数
wordpress教程如何输出用于回复评论的隐藏输入html
上面是“wordpress技巧如何显示所有的友情链接”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_4433.html
workflows工作流
一个男人正走进科幻的大门ComfyUI工作流
一张由表情符号组成的照片ComfyUI工作流
三阶放大comfyui工作流
一支令人难忘的狙击步枪ComfyUI工作流
一只白色的孔雀ComfyUI工作流
一座千年九尾白狐玉雕ComfyUI工作流
一块慕斯蛋糕ComfyUI工作流
树上挂着一只快乐的荔枝ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

iframe开发admin后台
canvas经线动画走到效果
barcode条形码/qrcode二维码兼容所有浏览器(含ie6/ie7/ie8)
3D彩色卡片
Bootstrap可视化拖放布局
纯html+css做一个3d统计效果
css3搭积木叠加图形
如何利用svg做一个有趣的loading动画加载









