环境现状

博客框架:typecho
主题插件:Handsome

修改的代码路径

网址根目录\usr\themes\handsome\post.php
网址根目录\usr\themes\handsome\function.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">
    <!--related=6指最多显示6篇-->
    <?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> 
<br >

热门文章推荐

在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 >

## 最新文章

        <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
            <!--pageSize=6指最多显示6篇-->
            $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> 

参考样式

       <!--相关文章推荐 + 热门文章推荐-->
       <div class="smallscreen ellipsis" style="display:flex;padding-left:2px;"> 
        <!--相关文章推荐-->
            <div div class="tab-content ellipsis smallscreen" style="width:50%;flex:1;margin-right:1px">
            <!--<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>
            <br >
         
       <!--热门文章推荐-->
            <div div class="tab-content ellipsis smallscreen" style="width:50%;flex:1;margin-right:1px">
            <!--<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 myart ellipsis" style="width:100%">
            <li> <?php getHotComments('6');?>  </li>
            </ul>
            </div>
            </div> 
            <br >
        </div> 
        <br >
           
       <!--最新文章推荐-->
            <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> 

参考网址:
https://www.52txr.cn/2022/relatedLinks.html



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