今天写个WordPress文章内链短代码,当然这个并非是外链转内链啊,虽然做内链我们都会采用WordPress文章默认A链接但是我们有了这个WordPress文章内链短代码也是非常方便的,我们可以用短代码的方式添加文章ID来直接调用文章,非常方便,下面给出实现方法。
WordPress文章内链短代码
function ruikeedu_insert_posts( $atts, $content = null ){
extract( shortcode_atts( array(
'ids' => ''
),
$atts ) );
global $post;
$content = '';
$postids = explode(',', $ids);
$inset_posts = get_posts(array('post__in'=>$postids));
foreach ($inset_posts as $key => $post) {
setup_postdata( $post );
$content .= '<div class="card-today-history"><div class="card-thContents"><div class="card-thLine"></div><div
class="card-thHeroTitle"><a target="_blank" class="label--thTitle" href="' . get_permalink() . '">' . get_the_title() .
'</a><div class="v-floatRight card-thMeta">' . get_comments_number(). '<i class="iconfont icon-
comment"></i></div></div></div></div>';
}
wp_reset_postdata();
return $content;
}
add_shortcode('ruikeedu_insert_post', 'ruikeedu_insert_posts');
你可以根据你自己的需要来调整代码,也可以自己自定义CSS样式,我这里就不给出CSS代码了,下面呢给大家说下WordPress文章内链短代码怎么调用,这里呢提供二种方式。
WordPress文章内链短代码
//文章内部调用[ruikeedu_insert_post ids=123,245]
//其它地方调用do_shortcode('[ruikeedu_insert_post ids=123,245]')
OK本WordPress文章内链短代码WordPress教程结束,结尾呢我们做过SEO的都知道内链是非常重要的合理的使用内链才能促进网站排名瑞课还有其它的教程哟。

