傻大憨

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

模板页是一个卖成品网站模板的平台

模板页mobanye.com是一个为企业用户提供高效、便捷、低成本建站解决方案的优质平台,无论是个人博客还是企业官网,都能在这里找到合适的模板资源。

网络建站模板资源网站

这些网站各有特色,用户可以根据自己的需求选择合适的资源进行网站搭建。无论是追求美观设计、SEO优化,还是个性化定制,都能在这些平台上找到满意的解决方案。

外贸老板用wordpress搭建独立站 需要懂哪些技术

越来越多的外贸老板,自己买wordpress模板,自己搭建外贸独立站。作为外贸老板,想要使用WordPress自己搭建独立站,需要了解一些基本的网站技术和概念。

wordpress外贸建站2B或2C如何选

wordpress外贸建站,就是外贸公司用免费开源好用的wordpress系统,为自己的公司搭建一个网站。因页… Continue reading wordpress外贸建站2B或2C如何选

买wordpress主题是否要看支持不支持Elementor

先搞清楚Elementor是什么非常重要,没搞清楚前,不要盲目瞎跟风。

The best independent website building platform for foreign trade

The best template website building platform