你好,我试图让这个wp_query循环的工作,但得到错误,虽然意想不到,虽然另一个类似的LOPP是罚款输出最近的新闻。请指教。第一个循环用于输出“新闻”类别的帖子。通过wp_Query输出帖子的麻烦
Parse error: syntax error, unexpected 'endwhile' (T_ENDWHILE)
add_shortcode('faq_all', 'FAQ_all_function');
function FAQ_all_function($atts) {
$query = new WP_Query(array(
'category_name' =>'FAQ',
'posts_per_page' => -1,
'order' => 'ASC',
'orderby' => 'title',
));
if ($query->have_posts()) { ob_start(); ?>
<div class="col-lg-12 col-xs-12 faq"><?php
while ($query->have_posts()) ; $query->the_post();
?>
<article><h5><a href="<?php the_permalink() ?>"> the_title() </a></h5>
<div class="post-text"> the_content() <br>
<div class="inner-height collapse" id="<?php the_ID() ?>"></div>
<div class="inner-height-long collapse" id="<?php the_ID() ?>"></div>
<button class="btn transparent" type="button" data-toggle="collapse" data-target="#<?php the_ID() ?>" aria-expanded="true" aria-controls="<?php the_ID() ?>"><i class="icon-chevron-down"></i>Открыть полность</button>
</div>
</article><?php
?>
</div> <?php
endwhile; ob_get_clean(); wp_reset_postdata();
}
}
这是正确输出常见问题类别的工作循环。你可以检查两个循环作为工作检查,但第二个基于wp-> query requset wp数据库是完全可行的 输出基于php文档的缓冲片段并打印出来。
add_shortcode('faq1', 'FAQ_function1');
function FAQ_function1($atts , $faq1) {
/*start buffering content with nulled variable t the start of the loop*/
$faq1=null;
$query = new WP_Query(array(
'category_name' =>'FAQ',
'posts_per_page' => -1,
'order' => 'ASC',
'cat' => '3',
'orderby' => 'title',
));
if ($query->have_posts()) { ob_start();
?>
<div class="col-lg-6 col-xs-12">
<?php while ($query->have_posts()) :static $counter = 0; $query->the_post();
$count = $query->post_count;
if ($counter > ($count/2)):
?>
<article>
<h5 href="<?php the_permalink(); ?>"><?php the_title(); ?></h5>
<div class="post-text"><?php the_content(); ?></div>
</article>
<?php endif;
$counter++;
endwhile; ?> </div> <?php return ob_get_clean();
/*start buffering content with nulled variable of the start of the loop. Finished with content - outputting. */
wp_reset_postdata(); ?>
<?php
}
也许这是一个错过brasket,但有眼痛,看是什么inorrect:
谢谢,Ali_k。我会尝试。因为它只是正确的。会让你知道。谢谢一堆! –
没问题,如果它适合你,请检查这个答案。 –