• 締切済み

WP タクソノミー前後の記事リンクについて

お客様の声:タクソンミー名(voice) ようにarchive-voice.phpを作りました。 記事の中身表示はsingle.phpはつくらず、ブログ用のindex.phpと共通にしました。 ブログ用のindex.phpには ↓↓↓↓ <!--内容の出力--> <?php if(is_home() || is_category() || is_archive()): ?> <div class="kiji"> <?php if(have_posts()): while(have_posts()): the_post(); ?> <div class="kiji-box"> <p class="catch-taitle"><span class="styledeco"><?php the_category(','); ?></span></p> <!-- アイキャッチ画像設置 --> <?php if (has_post_thumbnail()): ?> <?php the_post_thumbnail('medium'); ?> <?php else: ?> <?php echo '<img src="'.get_template_directory_uri().'/img/noimage.gif" alt="noimage" />'; ?> <?php endif; ?> <h2><a class="linktitle" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <p><?php echo mb_substr(get_the_excerpt(), 0, 120); ?><a class="linkleft" href="<?php the_permalink(); ?>">続きを読む</a>]</p> <div class="postinfo"><?php echo get_the_date(); ?>(<?php the_time(); ?>)<?php edit_post_link(' Edit',' |',''); ?></div> </div> <?php endwhile; endif; ?> </div> <?php else: ?> <!--フロントページ、アーカイブ、カテゴリ--> <!--単独ページ--> <?php if(have_posts()): while(have_posts()): the_post(); ?> <h2 class="blog-title"><?php the_title(); ?></h2> <div class="postinfo"><?php echo get_the_date(); ?>(<?php the_time(); ?>) | カテゴリー:<?php the_category(','); ?><?php edit_post_link(' Edit',' |',''); ?></div> <div class="blog_img"><?php if (has_post_thumbnail()): ?> <?php the_post_thumbnail('full'); ?> <?php endif; ?></div> <?php the_content(); ?> <?php endwhile; endif; ?> <?php endif; ?> <!--内容の出力ここまで--> <!--ページ送り--> <?php if (function_exists("pagination")) {pagination($additional_loop->max_num_pages); } ?> <!--個別の記事のページ送り--> <div id="pagelink"> <?php if(is_single()): ?> <p class="cell1"><?php previous_post_link('←%link', '%title', true, ''); ?></p> <p class="cell2"><?php next_post_link('%link→', '%title', true, ''); ?></p> <?php endif; ?> これだと、お客様の声のページに 記事の前後のリンクが表示されません。 <?php previous_post_link('« %link', '前の記事', TRUE, '', 'voice'); ?> <?php next_post_link('%link »', '次の記事', TRUE, '', 'voice'); ?> としてみたのですが、やはり表示されませんでした。 お客様の声とブログを共通にしているから表示されないのでしょうか・・・?

  • u2122
  • お礼率71% (125/176)
  • PHP
  • 回答数2
  • ありがとう数1

みんなの回答

  • garo1970
  • ベストアンサー率52% (54/103)
回答No.2

回答No1です。 よく考えたらアーカイブページに対して 「前の記事」「後の記事」っておかしいですね。 個別ページには「前の記事」「後の記事」はありますが、 アーカイブの場合は「前の記事」「後の記事」は存在しないので、 「<!--ページ送り-->」しか適用できないかと思います。

u2122
質問者

お礼

なるほど。了解しました。 でも前後の記事を表示させたいので、何か他の手段を考えてみます。 ご相談にのっていただき誠にありがとうございました。

  • garo1970
  • ベストアンサー率52% (54/103)
回答No.1

詳しく読んではいませんが、 最後から4行目のif文でis_single()と判定していますね? 「個別ページだったらページ送りを表示」 となっているわけですが、 この表示するつもりのページはアーカイブですよね? だから表示してくれないのでは? if文の判定をis_archive()なり、 ソースの2行目の判定文 if(is_home() || is_category() || is_archive()) をそのまま使うなりすればいいのでは?と思いました。

u2122
質問者

補足

ありがとうございます! 確かに!!!っと思って早速書き直してみたのですが まったく表示されず・・・? 試しにif文をとってみたのですが やはり表示されませんでした。 他にどこか間違っているところありますか

関連するQ&A

  • WordPressにおいて、サブカテゴリーに画像を表示させる。

    WordPressにおいて、サブカテゴリーに画像を表示させる。 WordPress,PHP初心者です。 現在 情報サイトを作っているのですが、 あるカテゴリーのループ中に、サブカテゴリーにも属していると、画像を表示させたいです。 ショッピングサイト等で例を言うと 「シャツ」という大カテゴリーをループを使って一覧で出力し、 その中で、サブカテゴリー「売り切れ」や「NEW」にチェックを入れていると(管理画面で) それに適した画像が表示されるようにしたいのです。 ”「売り切れ」と「NEW」にどちらも属している場合もあります” なおかつ、そのサブカテゴリーにチェックが入っていると 上位に表示されると一層良いのですが。 ループの中で、更にループ処理?という考えがあまり正しくないような気がするのですが、 試している所やはりうまくいきません。 ソースは下記の通りです。 <!--大カテゴリーのループ開始--> <?php query_posts("cat=3&showposts=10"); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="list-box"> <a href="<?php the_permalink() ?>"> <img src="<?php echo get_post_meta($post->ID,'faceimage',TRUE); ?>" alt="<?php the_title(); ?>" width="141" height="141" /> </a> <p class="name"><?php the_title(); ?></p> <p class="size"><?php echo get_post_meta($post->ID,'textfield',TRUE); ?></p> <!--売り切れの場合、画像表示--> <?php query_posts("cat=4"); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="ico-on"><img src="hogehoge" alt="売り切れ" /></div> <?php endwhile; ?> <?php endif; ?> <!--新着アイテムの場合、画像表示--> <?php query_posts("cat=6"); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="ico-new"><img src="hogehoge2" alt="新着アイテム" /></div> <?php endwhile; ?> <?php endif; ?> </div> <!--ループ完全に終了--> <?php endwhile; ?> <?php endif; ?> 調べてみたものの、行き詰まっています。 稚拙な質問ではございますが、 どうぞご教授お願い致します。

  • [wordpress] 固定ページで、カテゴリ名の

    [wordpress] 固定ページで、記事の一覧を表示し、その記事の属するカテゴリ名の表示 wordpressで、商品一覧ページを作成していて、一覧を表示するページは固定ページにしています。 その商品一覧の中で、記事(商品)の属するカテゴリ名を表示させたいのですが どうすればいいでしょうか? 商品が服なので、その商品が属するカテゴリを項目の一つとして出力したいのです。 つまり『抽出した商品毎(have_post()の出力結果)にカテゴリ名を抽出』という感じです。 具体的なソースも教えて頂けると助かります。 <?php the_category(); ?> はダメでした。 [参考ソース] <div id="collectionWrap" class="clearfix"> <?php $loop = new WP_Query( array( 'post_type' => 'collection', 'posts_per_page' => 8 ) ); while ( $loop->have_posts() ) : $loop->the_post(); ?> <div class="collection"> <div class="image"> <a href="<?php the_permalink() ?>"><?php echo wp_get_attachment_image(get_post_meta($post->ID,"画像",true),'medium' ); ?></a> </div> <div class="txt"> <div class="clearfix mb10"> <p class="upDate"><?php echo get_post_meta($post->ID,"性別",true); ?></p> <p class="seasons"> <span> /*ここにカテゴリの種類を出力 */ </span></p> </div> <p class="itemName"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></p> <p class="itemPrice">&yen;&nbsp;<?php echo get_post_meta($post->ID,"価格",true); ?></p> </div> </div> <?php endwhile; ?> <?php wp_reset_query(); ?> </div> どうかよろしく御願いします。足りない情報等あればおっしゃってください。 自分でもいろいろ調べてるのですが、わかりません。。急いでます。

    • ベストアンサー
    • PHP
  • Wordpressで特定カテゴリーの一覧ページ

    今特定のカテゴリーの一覧ページを作りたいのですがうまく作れません。 http://snapkidz.biz/wp/?cat=4(現状) 本当はhttp://blackartcard.com/?cat=4のような感じで作りたいんですがうまくいきません。 二つとも自分のサイトなのですが、http://blackartcard.com/?cat=4の方はテンプレートをいじって作ったので、うまくいっただけです。 アーカイブ.phpを同じ物をsnapkidz.bizにいれたのですがレイアウトがヘッダー部分に表示されるようになってしました。 アーカイブの中身は以下です。 <?php /** * @package WordPress * @subpackage Modularity */ ?> <?php get_header();?> <div> <?php query_posts($query_string.'&posts_per_page=2'); if (have_posts()) : ?> <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?> <div class="clear"></div> <div class="content"> <?php while (have_posts()) : the_post(); ?> <div class="archive-top"> <?php the_post_thumbnail('full'); ?> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf( esc_attr__( 'Permalink to %s', 'modularity' ), the_title_attribute( 'echo=0' ) ); ?>"><?php the_title() ?></a></h2> <div class="clear"></div> <p class="postmetadata alt quiet"> <?php $tag_list = get_the_tag_list( '| Tags: ', ', ' ); printf( __( '%1$s | Categories: %2$s %3$s | ', 'modularity' ), get_the_time( get_option( 'date_format' ) ), get_the_category_list( ', ' ), $tag_list ); ?> </p> <hr /> </div> <?php endwhile; ?> <div class="clear"></div> <div class="navigation"> <div class="alignleft"><?php next_posts_link( __( '&laquo; 前の記事', 'modularity' ) ); ?></div> <div class="alignright"><?php previous_posts_link( __( '次の記事 &raquo;', 'modularity' ) ) ?></div> </div> <div class="clear"></div> <?php else : ?> <h2 class="center"><?php _e( 'Not Found', 'modularity' ); ?></h2> <?php get_search_form(); ?> <?php endif; ?> </div> </div> </div> <!-- Begin Footer --> <?php get_footer(); ?> どうすればヘッダー下にうまく表示できるでしょうか?? 宜しくお願い致します。

    • 締切済み
    • CSS
  • カラム崩れが・・・

    トップページでは崩れてないのですが記事にはいると崩れてしまいます。 どうすれば治りますか?? ページ単体のphpは以下です。 ーーーーーーーーーーーーーーーーーーーーーーーーーー <?php get_header(); ?> <div id="column"> <?php if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?> <div class="post" id="post-<?php the_ID(); ?>"> <div class="content"> <div id="image"> <?php the_post_thumbnail(); ?> </div> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <?php the_title(); ?> </a></h2> <p> <?php the_content('Read the rest of this entry &raquo;'); ?> <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?> </p> <div class="clear"></div> <?php comments_template(); ?> <div class="clear"></div> <div id="tags"> <div id="toptags"></div> <span class="user"><?php the_author_posts_link('namefl'); ?> &raquo <?php the_time('d F, Y') ?> &raquo <?php the_category(', ') ?> <?php the_tags(' &raquo Tags:', ', ', '<br />'); ?> </span> </div> <div class="clear"></div> </div> </div> <?php endwhile; ?> <?php else : ?> <div class="post"> </div> <div class="content"> <h2>Page Not Found</h2> <p>Sorry, but you are looking for something that isn't here.</p> <h3>Search Blog</h3> <?php include(TEMPLATEPATH."/searchform.php"); ?> </div> </div> <?php endif; ?> <?php get_footer(); ?> ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー 他にも必要なphpがあれば言ってください。 宜しくお願い致します。

    • ベストアンサー
    • CSS
  • WordPress 最新記事をまとめてURLにする

    参考のURL https://www.buzzhook.co.jp/ 下の方に「BACKYARD BLOG」があります。 アイキャッチ画像、年月日、カテゴリー、タイトル、抜粋全てどれをクリックしてもURLへジャンプします。 HTMLソースは下記になります。 <li> <a herf="#"> . . . </a> </li> WordPressのトップページも同様にしたいのですが、PHPプログラムはまだ初心者なので、うまくいきませんでした。結果はアイキャッチのみURLでした。 どこが違うのでしょうか? 宜しくお願いします。 <!-- main --> <main> <!-- 最新記事リスト --> <ul> <li> <a href="<?php the_permalink(); ?>"> <?php query_posts('posts_per_page=5'); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <!-- アイキャッチ表示 --> <?php if (has_post_thumbnail()) : ?> <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a> <?php else : ?> <a href="<?php the_permalink(); ?>"><img src="<?php bloginfo('template_url'); ?>/img/noimage.gif" width="100" height="100" alt="デフォルト画像" /></a> <?php endif ; ?> <!-- カテゴリー表示 --> <?php echo get_the_category()[0]->name; ?> <!-- 抜粋 --> <?php echo get_the_excerpt(); ?> <span class="date"> <?php the_time('Y年n月j日'); ?> <?php $days=30; $today=date('U'); $entry=get_the_time('U'); $diff1=date('U',($today - $entry))/86400; if ($days > $diff1) { echo '<img src="images/new.gif" alt="New" />'; } ?> </span> </a> </li> <?php endwhile; endif; ?> <?php wp_reset_query(); ?> </ul> <!-- 最新記事リストここまで --> </main>

    • ベストアンサー
    • PHP
  • WordPress PCとスマホで表示を切り替える

    PCでは記事一覧5件、スマホでは3件表示するようにしたいです。 条件分岐タグを使って、PCとスマートフォンで記事の一覧表示を切り替える方法がうまくいきませんでした。 https://handywebdesign.net/2017/11/wp-is-mobile/ 改造前のコード(問題なく表示できました) <ul> <?php $latest_posts = get_posts( array( 'posts_per_page' => 5, // 表示する記事の数 'category_name' => '投稿ID',// 投稿IDを取得 'fields' => 'ids', ) ); foreach( $latest_posts as $post ): setup_postdata( $post ); if( has_post_thumbnail() ) { $post_thumb = get_the_post_thumbnail( '', 'post_thumbnail' ); // アイキャッチがあるときはアイキャッチを表示 } else { $post_thumb = '<img src="' . get_template_directory_uri() . '/img/noimage.gif" width="100" height="100" alt="デフォルト画像" />'; // アイキャッチがないときは《noimage.gif》を表示 } $post_categories = get_the_category(); // カテゴリーを取得 $post_content = wp_trim_words( get_the_content(), 30, '…' ); // 30字分を抜粋 ?> <li <?php post_class(); ?>> <a href="<?php the_permalink(); ?>"> <div class="blogListimg"> <?php echo wp_kses_post( $post_thumb ); ?> </div> <!-- アイキャッチここまで --> <p class="post-time blogDt"><?php the_time('Y.m.d'); ?></p> <p class="post-categories blogCt"><?php echo esc_html( $post_categories[0]->name ); ?></p> <h3 class="post-title"><?php the_title(); ?></h3> <p class="post-content blogBf"><?php echo esc_html( $post_content ); ?></p> </a> </li> <?php endforeach; wp_reset_postdata(); ?> </ul> PCとスマートフォンで記事の一覧表示を切り替えるコード 参考サイトを参考にfunctions.phpにfunction is_mobile() コードを追加。 トップページのphpに以下を改造。 <?php if ( is_mobile() ) : ?> <?php $latest_posts = get_posts( array( 'posts_per_page' => 5, // 表示する記事の数 'category_name' => '投稿ID',// 投稿IDを取得 'fields' => 'ids', ) ); foreach( $latest_posts as $post ): setup_postdata( $post );  ・  ・  ・ <?php else: ?> <?php $latest_posts = get_posts( array( 'posts_per_page' => 3, // 表示する記事の数 'category_name' => '投稿ID',// 投稿IDを取得 'fields' => 'ids', ) ); foreach( $latest_posts as $post ): setup_postdata( $post );  ・  ・  ・ <?php endforeach; wp_reset_postdata(); ?> </ul> 結果は真っ白になってしまいました。 HTMLソースも真っ白です。 空白はSublime Textのテキストエディターを使っていますので、確認しております。 どこが違うか、教えてくださいますか? よろしくおねがいします。

    • ベストアンサー
    • PHP
  • wordpressで特定の記事の本文だけを取り出す記述

    wordpressで特定の記事の本文だけを取り出す記述 超初心者です。 下記のようなwordpressの関数を使ったPHP文で「特定の記事の本文」のみを取り出したく いろんなwordpressのサンプルなどを参考にして作ってみました。 結果はまあ思い通りには出るのですが、 これって1つの記事を取り出すだけならスマートじゃないですよね・・・。 <?php query_posts('p=277'); ?> <?php if(have_posts()):while(have_posts()):the_post(); ?> <div><?php the_content(); ?></div> <?php endwhile;endif; ?> いまいちwhileなどのループなどがわかってないのですが、 よく考えれば1つの記事を抜き出すのにループを記述する必要があるのか? いろいろ試してみたのですが、エラーが頻出して挫折。 どうすればいいのかがわかんなくて質問させていただきました。 熟練された方はどういう記述にするのか参考にさせていただきたいです。

    • ベストアンサー
    • PHP
  • WordPressのtag.phpのループ回数

    WordPressでタグの一覧ページtag.phpを作成してループを読み込ませたのですが、10記事しか表示されません。ループ部分のコードは以下のとおりです。 <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div> <a href="<?php the_permalink();?>" title="<?php the_title_attribute(); ?>"><img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id() ); ?>" alt=""></a> <p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p> </div><!-- /.child-box --> <?php endwhile;?> <?php else:?> <?php endif;?> 該当する記事は40ほどあるのですが、違うタグで試してもやはり10記事しか表示されません。 色々と試したのですが原因がわかりません。ご教授いただけませんでしょうか。

    • ベストアンサー
    • PHP
  • headerをページによって表示、非表示にする

    トップページのみヘッダーのjavasprictを使い、他ページでは非表示にしたいのですが、header.phpをもう一つ作り(javaのタグが入ってないもの)別名で保存し、header.phpと同じデレクトリーに保存しページの<?php get_header(); ?>の部分を<?php get_header1(); ?>に変えたのですがエラーでした。 これはどうすれば別々に見る事ができるでしょうか?? 今のページ設定は以下になってます。 <?php get_header(); ?> <div class="span-24" id="contentwrap"> <div class="span-14"> <img src="http://pimpkidz.com/wp/wp-content/uploads/2011/08/side.jpg" /> <div id="content"> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div <?php post_class() ?> id="post-<?php the_ID(); ?>"> <div id="indexthumb"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_post_thumbnail(array( 200,200 ), array( 'class' => 'post_thumbnail' )); ?></a></div> <div id="indexcontent"> <h2 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <p class="postdate"><span><?php the_time('Y/n/j(D)') ?> </span></p> <div class="entry"> <?php echo excerpt(40); ?> <div class="readmorecontent"> <a class="readmore" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">Continue</a> </div> </div> </div> <div style="clear:both;"></div> </div><!--/post-<?php the_ID(); ?>--> <hr><?php endwhile; ?> <?php else : if ( is_category() ) { // If this is a category archive printf("<h2 class='pagetitle'>Sorry, but there aren't any posts in the %s category yet.</h2>", single_cat_title('',false)); } else if ( is_date() ) { // If this is a date archive echo("<h2 class='pagetitle'>Sorry, but there aren't any posts with this date.</h2>"); } else if ( is_author() ) { // If this is a category archive $userdata = get_userdatabylogin(get_query_var('author_name')); printf("<h2 class='pagetitle'>Sorry, but there aren't any posts by %s yet.</h2>", $userdata->display_name); } else { echo("<h2 class='pagetitle'>No posts found.</h2>"); } get_search_form(); endif; ?> </div> </div> <?php get_sidebars('right'); ?> </div> </div> <?php get_footer(); ?> もし他のソースが必要でしたら言ってください。宜しくお願い致します。

    • ベストアンサー
    • PHP
  • WordPress 条件分岐間違っている箇所は?

    WordPressで最新記事を判別して大きく見せるなど、表示を変更する条件分岐のカスタマイズ方法を下記のURLを参考に改造しました。 https://whitebear-seo.com/wordpress-newpost-conditional-branch/ 結果はエラーが出ました。 どこが間違っているか教えていただけないでしょうか? 宜しくお願いします。 <?php if ( have_posts() ) : if ( is_home() && ! is_front_page() ) : ?> <?php endif; /* 改造前 */ while ( have_posts() ) : the_post(); /* 改造前 */ get_template_part( 'template-parts/content', get_post_format() ); /* ページネーション */ endwhile; echo '<div class="text-center paging-navs">'; the_posts_pagination(); echo '</div>'; else : get_template_part( 'template-parts/content', 'none' ); /* ページネーション END */ endif; ?> /* 改造後 */の部分だけ改造しました。 ↓ <?php if ( have_posts() ) : if ( is_home() && ! is_front_page() ) : ?> <?php endif; /* 改造後 */ while ( have_posts() ) : the_post(); $counter++; if ($counter <= 1): ? get_template_part( 'template-parts/content2', get_post_format() ); else: /* 改造後 */ get_template_part( 'template-parts/content', get_post_format() ); /* ページネーション */ endwhile; echo '<div class="text-center paging-navs">'; the_posts_pagination(); echo '</div>'; else : get_template_part( 'template-parts/content', 'none' ); /* ページネーション END */ endif; ?>

    • 締切済み
    • PHP

専門家に質問してみよう