SOHO创业

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 SOHO

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

WordPress子页面page调用父页面标题

在需要调用的页面,添加以下代码就可以现实子页面调用父页面的标题。

wordpress调用全站随机文章

wordpress调用全站随机文章代码

WordPress外贸建站服务的成功实例分享

  在竞争激烈的外贸市场,提升用户满意度是建立和维护成功外贸网站的关键。本文将分享一些成功的WordPress… Continue reading WordPress外贸建站服务的成功实例分享

用wordpresss搭建外贸网站非常简单

2020年以来,以国内大循环为主体、国内国际双循环相互促进的新发展格局已经建立。我国的优秀企业,要想生存发展的更好,搭建外贸网站出海,已经是关系到生死存亡的必选项了。

把WordPress网站文章时间格式改为“几分钟前”

刚才访问一个网站时,发现这个网站文章发布时间并不是直接显示为具体时间,而是显示为“几分钟前”,大半夜的,不可能那么多文章都是几分钟前发布的,于是找了一下相关的教程,发现要实现这个挺简单的。

WordPress主题中添加自定义Owl Carousel轮播

首先,您需要在WordPress主题中安装Owl Carousel组件。可以通过WordPress主题文件目录安装Owl Carousel。