カテゴリ "food"のすべての投稿のアーカイブページを作成したいと思っています。 Category-food.phpというPHPファイルを作成してコードを追加しましたが、コードは正しく機能しませんでした。なぜコードを別のPHPファイルpage-food.phpに貼り付けるまで、困ったのですか?コードは、ページフードに取り組んだ。誰にもなぜこれが当てはまるのか、カテゴリ-food.phpでどのように動作するのかについての理由がありますか?カテゴリページでもっとボタンを押しても表示されない
*主な問題は、category-food.php my ajax load moreボタンがまったく表示されないということでした。しかし、page-food.phpでは、Ajaxの読み込みボタンが多く表示され、完全に機能しました。これは私がそのために使用していますプラグインです - https://wordpress.org/plugins/easy-load-more/
コード...
<?php
get_header();
get_template_part ('inc/carousel-food');
$the_query = new WP_Query(array(
'posts_per_page' => 3,
'paged' => get_query_var('paged', 1),
'cat' => 10,
));
if ($the_query->have_posts()) {
// display #ajax wrapper only if we have posts
echo '<div id="ajax"><div class="row">';
$i = 0;
while($the_query->have_posts()) {
$the_query->the_post(); ?>
<?php
if($i % 3 == 0) {
echo '</div><div class="row">';
}
?>
<div class="col-md-4">
<article <?php post_class(); ?> >
<?php the_post_thumbnail('medium-thumbnail'); ?>
<h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="post-excerpt"><?php echo get_the_excerpt(); ?></p>
<?php get_template_part('share-buttons'); ?>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php comments_popup_link ('No Comments', '1 Comment', '% Comments', 'comment-count', 'none'); ?>
</article>
</div>
<?php $i++; }//end while
echo '</div></div>'; // close the #ajax wrapper after the post list
if(get_query_var('paged') < $the_query->max_num_pages) {
load_more_button();
}
} else { // if there are no posts
echo '<p>Sorry, no posts matched your criteria.</p>';
}//end if
get_footer();
?>
が更新されたコード
<?php
get_header();
get_template_part ('inc/carousel-food');
global $wp_query;
$wp_query->set('posts_per_page', 3);
$wp_query->query($wp_query->query_vars);
$the_query = new WP_Query(array(
'posts_per_page' => 3,
'paged' => get_query_var('paged', 1),
'cat' => 10,
));
if ($the_query->have_posts()) {
// display #ajax wrapper only if we have posts
echo '<div id="ajax"><div class="row">';
$i = 0;
while($the_query->have_posts()) {
$the_query->the_post(); ?>
<?php
if($i % 3 == 0) {
echo '</div><div class="row">';
}
?>
<div class="col-md-4">
<article <?php post_class(); ?> >
<?php the_post_thumbnail('medium-thumbnail'); ?>
<h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="post-excerpt"><?php echo get_the_excerpt(); ?></p>
<?php get_template_part('share-buttons'); ?>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php comments_popup_link ('No Comments', '1 Comment', '% Comments', 'comment-count', 'none'); ?>
</article>
</div>
<?php $i++; }//end while
echo '</div></div>'; // close the #ajax wrapper after the post list
if(get_query_var('paged') < $the_query->max_num_pages) {
load_more_button();
}
} else { // if there are no posts
echo '<p>Sorry, no posts matched your criteria.</p>';
}//end if
get_footer();
?>
をあなたは私のために私のコードにそれを入れて気にしませんか?私はまだPHPで最高ではないと私はちょうどそれを追加しようとしたとき、私は間違った場所にそれを置くと思う私はエラーがあったため。 – user6738171
どのような種類のエラー?まだボタンはありませんか? – Grin
ページ上の唯一のものは私のヘッダーであり、私の質問には私が上に入れたコードを貼り付けた私のカルーセル(それはうんざりでした)でした。しかし、どういうわけか私があなたが間違った場所に示唆したコードを追加したことは確かです。 – user6738171