品牌出海 -
外贸推广、英文网站营销、独立站SEO

wordpress怎么使用卡片式文章内链功能

可以把要引用的文章以嵌入式卡片展现出来,不过样式比较单一,并且只能直接输入网址调用,这里给wordpress添加一个短代码调用功能,直接使用短代码就可以添加卡片式内链并且美化原始的效果。亲测有效哦,但是有时候要折腾一下,并不是通用的有些函数在不同的主题不好用吆!

首先需要将如下代码放入你主题的函数模板里(functions.php)\

/**
 卡片式文章内链功能
 */
 function yx_embed_posts( $atts, $content = null ){
 extract( shortcode_atts( array(
 'ids' => ''
 ),
 $atts ) );
 global $post;
 $content = '';
 $postids = explode(',', $ids);
 $inset_posts = get_posts(array('post__in'=>$postids));
 $category = get_the_category();
 foreach ($inset_posts as $key => $post) {
 setup_postdata( $post );
 $content .= ' '. $category[0]->cat_name .'
  '. _get_post_thumbnail() .' 
  '. get_the_title() . '
 
 '.wp_trim_words( get_the_excerpt(), 100, '…' ).'
  时间:'.get_the_time('Y-m-d').'
  评论:'. get_comments_number() .'
 阅读全文
';
 }
 wp_reset_postdata();
 return $content;
 }
 add_shortcode('yx_embed_post', 'yx_embed_posts'); 

注意:上述代码中有调用自定义的函数(如阅读量,缩略图等),如果读者使用的话需要根据实际情况进行修改,由于大家的主题不统一.
并给出其他网站在用的 CSS 代码,建议另存为 embed-card.css 并放入主题根目录的 css 文件夹中(与上述 PHP 代码中路径对应)

.embed-card,span.embed-card {
     display: block;
     position: relative;
     width: 620px;
     padding: 15px;
     margin: 30px auto;
     border: 1px solid #d4d4d4;
     overflow: hidden;
     max-width: 90%;
     transition: all 0.3s ease;
 }
 .embed-card:hover,span.embed-card:hover {
     box-shadow: 1px 1px 8px 5px #ddd;
     transition: all 0.3s ease;
 }
 .embed-card a,span.embed-card a {
     padding-right: 0;
     text-decoration: none;
     color: #313131;
 }
 .embed-card span,span.embed-card span {
     display: block;
     padding-right: 0;
 }
 .embed-card-category {
     display: inline-block;
     height: 20px;
     line-height: 20px;
     padding: 0 5px;
     font-size: 12px;
 }
 .embed-card-category {
     background-color: #6a99d8;
     background-color: rgba(43,110,200,0.8);
     color: #fff;
 }
 .embed-card-category:hover {
     background-color: #d5e2f4;
     background-color: rgba(43,110,200,1);
 }
 .embed-card .embed-card-category {
     position: absolute;
     top: 9px;
     left: 0;
     padding-right: 5px;
 }
 .embed-card-img {
     float: left;
     margin-right: 14px;
 }
 .embed-card-img img {
     width: 180px;
     height: 150px;
 }
 .embed-card-info {
     padding-right: 4px;
     overflow: hidden;
 }
 .embed-card-info .card-name {
     font-size: 16px;
     height: 44px;
     line-height: 22px;
     margin-bottom: 10px;
     margin-top: 7px;
     overflow: hidden;
     text-overflow: ellipsis;
     white-space: normal;
     font-weight: bold;
 }
 .embed-card-info .card-tags {
     height: 20px;
     overflow: hidden;
 }
 .embed-card-info .card-tags>span {
     display: inline-block;
     padding: 0 7px;
     margin-right: 8px;
     height: 16px;
     border: 1px solid #eee;
     line-height: 16px;
     color: #999;
     font-size: 12px;
 }
 .embed-card-info .card-tags span.tag-noborder {
     border: 0;
 }
 .embed-card-info .card-abstract {
     height: 36px;
     line-height: 18px;
     margin: 5px 0;
     font-size: 12px;
     color: #666;
     overflow: hidden;
     margin-bottom: 20px;
 }
 .embed-card-info .card-controls {
     overflow: hidden;
     line-height: 28px;
 }
 .embed-card-info .card-controls .group-data {
     float: left;
     margin-right: 10px;
     color: #999;
     font-size: 12px;
 }
 .embed-card-info .card-controls .group-data i {
     margin-right: 5px;
     font-style: normal!important;
 }
 .embed-card-info .card-btn-deep {
     float: right;
     width: 68px;
     height: 28px;
     margin-left: 10px;
     line-height: 28px;
     text-align: center;
     font-size: 12px;
     background-color: #ff5e5c;
     color: #fff;
 }
 .embed-card-info .card-btn-deep:hover {
     opacity: .9;
 }
 @media only screen and (max-width:700px) {
     span.embed-card {
         width: 95%;
         padding-left: 0;
         padding-right: 0;
     }
     .embed-card .embed-card-img {
         width: 24.27184%;
         margin-left: 9px;
     }
     .embed-card .embed-card-img img {
         width: 100%;
         height: auto;
     }
     .embed-card .embed-card-info {
         overflow: visible;
         padding: 0 9px;
     }
     .embed-card .embed-card-info .card-name {
         margin-top: 1%;
         margin-bottom: 1.5%;
     }
 }
 (机翻) .embed-card,跨度。{显示:块;位置:相对;宽度:620 px;填充:15 px;保证金:30 px汽车;固体边界:1 px

使用的时候只需要在文章里添加短代码

如果你不是在文章内容中,而是在其他地方想调用,则可使用下面代码来调用。

 do_shortcode('')

以上内容有助于用户体验

文章类别:外贸运营

如有转载,请注明本文链接: https://www.qi70.com/4728.html

赞(3) 外贸合作微信:Aiziji5267_
有任何问题或者外贸0-1建设合作联系微信:Aiziji5267_,本站点的内容仅供学习、分享与交流,不保证内容的正确性。通过使用本站内容随之而来的风险与本站无关。知识文章以及源码仅供参考学习,当使用本站时,代表你已接受本站的声明和隐私原则等条款。70外贸通_外贸跨境电商运营推广网站 » wordpress怎么使用卡片式文章内链功能
分享到: 更多 (0)
标签:

亚马逊、国际站代运营,独立站建设,外贸B2B、B2C合作加微信(w5267q) 抢沙发

专业网站运营,云服务器技术分享!

阿里云优惠购买购物优惠网

如有需要或者帮助可以加我微信:Aiziji5267_

支付宝扫一扫打赏

微信扫一扫打赏