傻大憨

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是一个关注跨境电商、创业话题的网站。

靠谱是对一个建网站公司的最好评价

靠谱是对一个建网站公司的最好评价,它不仅代表着公司的专业能力和服务质量,更体现了客户对其的信任和认可。

wordpress建站公司如何选择

选择一家合适的WordPress建站公司需要考虑多个方面,包括公司的背景和实力、需求和预算、技术实力和服务质量、设计师和开发人员的经验、合同和项目细节、网站的安全性和稳定性以及未来的扩展性和升级性等。

wordpress主题模板开发必须要掌握的知识点

CSS知识、HTML知识、PHP知识。

wordpress建站必备的函数大全

wordpress主题二次开发时常用到的函数

推荐10个外贸建站模板

一个好的外贸网站要看着美观,要运行稳定,要易于维护管理,因此,选择一个简洁实用的wordpress模板来建站至关重要。

自建外贸站群与租用外贸网站的比较分析

自建外贸站群和租用外贸网站各有优劣,适用于不同的业务场景和需求。在实际操作中,企业应根据自身的实际情况和需求,综合考虑成本、灵活性、定制性、品牌建设与推广以及风险与稳定性等因素,选择最适合自己的外贸网站策略。