秋硕学习笔记 美化 增加WordPress 友情链接页面的方法

增加WordPress 友情链接页面的方法

1、把下面的代码添加到functions.php中: /* 增加WordPress 友情链接页面:https:…

1、把下面的代码添加到functions.php中:

/* 增加WordPress 友情链接页面:https://fatesinger.com/*/
function get_the_link_items($id = null){
    $bookmarks = get_bookmarks('orderby=date&category=' .$id );
    $output = '';
    if ( !empty($bookmarks) ) {
        $output .= '<ul class="link-items fontSmooth">';
        foreach ($bookmarks as $bookmark) {
            $output .=  '<li class="link-item"><a class="link-item-inner effect-apollo" href="' . $bookmark->link_url . '" title="' . $bookmark->link_description . '" target="_blank" >'. get_avatar($bookmark->link_notes,64) . '<span class="sitename">'. $bookmark->link_name .'</span></a></li>';
        }
        $output .= '</ul>';
    }
    return $output;
}

function get_link_items(){
    $linkcats = get_terms( 'link_category' );
    if ( !empty($linkcats) ) {
        foreach( $linkcats as $linkcat){            
            $result .=  '<h3 class="link-title">'.$linkcat->name.'</h3>';
            if( $linkcat->description ) $result .= '<div class="link-description">' . $linkcat->description . '</div>';
            $result .=  get_the_link_items($linkcat->term_id);
        }
    } else {
        $result = get_the_link_items();
    }
    return $result;
}

function shortcode_link(){
    return get_link_items();
}
add_shortcode('bigfalink', 'shortcode_link');

2、CSS:

//* 增加WordPress 友情链接页面:https://fatesinger.com */
.link-title {
    font-size: 18px;
    color: rgba(0,0,0,0.44);
    margin: 40px 0 10px
}

.link-description {
    font-size: 12px;
    margin-bottom: 10px;
    font-style: italic;
    color: rgba(0,0,0,0.3)
}

.link-item {
    display: inline-block;
    margin: 10px;
    width: 64px;
    vertical-align: top
}

.link-item-inner {
    display: block;
    overflow: hidden;
    position: relative;
    text-decoration: none!important
}

.link-item .avatar {
    border-radius: 5px;
    width: 64px;
    height: 64px
}

.sitename {
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block
}

.effect-apollo::before {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255,255,255,0.5);
    content: '';
    -webkit-transition: -webkit-transform 0.6s;
    transition: transform 0.6s;
    -webkit-transform: scale3d(1.9,1.4,1) rotate3d(0,0,1,45deg) translate3d(0,-100%,0);
    transform: scale3d(1.9,1.4,1) rotate3d(0,0,1,45deg) translate3d(0,-100%,0)
}

.effect-apollo:hover::before {
    -webkit-transform: scale3d(1.9,1.4,1) rotate3d(0,0,1,45deg) translate3d(0,100%,0);
    transform: scale3d(1.9,1.4,1) rotate3d(0,0,1,45deg) translate3d(0,100%,0)
}

3、调用方法

新建页面,直接添加短代码

[bigfalink]

即可。也可新建自定义模版使用以下代码调用:

<!--?php echo get_link_items(); ?-->

4、链接演示

演示

代码来自bigfa

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。若本站内容侵犯了原著者的合法权益,请联系我们进行处理。本文地址:https://wparticle.cn/476.html

作者: wordus

记录生活感悟,分享网络资源,交流学习体会,感受美好人生。秋硕学习笔记,记录分享学习、生活、工作、旅游、健身、爱好的个人博客。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

返回顶部