こんにちは
テンプレートファイルをどのように配置しているかにもよりますが、例えば
index.php
<?php
$count = 30;
if( have_posts() ){
foreach($posts as $key=>$post){
setup_postdata($post);
echo $key;
the_title();
}
//追加分
if($key < $count ){
for($i=$key;$i<$count;$i++){
echo $i;
}
}
}
wp_reset_postdata( );
?>
不足分を、追加するようにしてみてはどうですか?
ありがとうございます。
twentytenを元にカスタマイズしています。
loopに渡して記事を生成してます。
<?php
query_posts('cat=-4&offset=10&showposts=10');
get_template_part( 'loop', 'index' );
wp_reset_query();
?>
といった感じで3列を10件ずつ表示してます。
loop側はこんな感じです。
<div class="entry-content <?php if ( is_category() || is_single() ) { ?><?php $cat = get_the_category(); $cat = $cat[0]; { echo $cat -> category_nicename; } ?><?php } ?>">
<!-- .追加サムネ -->
<?php the_post_thumbnail('my_thumbnail'); ?>
<div class="new_wrap02">
<div class="inbox clerfix <?php echo $cat = get_the_category();
echo $cat[0]->name; ?>">
<h2 class="entry-title"><a>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></h2>
<p><?php echo mb_substr(get_the_excerpt(), 0, 36);//抜粋の文字数を設定 ?>
Read More…</p>
<p class="entry-meta">
<?php twentyten_posted_on(); ?>
</p><!-- .entry-meta -->
</div>
</div>
<!--// .追加サムネ -->
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
indexで試したところ10件×$count = 30;みたいなことだったので
loopに挟んだところエラーになってしまいました。
ご教授いただけると助かります。
すみません。当方PHPなど素人で。。
よろしくお願いします。
こんにちは、
indexで試したところ10件×$count = 30;みたいなことだったので
loopに挟んだところエラーになってしまいました。
恐縮ですが、エラーになった場合は、どのようなエラーが発生しているのか、明示いただけると、修正等がしやすくなりますので、明示を心がけていただけるとうれしいです。
twentyetenを使って、コードが正常に表示できるか試してみました。
loop-index.phpを作成
<!--start loop-index--><?php
$count = 10;
query_posts('showposts='.$count);
if( have_posts() ){
foreach($posts as $key=>$post){
setup_postdata($post);
echo $key;
the_title();
}
//追加分
$key = $key + 1;
if($key < $count ){
for($i=$key;$i<$count;$i++){
echo $i;
}
}
}
wp_reset_postdata( );
wp_reset_query();
?><!--//end loop-index-->
cont96さんの、index.phpのクエリを、コメントアウトしてください
<?php
//query_posts('cat=-4&offset=10&showposts=10');
get_template_part( 'loop', 'index' );
//wp_reset_query();
?>
category.php archive.php など、必要箇所で
/* Run the loop for the category page to output the posts.
* If you want to overload this in a child theme then include a file
* called loop-category.php and that will be used instead.
*/
get_template_part( 'loop', 'index' ); //categoryをindexに変更
してみましたが、特にエラーは、再現できませんでした。