zblog侧栏热门文章模板
时间 : 2024-01-07 06:25:02声明: : 文章内容来自网络,不保证准确性,请自行甄别信息有效性

最佳答案
Zblog侧栏热门文章模板:
<div class="sidebar-widget">
<h3 class="widget-title">热门文章</h3>
<ul class="widget-list">
<?php
$limit = 5; // 设定显示的文章数量
$hot_posts = $zbp->GetArticleList('*', array(array('=', 'log_Status', 0)), array('log_ViewNums' => 'DESC'), $limit, null);
foreach ($hot_posts as $hot_post) {
echo '<li><a href="' . $hot_post->Url . '">' . $hot_post->Title . '</a></li>';
}
?>
</ul>
</div>
此模板是一个简单的Zblog侧栏热门文章模板。它会显示最热门的5篇文章标题,并提供链接到各自的文章页面。
要使用此模板,您需要将上述代码复制并粘贴到Zblog的侧栏插件中,或者将其添加到您的主题的侧栏模板文件中。
请注意,此模板需要在Zblog中正确配置数据库连接和相关设置,并确保数据库中有合适的文章数据。
您可以根据需要自定义此模板,例如更改显示的文章数量、修改链接样式或添加其他功能。
其他答案
/* 热门文章模板 */
<div class="sidebar-widget">
<h3 class="widget-title">热门文章</h3>
<ul class="popular-posts">
<?php
$args = array(
'posts_per_page' => 5,
'orderby' => 'meta_value_num',
'meta_key' => 'post_views_count',
'order' => 'DESC',
);
$popular_posts = new WP_Query($args);
if ($popular_posts->have_posts()) {
while ($popular_posts->have_posts()) {
$popular_posts->the_post();
?>
<li class="popular-post">
<div class="post-thumbnail">
<?php the_post_thumbnail('thumbnail'); ?>
</div>
<div class="post-details">
<h4 class="post-title">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h4>
<div class="post-meta">
<span class="post-date"><?php echo get_the_date(); ?></span>
<span class="post-views"><?php echo get_post_meta(get_the_ID(), 'post_views_count', true); ?> 浏览</span>
</div>
</div>
</li>
<?php
}
}
wp_reset_postdata();
?>
</ul>
</div>
/* CSS样式 */
.sidebar-widget {
margin-bottom: 20px;
}
.widget-title {
font-size: 18px;
font-weight: bold;
margin-bottom: 10px;
}
.popular-post {
display: flex;
margin-bottom: 15px;
}
.post-thumbnail {
flex-basis: 30%;
}
.post-thumbnail img {
width: 100%;
height: auto;
}
.post-details {
flex-basis: 70%;
padding-left: 10px;
}
.post-title {
margin-bottom: 5px;
}
.post-title a {
text-decoration: none;
color: #333;
font-weight: bold;
}
.post-meta {
font-size: 14px;
}
.post-date, .post-views {
margin-right: 15px;
}
.post-views:after {
content: '浏览';
}
https/SSL证书广告优选IDC>>
推荐主题模板更多>>
推荐文章