こんにちは、私はこの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 to wpデータベースに基づいて2番目のループは完全に実行可能です 出力は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。試してみます。それは単に正しいので。お知らせします。本当にありがとう! –
問題ないですが、それがあなたのために働く場合、答えとしてこれをチェックしてください。 –