1
我在WordPress中创建了一个登陆页面(一个页面有很多节),并且我使用get_template_part()调用每个节。所以我有这样的事情;Wordpress在不同的页面上显示帖子
<?php get_template_part('content', 'reasons-to-purchase'); ?>
<?php get_template_part('content', 'testimonials'); ?>
<?php get_template_part('content', 'reasons-to-purchase'); ?>
然后,每个内容文件具有一个循环返回匹配它的类别,该职位,posts_per_page设置为一个,如下所示(内容 - 原因对purchase.php);
<?php
$args = array(
'post_type' => 'section',
'category_name' => 'Reasons-To-Purchase',
'posts_per_page' => 1,
'orderby' => 'date',
'order' => 'DESC'
);
$the_query = new WP_Query ($args);
if (get_category_by_slug('Reasons-To-Purchase')->category_count > 0) {?>
<!-- Featured content image or slider. -->
<div class="container panel">
<?php if (have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?>
<?php the_content(); ?>
</div>
<?php } ?>
<?php wp_reset_query(); ?> <div class="clearfix"></div>
我想是创造尽可能多的,因为这些部分在曾经为了我喜欢的,每个部分内环路拉分配给该类别中的下一个职位。因此,例如在第一个'购买原因'部分,第一个职位被拉,然后在第二个'购买原因'第二个职位被称为。目前我使用'wp_reset_query()'重置每个文件中的循环,所以它不会干扰下一个可能不同的部分。基本上循环必须继续为下一个类似的命名部分没有重复任何帖子..
任何想法如何做到这一点或建议将不胜感激。
您的问题似乎并不清楚,请编辑和b它还包括相关的代码 –
现在已经做好了,希望所有必要的信息都在那里。 – Naz