傻大憨

wordpress调用指定栏目下的tag标签相关文章列表

<?php
global $post;
$post_tags = wp_get_post_tags($post->ID);
if ($post_tags) {
foreach ($post_tags as $tag) {
// 获取标签列表
$tag_list[] .= $tag->term_id;
}
$cat = get_the_category();
foreach($cat as $key=>$category){
$catid = $category->term_id;
}
// 随机获取标签列表中的一个标签
$post_tag = $tag_list[ mt_rand(0, count($tag_list) - 1) ];

// 该方法使用 query_posts() 函数来调用相关文章,以下是参数列表
$args = array(
'tag__in' => array($post_tag),
'cat' => $catid,  // 不包括的分类ID
'post__not_in' => array($post->ID),
'showposts' => 6,                           // 显示相关文章数量
'caller_get_posts' => 1
);
query_posts($args);

if (have_posts()) {
while (have_posts()) {
the_post(); update_post_caches($posts); ?>
<div id="post-<?php the_ID(); ?>" class="col-md-4 mb-4">
<div class="portfolio">
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">

<div class="image">
<img src='<?php if ( has_post_thumbnail() ) { ?>
<?php
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
echo $large_image_url[0];
?>
<?php } else {?>
<?php bloginfo('template_url'); ?>/images/noneimg-portfolio.png
<?php } ?>' class='' alt='<?php the_title(); ?>'>
<div class="hover-effect">
<div class="hover-effect-inn"></div>
</div>
</div>
<h1><?php the_title(); ?></h1>

<p><?php the_excerpt(); ?></p>




</a>

</div>
</div>
<?php
}
}
else {
echo '<li>* 暂无相关文章</li>';
}
wp_reset_query();
}
else {
echo '<li>* 暂无相关文章</li>';
}
?>

这是wordpress模板制作中常会用到的一段代码

Published
Categorized as 建站知识 Tagged

By 傻大憨

shadahan.com是一个关注跨境电商、创业话题的网站。

推荐3个建网站的模板平台

可以免费下载网站模板的网站

预算1000元左右 wordpress模板建站是明智选择

千元预算建站:为什么WordPress模板是你的唯一明智选择 对于中小企业主和创业者来说,”网站建… Continue reading 预算1000元左右 wordpress模板建站是明智选择

外贸SOHO建网站怎么购买域名和主机

选择主机服务商时,要特别注意其客服响应时间和值班时间,确保在遇到问题时能够及时得到帮助。

WordPress外贸网站建设的最佳实践

  在当今数字化的商业环境中,WordPress成为了许多外贸企业建设网站的首选平台之一。本文将深入解读一些成… Continue reading WordPress外贸网站建设的最佳实践

河北燕子丹网络营销

河北燕子丹网络营销是一家专注于为企业提供全方位网络营销解决方案的专业服务公司。成立于2018,总部位于河北省保定市,致力于帮助企业在数字化时代提升品牌知名度、扩大市场份额、实现业务增长。

挑选适合你业务的建站引擎

  在选择外贸建站程序时,挑选适合你业务需求的建站引擎是至关重要的一步。本文将为您提供一份全面的选购指南,帮助… Continue reading 挑选适合你业务的建站引擎