傻大憨

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

歪猫建站在业界口碑如何

歪猫建站在业界的口碑较好,得到了客户和行业的认可。如果您正在寻找一个专业的外贸建站服务提供商,歪猫建站是一个值得考虑的选择。

按分类调用标签 调用指定分类下的TAG

在制作wordpress主题时,有时候会用到按分类调用标签的时候,用上面的这一段代码就可以解决。

Jianzhanpress themes are the best Chinese WordPress themes to use

Jianzhanpress.com themes are the best Chinese WordPress themes to use

WordPress受海归人士欢迎的原因

随着全球化的深入发展,越来越多的海归人士选择回国发展,他们不仅带回了丰富的国际经验和资源,也对国内的互联网技术和应用产生了深远的影响。在众多建站平台中,WordPress凭借其独特的优势,受到了广大海归人士的青睐。

WordPress外贸建站的灵活功能应用

  在竞争激烈的外贸市场中,建立一个突出的品牌形象是成功的关键之一。通过WordPress外贸建站,您可以利用… Continue reading WordPress外贸建站的灵活功能应用

WordPress外贸建站 挑选最适合你业务的引擎

  在构建一个成功的外贸网站时,选择合适的建站平台是至关重要的一步。本文将深入解析WordPress外贸建站平… Continue reading WordPress外贸建站 挑选最适合你业务的引擎