傻大憨

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

歪猫独立站

歪猫独立站是一个专注于跨境电商独立站建设的平台,提供多种服务和资源,帮助跨境电商卖家搭建和运营自己的独立网站。

推荐10个外贸建站模板

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

通过PHPMyAdmin导入WP数据库文件的步骤

wordpress通过phpmyadmin导入数据库文件.sql的步骤与过程中发生的常见错误

我能否完全按照我的需求来设计wordpress网站

简站wordpress主题是我用过最简洁最好用的wordpress主题,简站主题的基础框架是固定的,呈现出来的东西,都在后台有对应修改的地方,使用起来非常方便。

WordPress外贸B2C建站主题推荐

在外贸B2C领域,一个独特而吸引人的网站设计对于吸引客户、提升用户体验至关重要。WordPress作为一个强大… Continue reading WordPress外贸B2C建站主题推荐

用wordpress搭建跨境电商独立站 成本低 效率高

跨境电商老板,为什么喜欢用wordpress搭建独立站。为什么说用wordpress搭建跨境电商独立站是成本最低效率最高的。