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外贸建站须知

在广东进行WordPress外贸建站时,需要注意以下几个关键点: 选择合适的主题和插件:WordPress提供… Continue reading 广东wordpress外贸建站须知

用wordpress建外贸网站的优势

使用简站WordPress主题建立外贸网站具有许多优势,如出色的SEO优化功能、良好的用户体验、高度的安全性和灵活性等。这些优势可以帮助外贸企业更好地展示品牌形象、提高产品知名度,并吸引更多的潜在客户。因此,对于需要建立外贸网站的企业来说,简站WordPress主题是一个值得考虑的优秀解决方案。

WordPress外贸建站优化新技巧 提升网站性能

  在外贸业务中,一个高性能的网站对于吸引国际客户和提升用户体验至关重要。本文将介绍一些最新的WordPres… Continue reading WordPress外贸建站优化新技巧 提升网站性能

歪猫建站公司有哪些优势

歪猫建站(WaimaoYes)是一家专业的外贸建站公司,通过提供全方位的服务和先进的技术支持,帮助外贸企业提升品牌形象和市场竞争力。

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

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

什么样的人不适合用wordpress模板建站?

上一篇写了什么样的网站不适合使用WordPress?今天再写一个什么样的人不适合使用wordpress搭建网站。