增加网站之间的内链有利于SEO。可以通过在文章末端增加相关文章推荐、热评文章推荐、最新文章推荐来提高网站的内链程度。

示例

电子发烧友网站的内链建设

某保健网站的内链建设

添加之后的效果

添加的效果

代码详解

针对handsome主题,直接放在主题文件夹下的post.php文件里。具体位置如下图所示。

代码的位置

相关文章推荐

这里的推荐是根据标签来推荐的。相同的标签则认为是相关的文章,因此在写文章的时候要注意标签的建设。

            <div class="tab-content clear">
            <h4 class="widget-title m-t-none text-md"><?php _me("※相关文章推荐※ ") ?>
            </h4>
            <div id="relatedPosts" >
            <ul class="list-group-item  nav nav-list">
                <?php $this->related(6)->to($relatedPosts); ?>
                <?php if ($relatedPosts->have()): ?>
                    <?php while ($relatedPosts->next()): ?>
                    <li >
                        <a href="<?php $relatedPosts->permalink(); ?>" title="<?php $relatedPosts->title(); ?>"><?php $relatedPosts->title(); ?></a>
                    </li>
                    
                    <?php endwhile; ?>
                <?php else : ?>
                <li>暂无相关推荐</li>
                <?php endif; ?>
            </ul>
            </div>
            </div> 

数字6即最多显示6篇。不建议显示太多。

热门文章推荐

首先,在function.php的底部增加一个函数:

function getHotComments($limit = 5){
$db = Typecho_Db::get();
$result = $db->fetchAll($db->select()->from('table.contents')
->where('status = ?','publish')
->where('type = ?', 'post')
->where('created <= unix_timestamp(now())', 'post')
->limit($limit)
->order('commentsNum', Typecho_Db::SORT_DESC)
);
if($result){
foreach($result as $val){
$val = Typecho_Widget::widget('Widget_Abstract_Contents')->push($val);
$post_title = htmlspecialchars($val['title']);
$permalink = $val['permalink'];
echo '<li><a href="'.$permalink.'" title="'.$post_title.'" target="_blank">'.$post_title.'</a></li>';
}
}
}

随后在post.php文件里增加代码:

            <div class="tab-content clear">
            <h4 class="widget-title m-t-none text-md"><?php _me("※热评文章推荐※") ?>
            </h4>
            <div id="relatedPosts" >
            <ul class="list-group-item  nav nav-list">
            <li> <?php getHotComments('5');?>  </li>
            </ul>
            </div>
            </div> 
          <br >

数字5就是最多显示5篇。

最新文章

            <div class="tab-content clear">
            <h4 class="widget-title m-t-none text-md"><?php _me("※最新文章推荐※") ?>
            </h4>
            <div id="relatedPosts" >
            <ul class="list-group-item  nav nav-list">
                <?php
                $recent = $this->widget('Widget_Contents_Post_Recent','pageSize=6');
                if($recent->have()):
                while($recent->next()):
                ?>
            <li><a href="<?php $recent->permalink();?>"><?php $recent->title();?></a></li>
            <?php endwhile; endif;?>

            </ul>
            </div>
            </div> 

pageSize=6指最多显示6篇。


数量上可以自行设置参数。样式可以自定义CSS。我觉得没必要做的太花哨。

本文标签: SEO网站开发

版权声明 ▶ 本网站名称:陶小桃Blog
▶ 本文链接:https://www.52txr.cn/2022/relatedLinks.html
▶ 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行核实删除。
▶ 转载本站文章需要遵守:商业转载请联系站长,非商业转载请注明出处并附带原文链接!!
▶ 站长邮箱 [email protected][email protected] ,如不方便留言可邮件联系。

小陶的个人微信公众号

学累了就来张美女照片养养眼吧,身体是革命的本钱,要多多休息哦~ 随机美女图片

最后修改:2023 年 03 月 29 日
如果觉得我的文章对你有用,请随意赞赏!