我做了一个循环,它正在加载post类型。但是,虽然它正在加载基本的帖子和帖子类型,但它并没有加载页面的主要内容。我正在寻找一种在加载帖子类型时加载当前页面内容的方法。
我该怎么做?
global $wp_query;
$args = array_merge( $wp_query->query, array( \'post_type\' => array(\'post\',\'Projets\'), \'posts_per_page\' => 3, ) );
if ( query_posts($args) ) :
while ( have_posts() ) : the_post();
get_template_part( \'template-parts/content\', \'content\' )
endwhile;
else :
get_template_part( \'template-parts/none\', \'none\' );
endif;
SO网友:Yagayente
好的,这样解决:
<?php
$mainquery = get_queried_object();
$args = array(
\'pagename\' => \'Accueil\' //as my home page
);
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
?>
<div class="entry-content">
<?php
the_content(); // here I can load my content
?>
</div><br><br>
<?php
}
}
wp_reset_postdata();
global $wp_query;
$args = array_merge($wp_query->query, array(
\'post_type\' => array(
\'post\',
\'Projets\'
),
\'posts_per_page\' => 3
));
if (query_posts($args)):
while (have_posts()):
the_post();
get_template_part(\'template-parts/content\', \'content\');
endwhile;
else:
get_template_part(\'template-parts/none\', \'none\');
endif;
?>