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的soho人需要注意的事项

使用WordPress自建网站的SOHO人士需要注意以下几个关键事项,可以确保他们的WordPress网站能够稳定运行,同时为用户提供良好的体验。

WordPress外贸网站建设的成功因素与技术点

  在竞争激烈的网络环境中,打造一家成功的外贸网站需要精心规划和技术实力。本文将揭晓一些成功建站的秘籍,重点聚… Continue reading WordPress外贸网站建设的成功因素与技术点

把页面内容从wordpress的搜索结果中去掉

把wordpress的页面内容从搜索结果中移除的时候,除了使用插件以外,还可以使用非插件的方法,用一段代码就可以实现。

KJD独立站与DTC独立站的区别

KJD独立站和DTC独立站都强调品牌自主性和独立运营,但KJD独立站更注重品牌出海和多渠道营销,而DTC独立站更侧重于与消费者建立直接联系和互动,提升品牌忠诚度。

为wordpress后台添加一个自定义页面

给wordpress后台添加一个自定义页面,一个所有用户可见,一个只有编辑权限的用户可见。

独立站正在为中国产品热销海外贡献巨大力量

独立站作为一种新兴的跨境电商模式,具有许多优势,使其成为中国企业品牌出海的重要渠道。