求推荐个wordpress文章内链的方法

正在查看 5 个帖子:1-4 (共 4 个帖子)
  • 作者
    帖子
  • bigcherry
    • 文章数量: 60
    @bigcherry
    楼主

    在发布文章后标签自动生成内链,不用了内链也不会消失,谢谢

    来自昆明, 云南, 中国
    cbsldf
    • 文章数量: 2
    @cbsldf

    当前主题     模板函数   functions.php

    注释一下代码

    /* 自动为文章内的标签添加内链 */
    $match_num_from = 1; //一篇文章中同一个标签少于几次不自动链接
    $match_num_to = 1; //一篇文章中同一个标签最多自动链接几次
    function tag_sort($a, $b){
    if ( $a->name == $b->name ) return 0;
    return ( strlen($a->name) > strlen($b->name) ) ? -1 : 1;
    }
    function tag_link($content){
    global $match_num_from,$match_num_to;
    $posttags = get_the_tags();
    if ($posttags) {
    usort($posttags, “tag_sort”);
    foreach($posttags as $tag) {
    $link = get_tag_link($tag->term_id);
    $keyword = $tag->name;
    $cleankeyword = stripslashes($keyword);
    $url = “<a href=”$link” title=””.str_replace(‘%s’,addcslashes($cleankeyword, ‘$’),__(‘【查看含有[%s]标签的文章】’)).”””;
    $url .= ‘ target=”_blank”‘;
    $url .= “>”.addcslashes($cleankeyword, ‘$’).”“;
    $limit = rand($match_num_from,$match_num_to);
    $content = preg_replace( ‘|(<a[^>]+>)(.*)(‘.$ex_word.’)(.*)(</a[^>]*>)|U’.$case, ‘$1$2%&&&&&%$4$5’, $content);
    $content = preg_replace( ‘|(<img)(.*?)(‘.$ex_word.’)(.*?)(>)|U’.$case, ‘$1$2%&&&&&%$4$5′, $content);
    $cleankeyword = preg_quote($cleankeyword,”’);
    $regEx = ”(?!((<.*?)|(<a.*?)))(‘. $cleankeyword . ‘)(?!(([^<>]*?)>)|([^>]*?))’s’ . $case;
    $content = preg_replace($regEx,$url,$content,$limit);
    $content = str_replace( ‘%&&&&&%’, stripslashes($ex_word), $content);
    }
    }
    return $content;
    }
    add_filter(‘the_content’,’tag_link’,1);

    来自蓉城, 安徽, 中国
    孙锡源
    • 文章数量: 704
    @ibadboy

    之前有人问过类似的:

    https://wenpai.org/support/topic/20063

    来自潍坊市, 山东省, 中国
    shenyebao
    • 文章数量: 1
    @shenyebao

    有现成的插件 https://gplwp.eastfu.com/product/interlinks-manager/ ,相当好用。把关键词对应的链接输入进去,文章和页面中带有关键词发布时就会自动加上链接。

    来自长沙, 湖南, 中国
    rawchen
    • 文章数量: 196
    @rawchen

    楼主的意思是发布文章的时候,自动处理文章内容里匹配的标签并添加A标签(链接)

    来自成都, 四川省, 中国
正在查看 5 个帖子:1-4 (共 4 个帖子)
  • 哎呀,回复话题必需登录。

话题信息