カテゴリー毎に作成(表示)した記事のページング
-
今回、初めてWordPressでページを制作するに当たりまして、カテゴリーページのページングをしたいと思ったのですが、ちょっとどうやって行っていいかわからず困っております。
<具体的には太字で書かれている部分が、ページングを実装したい部分です>
・親カテゴリー1の一覧ページ
⇒親カテゴリー1の下
・子カテゴリー:1-1の一覧ページ
・子カテゴリー:1-2の一覧ページ
・子カテゴリー:1-3の一覧ページ
・子カテゴリー:1-4の一覧ページ
・子カテゴリー:1-5の一覧ページ・親カテゴリー2の一覧ページ
⇒親カテゴリー2の下
・子カテゴリー:2-1の一覧ページ
・子カテゴリー:2-2の一覧ページ
・子カテゴリー:2-3の一覧ページ・親カテゴリー3の一覧ページ(サイトのお知らせ)
親カテゴリーで分けた一覧ページ と 親カテゴリーに所属する子カテゴリーで分けた一覧ページそれぞれにページングを付与することは可能でしょうか?
設計が難しいのでプラグインがもしかしたらうまくいかないかもという不安があって今回投稿しました。
補足要求があれば、そのつど対応致しますのでよろしくお願い致します。
(ここではない某場所で質問したら、冷たく突っ返されてしまったのでちょっと怖いですが・・・)
-
「ページング」というのは、下記リンク先のExampleのようなナビゲーションですか?
http://wordpress.org/extend/plugins/wp-pagenavi/umbrella_process様
おっしゃるとおりでございます。GoogleやYahooなどの下のほうで見かけるような形のナビゲーションのことです。
たぶん、リンク先のプラグインで大丈夫だと思いますが…。
ご質問を見る限りWordPressの普通の構成だと思いますが、
何か、親カテゴリーの場合と子カテゴリーの場合で違う点はありますか?ありがとう御座います!
今回の設計ですと、TOPページに表示するのは、親カテゴリー3の最新5件で、あとは選択されたカテゴリーによって表示が変化(ビジュアルと画像)するくらいですね。
案の定、不具合がおきてしまいました(T T)
メインのテンプレート(index.php)の中に
<?php if(in_category(‘7’)): ?>
<?php if(have_posts()): while(have_posts()): the_post(); ?>
…処理…
<?php endif; endwhile; ?>
<?php endif; ?><?php if(in_category(‘8’)): ?>
<?php if(have_posts()): while(have_posts()): the_post(); ?>
…処理…
<?php endif; endwhile; ?>
<?php endif; ?>という風に条件分岐を行って、wp-pagenaviプラグインを使用したところ、2ページ目以降が真っ白になってにっちもさっちも行かない状態です。
カテゴリによっては表示するレイアウトの変更もあったりします。
ほんとに2日間会社も休んで悩みあぐねて、このままではノイローゼにでもなりそうな感じなのですが、いかがすればいいのでしょう???
このプラグインに関しても質問があります。
このプラグインは、ifを混在させてしまうと、機能としては意味を成さなくなるのでしょうか?
(そうだとしたら、ちょっと問題ですが・・・)Webの記事にも該当するものは全く持ってないので、本当に本当に困って困っています。
もし、テンプレートを見たいと言うことでありましたら、遠慮なく公開いたします。
何卒よろしくお願いします。
あ~こんなところで足踏みはごめんです。助けて(泣)
2ページ目以降が真っ白に
自信はありませんが、 endif; と endwhile; の順番が逆だと思うので、1ページ目もエラーになってませんか?
<!-- ループ開始 --> <?php if(have_posts()): while(have_posts()): the_post(); ?> <!-- カテゴリーID7の分岐 --> <?php if(in_category('7')): ?> …処理… <!-- カテゴリーID8の分岐 --> <?php elseif(in_category('8')): ?> …処理… <!-- カテゴリー分岐終了 --> <?php endif; ?> <!-- ループ終了 --> <?php endwhile; endif; ?> <!-- ページナビ --> <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
こんな感じでどうでしょう。
ありがとうございます。
特にページングをつけない場合は、表示されています。
(特にエラーもないようです。)また、ページングをつけると2ページ目以降は条件分岐はすべて無視され、ifで指定した部分は真っ白になります。
googleなどでも、調べてみましたが、全く前例はないので、困っています。
試してはみたんですが結果変わらずです・・・・・
それとも今回はWordPressでページング(カテゴリー記事)はキレイさっぱりあきらめて、PHP直組みでつくり直したほうが、いいのでしょうか?
カテゴリー毎にテンプレートを用意するorアーカイブのテンプレートを用意するとかしたほうがいいのでしょうか?
愚痴みたいな書き方になって申し訳ないのですが、よろしくお願い致します。
因みに今日も会社も休んでいます(T T)
fumiyasac さん
はじめまして。
どれだけお役に立てるか分かりませんが、私もお手伝いしたいと思います。
ただ、トピックの説明だけでは問題を把握できている確信がありません。特に
<具体的には太字で書かれている部分が、ページングを実装したい部分です>
について、太字になっている箇所がなかったのでその箇所についても明記していただけますか?
私の解釈では、カテゴリー別アーカイブのテンプレートの中身をカテゴリー毎に分けたいと思いテンプレートを作成したがうまくいかず、さらにページングも機能していない、という問題なのですが正しいでしょうか?
もし可能であれば、現在のテンプレートの全容(公開に差し支えのある部分は省略して頂いて構いませんが、そこに問題が潜んでいる可能性もあります)と、ページングに使用しているプラグインを教えてください(WP-PageNavi 等)。
カテゴリー毎にテンプレートを用意するorアーカイブのテンプレートを用意するとかしたほうがいいのでしょうか?
その方が場合の切り分けができてすっきりすると思います。あと、カテゴリー別アーカイブのページ毎の条件分岐を、カテゴリー別ページ用のテンプレートを用意しないで行う場合は、 in_category() ではなく is_category() の方をお使いになるべきです。
また、ページングの処理がうまくいかない場合については、query_posts() を使用されておりかつ適切なパラメータを渡していない可能性が想像されますが、そういうことはありませんか?
mizube様
ありがとうございます。本当に今ノイローゼに近い状態で…とても嬉しいです。
太字になっている箇所は以下の部分です。
親カテゴリー1の一覧ページ(ページ+自作のページングで何とかクリア)・子カテゴリー:1-1の一覧ページ
・子カテゴリー:1-2の一覧ページ
・子カテゴリー:1-3の一覧ページ
・子カテゴリー:1-4の一覧ページ
・子カテゴリー:1-5の一覧ページ・親カテゴリー2の一覧ページ
・の部分はindex.phpでカテゴリーわけを行って作っているんですが、ページングをつけると2ページ目以降は条件分岐はすべて無視され、ifで指定した部分は真っ白になります。正しい書き方をしているのにページ送りにならないばかりか、ifの指定はすべて切られます。
(使用テンプレート)
「PHPファイル」
gallery.php (gallery.php)
gallery_ip.php (gallery_ip.php)
google_analytics.php (google_analytics.php)
meta_gallery.php (meta_gallery.php)
meta_gallery_html5.php (meta_gallery_html5.php)
meta_top.php (meta_top.php)
toppage.php (toppage.php)
twitter_badge.php (twitter_badge.php)
works.php (works.php)
サイドバー (sidebar.php)
フッター (footer.php)
ヘッダー (header.php)
ページテンプレート (page.php)
メインインデックスのテンプレート (index.php)←「今回はカテゴリーによって表記を分ける処理をここにすべて書いています。」
単一記事の投稿 (single.php)「スタイル」
スタイルシート (style.css)(使用PI)
WP-PageNavi
WP-Optimize現在の状態ではアーカイブテンプレートとカテゴリーのテンプレートがないので、すべてindex.phpに処理を書き、場合わけをしています。
今日は会社休んでいるので、何かあればすぐレスします。
>ページングの処理がうまくいかない場合については、query_posts() を使用されておりかつ適切なパラメータを渡していない可能性が想像されますが、そういうことはありませんか?
query_posts()を書いていませんでした。そもそもページングに必要だとはまったく思いませんでした。
(googleで調べてみましたが、該当しそうなものまったく見当たらず)しかし、どうやって書けばいいか皆目検討がつかず、混乱が混乱を招いて、もうぐっちゃぐちゃなんです(T T)
最悪、外注も視野に・・・とか悪い方向へ考えてしまう自分がいますが・・・
もう少し混乱してみますが、よろしくお願い致します。
(まだうまくいきません・・・もう嫌だー!!)
すみません、コードの貼り付けを、blockquote ではなくて code でお願いできますか?一部タグが削除されたりして、そのままだと元の形が復元できません。code は バッククォート(`)で挟みます。
しつれいしました。以下になります。
<?php /* Template Name:ブログページのテンプレート */ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" /> <title><?php bloginfo('name'); ?>|<?php if(in_category('3')): ?>Media - メディア/掲載等<?php endif; ?><?php if(in_category('4')): ?>Works - 制作実績紹介 [映画]<?php endif; ?><?php if(in_category('5')): ?>Information - 出演・受賞などのお知らせ一覧<?php endif; ?><?php if(in_category('6')): ?>Works - 制作実績紹介 [TV]<?php endif; ?><?php if(in_category('7')): ?>Works - 制作実績紹介 [出演]<?php endif; ?><?php if(in_category('8')): ?>Works - 制作実績紹介 [企画・プロデュース]<?php endif; ?><?php if(in_category('9')): ?>Works - 制作実績紹介 [WEB-CF]<?php endif; ?> <?php if(in_category('13')): ?>Works - 制作実績紹介 [イベント]<?php endif; ?><?php if(in_category('23')): ?>Works - 制作実績紹介 [講演・登壇]<?php endif; ?></title> <!-- META[Don't Delete]// --> <meta name="keywords" content="" /> <meta name="description" content="<?php bloginfo('description'); ?>" /> <meta name="robots" content="INDEX,FOLLOW" /> <meta name="copyright" content="Copyright © 2010 Shun Coney All Rights Reserved." /> <!--link rel="shortcut icon" type="image/x-icon" href="images/common/favicon.ico" /--> <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo('rss2_url'); ?>" /> <link rel="alternate" type="text/xml" title="RSS .92" href="<?php bloginfo('rss_url'); ?>" /> <link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="<?php bloginfo('atom_url'); ?>" /> <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" /> <!-- CSS[Don't Delete]// --> <link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/css/import.css" /> <link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/css/tweet.css" /> <!-- Javascript Default Adoptor// --> <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/css_browser_selector.js"></script> <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/swfobject.js"></script> <script type="text/javascript"> swfobject.embedSWF("ImageGallery.swf","flashcontent","960","330","9.0.0"); </script> <!--[if lte IE 6]> <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/DD_belatedPNG_0.0.8a.js"></script> <script type="text/javascript"> DD_belatedPNG.fix('img, #headerLogo'); </script> <![endif]--> <!-- Javascript Packages jQuery[Editable]// --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jQuery/fadeButton.js"></script> <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jQuery/jquery.twit.0.2.0.js"></script> <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jQuery/twitterAccount.js"></script> <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jQuery/ipadGallery.js"></script> <?php load_template(TEMPLATEPATH . '/google_analytics.php'); ?> </head> <body> <div id="wrapper"> <div id="container"> <?php load_template(TEMPLATEPATH . '/header.php'); ?> <!--div id="mainVisualPages"> メインビジュアル下層 </div--><!--//mainVisualPages end--> <div id="plistBoxPages"> <p class="magl10 magt10">">TOP >> <?php if(in_category('4')): ?>/works/">Works - 制作実績紹介 >> 映画 <?php endif; ?><?php if(in_category('5')): ?>Information - 出演・受賞などのお知らせ一覧<?php endif; ?><?php if(in_category('6')): ?>/works/">Works - 制作実績紹介 >> TV <?php endif; ?><?php if(in_category('7')): ?>/works/">Works - 制作実績紹介 >> 出演 <?php endif; ?><?php if(in_category('3')): ?>Media - メディア/掲載等 <?php endif; ?><?php if(in_category('8')): ?>/works/">Works - 制作実績紹介 >> 企画・プロデュース <?php endif; ?><?php if(in_category('9')): ?>/works/">Works - 制作実績紹介 >> WEB-CF <?php endif; ?><?php if(in_category('13')): ?>/works/">Works - 制作実績紹介 >> イベント <?php endif; ?><?php if(in_category('23')): ?>/works/">Works - 制作実績紹介 >> 講演・登壇 <?php endif; ?></p> </div><!--//mainVisualPages end--> <div id="contentsPages" class="clearfix"> <div id="leftPages" class="boxL"> <div class="magt10"> <?php if(in_category('5')): ?> <h3 id="leftTopInfo"><img src="<?php bloginfo('template_directory'); ?>/images/contents/h3_information.gif" alt="Information from this website [最新情報]" width="650" height="35" /></h3> <p id="galleryDescription" class="magl10 magt10"></p> <div class="magl10 magt10 magb10"> <img src="<?php bloginfo('template_directory'); ?>/images/common/informationSlide.jpg" alt="イメージテキスト" width="640" height="115" border="0" /> </div> <h5 class="magl10 magt20 magb20" style="font-size:14px; color:#333333!important;">【 これまでのお知らせ・最新情報の一覧 】</h5> <div class="magl10" style="border-bottom:dotted 1px #999;"></div> <?php endif; ?> <?php if(in_category('4')): ?> <h3 id="leftTopInfo"><img src="<?php bloginfo('template_directory'); ?>/images/contents/h3_work.gif" alt="Works [制作実績一覧]" width="650" height="35" /></h3> <h5 class="magl10 magt10" style="font-size:14px; color:#333333!important;"><span class="yellow">◆</span> 制作実績一覧:映画</h5> <p id="galleryDescription" class="magl10 magt10 magb20"></p> <div class="magl10" style="border-bottom:dotted 1px #999;"></div> <?php endif; ?> <?php if(in_category('7')): ?> <h3 id="leftTopInfo"><img src="<?php bloginfo('template_directory'); ?>/images/contents/h3_work.gif" alt="Works [制作実績一覧]" width="650" height="35" /></h3> <h5 class="magl10 magt10 magb20" style="font-size:14px; color:#333333!important;"><span class="green">◆</span> 制作実績一覧:出演</h5> <div class="magl10" style="border-bottom:dotted 1px #999;"></div> <?php endif; ?> <?php if(in_category('6')): ?> <h3 id="leftTopInfo"><img src="<?php bloginfo('template_directory'); ?>/images/contents/h3_work.gif" alt="Works [制作実績一覧]" width="650" height="35" /></h3> <!--div class="magl10 magt10 magb10"> <img src="<?php bloginfo('template_directory'); ?>/images/common/informationSlide.jpg" alt="イメージテキスト" width="640" height="115" border="0" /> </div--> <h5 class="magl10 magt10 magb20" style="font-size:14px; color:#333333!important;"><span class="red">◆</span> 制作実績一覧:TV</h5> <div class="magl10" style="border-bottom:dotted 1px #999;"></div> <?php endif; ?> <?php if(in_category('9')): ?> <h3 id="leftTopInfo"><img src="<?php bloginfo('template_directory'); ?>/images/contents/h3_work.gif" alt="Works [制作実績一覧]" width="650" height="35" /></h3> <h5 class="magl10 magt10 magb20" style="font-size:14px; color:#333333!important;"><span class="orange">◆</span> 制作実績一覧:WEB-CF</h5> <div class="magl10" style="border-bottom:dotted 1px #999;"></div> <?php endif; ?> <?php if(in_category('13')): ?> <h3 id="leftTopInfo"><img src="<?php bloginfo('template_directory'); ?>/images/contents/h3_work.gif" alt="Works [制作実績一覧]" width="650" height="35" /></h3> <h5 class="magl10 magt10 magb20" style="font-size:14px; color:#333333!important;"><span class="purple">◆</span> イベント</h5> <div class="magl10" style="border-bottom:dotted 1px #999;"></div> <?php endif; ?> <?php if(in_category('23')): ?> <h3 id="leftTopInfo"><img src="<?php bloginfo('template_directory'); ?>/images/contents/h3_work.gif" alt="Works [制作実績一覧]" width="650" height="35" /></h3> <h5 class="magl10 magt10 magb20" style="font-size:14px; color:#333333!important;"><span class="gunjo">◆</span> 講演・登壇</h5> <div class="magl10" style="border-bottom:dotted 1px #999;"></div> <?php endif; ?> <?php if(in_category('8')): ?> <h3 id="leftTopInfo"><img src="<?php bloginfo('template_directory'); ?>/images/contents/h3_work.gif" alt="Works [制作実績一覧]" width="650" height="35" /></h3> <h5 class="magl10 magt10 magb20" style="font-size:14px; color:#333333!important;"><span class="blue">◆</span> 制作実績一覧:企画・プロデュース</h5> <div class="magl10" style="border-bottom:dotted 1px #999;"></div> <?php endif; ?> <?php if(in_category('3')): ?> <h3 id="leftTopInfo"><img src="<?php bloginfo('template_directory'); ?>/images/contents/h3_media.gif" alt="Works [メディア/掲載等]" width="650" height="35" /></h3> <p id="galleryDescription" class="magl10 magt10 magb20">各メディア(TV・ラジオ等)への出演実績ならびにWebや出版物への掲載情報等を公開しております。</p> <!--div class="magl10 magt10 magb10"> <img src="<?php bloginfo('template_directory'); ?>/images/common/informationSlide.jpg" alt="イメージテキスト" width="640" height="115" border="0" /> </div--> <!--h5 class="magl10 magt10 magb20" style="font-size:14px; color:#333333!important;"><span class="red">◆</span> 制作実績一覧:TV</h5--> <div class="magl10" style="border-bottom:dotted 1px #999;"></div> <?php endif; ?> <?php if(in_category('5')): ?> <?php if(have_posts()): while(have_posts()): the_post(); ?> <div class="magl10 ListArea2"> <dl class="newsBlock magt10"> <dt><?php the_time('Y.m.d') ?></dt> <?php if ( get_post_meta($post->ID, '外部ページURL(カテゴリ:お知らせ・最新情報)') ) : ?> <dd>ID, '外部ページURL(カテゴリ:お知らせ・最新情報)',true); ?>" target="_blank"><?php the_title(); ?></dd> <?php endif; ?> <?php if ( !get_post_meta($post->ID, '外部ページURL(カテゴリ:お知らせ・最新情報)') ) : ?> <dd><?php the_title(); ?></dd> <?php endif; ?> </dl> </div> <?php endwhile; endif; ?> <?php endif; ?> <?php if(in_category('4')): ?> <?php if(have_posts()): while(have_posts()): the_post(); ?> <div class="magl10 ListArea2"> <h5 class="magt10"><span class="tag1-head">映画</span> "><?php the_title(); ?></h5> <div class="magt10 magb5"><?php the_content(); ?></div> </div> <?php endwhile; endif; ?> <?php endif; ?> <?php if(in_category('6')): ?> <?php if(have_posts()): while(have_posts()): the_post(); ?> <div class="magl10 ListArea2"> <h5 class="magt10"><span class="tag2-head">TV</span> <?php the_title(); ?></h5> <div class="magt10 magb5 clearfix"><?php the_content(); ?></div> </div> <?php endwhile; endif; ?> <?php endif; ?> <?php if(in_category('9')): ?> <?php if(have_posts()): while(have_posts()): the_post(); ?> <div class="magl10 ListArea2"> <h5 class="magt10"><span class="tag5-head">Web-CF</span> <?php the_title(); ?></h5> <div class="magt10 magb5 clearfix"><?php the_content(); ?></div> </div> <?php endwhile; endif; ?> <?php endif; ?> <?php if(in_category('13')): ?> <?php if(have_posts()): while(have_posts()): the_post(); ?> <div class="magl10 ListArea2"> <h5 class="magt10"><span class="tag7-head">イベント</span> <?php the_title(); ?></h5> <div class="magt10 magb5 clearfix"><?php the_content(); ?></div> </div> <?php endwhile; endif; ?> <?php endif; ?> <?php if(in_category('23')): ?> <?php if(have_posts()): while(have_posts()): the_post(); ?> <div class="magl10 ListArea2"> <h5 class="magt10"><span class="tag8-head">講演・登壇</span> <?php the_title(); ?></h5> <div class="magt10 magb5 clearfix"><?php the_content(); ?></div> </div> <?php endwhile; endif; ?> <?php endif; ?> <?php if(in_category('7')): ?> <?php if(have_posts()): while(have_posts()): the_post(); ?> <div class="magl10 ListArea2"> <h5 class="magt10"><span class="tag3-head">出演</span> <?php the_title(); ?></h5> <div class="magt10 magb5 clearfix"><?php the_content(); ?></div> <div style="height:10px;"></div> </div> <?php endwhile; endif; ?> <?php endif; ?> <?php if(in_category('8')): ?> <?php if(have_posts()): while(have_posts()): the_post(); ?> <div class="magl10 ListArea2"> <h5 class="magt10"><span class="tag4-head">企画・プロデュース</span> <?php the_title(); ?></h5> <div class="magt10 magb5 clearfix"><?php the_content(); ?></div> <div style="height:10px;"></div> </div> <?php endwhile; endif; ?> <?php endif; ?> <?php if(in_category('3')): ?> <?php if(have_posts()): while(have_posts()): the_post(); ?> <div class="magl10 ListArea2"> <h5 class="magt10"><span class="tag6-head">メディア・掲載等</span> <?php the_title(); ?></h5> <div class="magt10 magb5 clearfix"><?php the_content(); ?></div> <div style="height:10px;"></div> </div> <?php endwhile; endif; ?> <?php endif; ?> <div class="PagerArea magt20 magb20"><p></p></div> </div> </div><!--//leftPages end--> <div id="rightPages" class="boxR magl20"> <?php load_template(TEMPLATEPATH . '/sidebar.php'); ?> </div><!--//rightPages end--> </div><!--//contentsPages end--> <?php load_template(TEMPLATEPATH . '/footer.php'); ?> </div><!--//container end--> </div><!--//wrapper end--> <?php load_template(TEMPLATEPATH . '/twitter_badge.php'); ?> </body> </html>
- トピック「カテゴリー毎に作成(表示)した記事のページング」には新たに返信することはできません。