Title: eijiyの返信 - page 3 | WordPress.org 日本語

---

# eijiy

  [  ](https://ja.wordpress.org/support/users/eijiy/)

 *   [プロフィール](https://ja.wordpress.org/support/users/eijiy/)
 *   [作成したトピック](https://ja.wordpress.org/support/users/eijiy/topics/)
 *   [作成した返信](https://ja.wordpress.org/support/users/eijiy/replies/)
 *   [返信したトピック](https://ja.wordpress.org/support/users/eijiy/replied-to/)
 *   [エンゲージメント](https://ja.wordpress.org/support/users/eijiy/engagements/)
 *   [お気に入り](https://ja.wordpress.org/support/users/eijiy/favorites/)

 返信を検索

## フォーラムへの返信

15件の返信を表示中 - 31 - 45件目 (全102件中)

[←](https://ja.wordpress.org/support/users/eijiy/replies/page/2/?output_format=md)
[1](https://ja.wordpress.org/support/users/eijiy/replies/?output_format=md) [2](https://ja.wordpress.org/support/users/eijiy/replies/page/2/?output_format=md)
3 [4](https://ja.wordpress.org/support/users/eijiy/replies/page/4/?output_format=md)
[5](https://ja.wordpress.org/support/users/eijiy/replies/page/5/?output_format=md)
[6](https://ja.wordpress.org/support/users/eijiy/replies/page/6/?output_format=md)
[7](https://ja.wordpress.org/support/users/eijiy/replies/page/7/?output_format=md)
[→](https://ja.wordpress.org/support/users/eijiy/replies/page/4/?output_format=md)

 *   フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   返信が含まれるトピック: [PHPで条件分岐して、カテゴリーリストをecho($data)](https://ja.wordpress.org/support/topic/php%e3%81%a7%e6%9d%a1%e4%bb%b6%e5%88%86%e5%b2%90%e3%81%97%e3%81%a6%e3%80%81%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e3%83%aa%e3%82%b9%e3%83%88%e3%82%92echodata/)
 *  トピック投稿者 [eijiy](https://ja.wordpress.org/support/users/eijiy/)
 * (@eijiy)
 * [16年前](https://ja.wordpress.org/support/topic/php%e3%81%a7%e6%9d%a1%e4%bb%b6%e5%88%86%e5%b2%90%e3%81%97%e3%81%a6%e3%80%81%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e3%83%aa%e3%82%b9%e3%83%88%e3%82%92echodata/#post-132559)
 * nobitaさん、返信ありがとうございます。
 * header.phpやindex.phpは変化なし、それぞれ一行目に<?php require(‘./wp-load.php’);?
   >を入れてみました。test.phpに入れたら以下の様なエラーメッセージが表示されて、
   どこに入れていいのかサッパリ分らずギブアップです。
 * Warning: require(./wp-load.php) [function.require]: failed to open stream: No
   such file or directory in C:\xampp\htdocs2\wp\wp-content\themes\twentyten\test.
   php on line 1
 * Fatal error: require() [function.require]: Failed opening required ‘./wp-load.
   php’ (include_path=’.;C:\xampp\php\PEAR’) in C:\xampp\htdocs2\wp\wp-content\themes\
   twentyten\test.php on line 1
 * ご指導頂けないでしょうか。
 * 宜しくお願い致します。
 *   フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   返信が含まれるトピック: [PHPで条件分岐して、カテゴリーリストをecho($data)](https://ja.wordpress.org/support/topic/php%e3%81%a7%e6%9d%a1%e4%bb%b6%e5%88%86%e5%b2%90%e3%81%97%e3%81%a6%e3%80%81%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e3%83%aa%e3%82%b9%e3%83%88%e3%82%92echodata/)
 *  トピック投稿者 [eijiy](https://ja.wordpress.org/support/users/eijiy/)
 * (@eijiy)
 * [16年前](https://ja.wordpress.org/support/topic/php%e3%81%a7%e6%9d%a1%e4%bb%b6%e5%88%86%e5%b2%90%e3%81%97%e3%81%a6%e3%80%81%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e3%83%aa%e3%82%b9%e3%83%88%e3%82%92echodata/#post-132550)
 * 例えば、以下の様にして
 *     ```
       function test(){
           //load第2引数のデータを受け取ります
           $type = $_POST['type'];
           //typeが"cate"ならカテゴリーリストを返します
           if ($type=="cate") {
               $data = wp_list_categories('title_li=&depth=2&hierarchical=true&show_post_count=true&use_desc_for_title=0');
           } else {
               $data = date("Y/m/d H:i:s");
           }
           echo($data);
       }
       ```
   
 * `get_test()`
    と言う事ですか？、何分phpの理解度が低レベルなので間違っていたら
   ご指摘ください。
 * しかし、このプログラムの流れからするとどうなんでしょうか。
 * 流れ
    １．jQueryで、ボタンがクリックされたら#sidepanelにtest.phpをload ２．jQuery
   で、クリックされたボタンのid名を取得 ３．phpで、id名を受け取る ４．phpで、id名
   によって条件分岐してデータを変数$dataに代入してecho($data) ５．jQueryで、#sidepanel
   を一旦フェードアウトして、フェードイン
 *   フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   返信が含まれるトピック: [PHPで条件分岐して、カテゴリーリストをecho($data)](https://ja.wordpress.org/support/topic/php%e3%81%a7%e6%9d%a1%e4%bb%b6%e5%88%86%e5%b2%90%e3%81%97%e3%81%a6%e3%80%81%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e3%83%aa%e3%82%b9%e3%83%88%e3%82%92echodata/)
 *  トピック投稿者 [eijiy](https://ja.wordpress.org/support/users/eijiy/)
 * (@eijiy)
 * [16年前](https://ja.wordpress.org/support/topic/php%e3%81%a7%e6%9d%a1%e4%bb%b6%e5%88%86%e5%b2%90%e3%81%97%e3%81%a6%e3%80%81%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e3%83%aa%e3%82%b9%e3%83%88%e3%82%92echodata/#post-132544)
 * shokun0803さん、返信ありがとうございます。
 * 説明不足ですね、Ajaxで非同期通信です。
 * 以下にテスト中のコードを示します。
    html
 *     ```
       <div id="btn">
           <button id="cate">Category</button>
           <button id="date">Date</button>
       </div>
       <div id="sidepanel"></div>
       ```
   
 * jQuery
 *     ```
       jQuery(function(){
       	jQuery("button","#btn").click(function(){
       		jQuery("#sidepanel").load("/wp/wp-content/themes/twentyten/test.php",
       				{ type: this.id },
       				function(){
       					jQuery(this)
       					.fadeOut(100)
       					.fadeIn(1000);
       				});
       	});
       });
       ```
   
 * php
 *     ```
       <?php
       	//load第2引数のデータを受け取ります
       	$type = $_POST['type'];
       	//typeが"cate"ならカテゴリーリストを返します
       	if ($type=="cate") {
       		$data = wp_list_categories('title_li=&depth=2&hierarchical=true&show_post_count=true&use_desc_for_title=0');
       	} else {
       		$data = date("Y/m/d H:i:s");
       	}
       	echo($data);
       ?>
       ```
   
 * これを実行するとCategoryボタンをクリックした時に以下のエラーが表示されます。
 * Fatal error: Call to undefined function wp_list_categories() in C:\xampp\htdocs2\
   wp\wp-content\themes\twentyten\test.php on line 6
 * カテゴリーリストのタグは現在使っているものをそのまま使っているので間違ってない
   と思うのですが、エラー行はカテゴリーリストのタグのところです。
 *   フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   返信が含まれるトピック: [最新の投稿を一件のみ、タイトルとリンク、抜粋をヘッダーに表示](https://ja.wordpress.org/support/topic/%e6%9c%80%e6%96%b0%e3%81%ae%e6%8a%95%e7%a8%bf%e3%82%92%e4%b8%80%e4%bb%b6%e3%81%ae%e3%81%bf%e3%80%81%e3%82%bf%e3%82%a4%e3%83%88%e3%83%ab%e3%81%a8%e3%83%aa%e3%83%b3%e3%82%af%e3%80%81%e6%8a%9c%e7%b2%8b/)
 *  トピック投稿者 [eijiy](https://ja.wordpress.org/support/users/eijiy/)
 * (@eijiy)
 * [16年、 1ヶ月前](https://ja.wordpress.org/support/topic/%e6%9c%80%e6%96%b0%e3%81%ae%e6%8a%95%e7%a8%bf%e3%82%92%e4%b8%80%e4%bb%b6%e3%81%ae%e3%81%bf%e3%80%81%e3%82%bf%e3%82%a4%e3%83%88%e3%83%ab%e3%81%a8%e3%83%aa%e3%83%b3%e3%82%af%e3%80%81%e6%8a%9c%e7%b2%8b/#post-132399)
 * show555さん、返信ありがとうございます。
 * 勉強不足（反省！）です。
    setup_postdata($post);を使うんですね。
 * お陰でテストも成功して、実現できそうです。
 * ありがとうございました。
 *   フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   返信が含まれるトピック: [最新の投稿を一件のみ、タイトルとリンク、抜粋をヘッダーに表示](https://ja.wordpress.org/support/topic/%e6%9c%80%e6%96%b0%e3%81%ae%e6%8a%95%e7%a8%bf%e3%82%92%e4%b8%80%e4%bb%b6%e3%81%ae%e3%81%bf%e3%80%81%e3%82%bf%e3%82%a4%e3%83%88%e3%83%ab%e3%81%a8%e3%83%aa%e3%83%b3%e3%82%af%e3%80%81%e6%8a%9c%e7%b2%8b/)
 *  トピック投稿者 [eijiy](https://ja.wordpress.org/support/users/eijiy/)
 * (@eijiy)
 * [16年、 1ヶ月前](https://ja.wordpress.org/support/topic/%e6%9c%80%e6%96%b0%e3%81%ae%e6%8a%95%e7%a8%bf%e3%82%92%e4%b8%80%e4%bb%b6%e3%81%ae%e3%81%bf%e3%80%81%e3%82%bf%e3%82%a4%e3%83%88%e3%83%ab%e3%81%a8%e3%83%aa%e3%83%b3%e3%82%af%e3%80%81%e6%8a%9c%e7%b2%8b/#post-132396)
 * kvexさん、返信ありがとうございます。
 * そうです、そのコードで駄目です。
 * `<?php the_excerpt(); ?>`
    はループ外では使えないのでしょうか。
 * 以下のコードをヘッダーに入れると
 *     ```
       <br />
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?></p>
       <div class="post">
       <a href="<?php the_permalink(); ?>" rel="bookmark"><br />
       ■<?php the_title(); ?></a>-<br />
       <?php the_date(); ?>-<?php the_time(); ?><br />
       <?php the_category(); ?><br />
       <?php the_excerpt(); ?>
       </div>
       <p><?php endwhile; else : ?><br />
       <?php _e('sorry,no posts'); ?><br />
       <?php endif; ?>
       ```
   
 * 現在表示中のタイトル、リンク、投稿日時、カテゴリ、内容の抜粋が表示されます。
 * これを現在表示中の記事と関係なく、トップページを開いた時のみヘッダーに最新の投稿
   の一件を表示させるように変えられないものでしょうか。
 *   フォーラム: [プラグイン](https://ja.wordpress.org/support/forum/plugins/)
    
   返信が含まれるトピック: [wibiya toolbar がIEで表示されません。](https://ja.wordpress.org/support/topic/wibiya-toolbar-%e3%81%8cie%e3%81%a7%e8%a1%a8%e7%a4%ba%e3%81%95%e3%82%8c%e3%81%be%e3%81%9b%e3%82%93%e3%80%82/)
 *  トピック投稿者 [eijiy](https://ja.wordpress.org/support/users/eijiy/)
 * (@eijiy)
 * [16年、 2ヶ月前](https://ja.wordpress.org/support/topic/wibiya-toolbar-%e3%81%8cie%e3%81%a7%e8%a1%a8%e7%a4%ba%e3%81%95%e3%82%8c%e3%81%be%e3%81%9b%e3%82%93%e3%80%82/#post-131381)
 * takuyaさん、返信ありがとうございます。
 * 確認しようと努力はしてみましたが、私のレベルでは難しくて分りませんでした。
 * とりあえず関連のプラグインとjQueryを外してみましたが変化はありません。
 * 次、自作テーマを作る時に確認しながらやってみます。
 * twentytenを使いながら勉強していきますので、今回はこれで解決とさせてください。
 * ありがとうございました。
 *   フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   返信が含まれるトピック: [自作テーマをテスト環境から本サイトにアップしたらjQueryが全く機能しな](https://ja.wordpress.org/support/topic/%e8%87%aa%e4%bd%9c%e3%83%86%e3%83%bc%e3%83%9e%e3%82%92%e3%83%86%e3%82%b9%e3%83%88%e7%92%b0%e5%a2%83%e3%81%8b%e3%82%89%e6%9c%ac%e3%82%b5%e3%82%a4%e3%83%88%e3%81%ab%e3%82%a2%e3%83%83%e3%83%97%e3%81%97/)
 *  トピック投稿者 [eijiy](https://ja.wordpress.org/support/users/eijiy/)
 * (@eijiy)
 * [16年、 2ヶ月前](https://ja.wordpress.org/support/topic/%e8%87%aa%e4%bd%9c%e3%83%86%e3%83%bc%e3%83%9e%e3%82%92%e3%83%86%e3%82%b9%e3%83%88%e7%92%b0%e5%a2%83%e3%81%8b%e3%82%89%e6%9c%ac%e3%82%b5%e3%82%a4%e3%83%88%e3%81%ab%e3%82%a2%e3%83%83%e3%83%97%e3%81%97/#post-131005)
 * 自己解決です。
 * WordPressの場合は以下の様にするんですね。
 *     ```
       <?php wp_enqueue_script('all', get_bloginfo('template_url') . '/js/jQuery.all.js', array('jquery')); ?>
       <?php wp_head(); ?>
       ```
   
 * たった１行で複数のjQueryが利用でき、読み込み速度も体感で約２倍になった感じです。
 *   フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   返信が含まれるトピック: [自作テーマをテスト環境から本サイトにアップしたらjQueryが全く機能しな](https://ja.wordpress.org/support/topic/%e8%87%aa%e4%bd%9c%e3%83%86%e3%83%bc%e3%83%9e%e3%82%92%e3%83%86%e3%82%b9%e3%83%88%e7%92%b0%e5%a2%83%e3%81%8b%e3%82%89%e6%9c%ac%e3%82%b5%e3%82%a4%e3%83%88%e3%81%ab%e3%82%a2%e3%83%83%e3%83%97%e3%81%97/)
 *  トピック投稿者 [eijiy](https://ja.wordpress.org/support/users/eijiy/)
 * (@eijiy)
 * [16年、 2ヶ月前](https://ja.wordpress.org/support/topic/%e8%87%aa%e4%bd%9c%e3%83%86%e3%83%bc%e3%83%9e%e3%82%92%e3%83%86%e3%82%b9%e3%83%88%e7%92%b0%e5%a2%83%e3%81%8b%e3%82%89%e6%9c%ac%e3%82%b5%e3%82%a4%e3%83%88%e3%81%ab%e3%82%a2%e3%83%83%e3%83%97%e3%81%97/#post-131000)
 * 本番サイトではwp_headの下でjQueryを読み込まないといけない様で、とりあえずは解決
   しましたが、上記の方法のどこがいけないのか分りません。
 * どなたかご存知の方がおられましたらご教授頂けないでしょうか。
 * 宜しくお願い致します。
 *   フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   返信が含まれるトピック: [表示中の単一記事のカテゴリーIDとカテゴリー名の取得](https://ja.wordpress.org/support/topic/%e8%a1%a8%e7%a4%ba%e4%b8%ad%e3%81%ae%e5%8d%98%e4%b8%80%e8%a8%98%e4%ba%8b%e3%81%ae%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bcid%e3%81%a8%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e5%90%8d%e3%81%ae/)
 *  トピック投稿者 [eijiy](https://ja.wordpress.org/support/users/eijiy/)
 * (@eijiy)
 * [16年、 2ヶ月前](https://ja.wordpress.org/support/topic/%e8%a1%a8%e7%a4%ba%e4%b8%ad%e3%81%ae%e5%8d%98%e4%b8%80%e8%a8%98%e4%ba%8b%e3%81%ae%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bcid%e3%81%a8%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e5%90%8d%e3%81%ae/#post-130845)
 * mizubeさん、wp_reset_query()を追加する事で思い通りになりました。
 *     ```
       <?php
       if ( is_single() ) : wp_reset_query();
           $categories = get_the_category( $post->ID );
           // カテゴリー ID 順に並べ替える場合は下の行をアンコメント
           // if ( !empty( $categories ) ) usort( $categories, '_usort_terms_by_ID' );
           foreach ( $categories as $cnt => $cat ) :
       ?>
       	<div id="toggler-<?php echo $cnt+1; ?>" class="opened" title="<?php echo esc_attr( $cat->cat_name ); ?> の投稿一覧">
       		<div>
       			<ul>
       <?php
       //子孫が要る時
       //remove_filter( 'pre_option_category_children', 'my_category_children' );
       //子孫が要らない時
       add_filter( 'pre_option_category_children', 'my_category_children' );
       //
       $single_posts = get_posts( "numberposts=-1&category=$cat->cat_ID&order=asc" ); //$cat->term_idでもいい
               foreach ( $single_posts as $post ) :
       ?>
       				<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
       <?php
               endforeach; // single_posts
       ?>
       			</ul>
       		</div>
       	</div>
       <?php
           endforeach; // categories
       endif; // is_single
       ?>
       ```
   
 * ちょっと追加してますが、お陰で完成しました。
    ありがとうございました。
 * また機会があれば宜しくお願い致します。
 *   フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   返信が含まれるトピック: [表示中の単一記事のカテゴリーIDとカテゴリー名の取得](https://ja.wordpress.org/support/topic/%e8%a1%a8%e7%a4%ba%e4%b8%ad%e3%81%ae%e5%8d%98%e4%b8%80%e8%a8%98%e4%ba%8b%e3%81%ae%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bcid%e3%81%a8%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e5%90%8d%e3%81%ae/)
 *  トピック投稿者 [eijiy](https://ja.wordpress.org/support/users/eijiy/)
 * (@eijiy)
 * [16年、 2ヶ月前](https://ja.wordpress.org/support/topic/%e8%a1%a8%e7%a4%ba%e4%b8%ad%e3%81%ae%e5%8d%98%e4%b8%80%e8%a8%98%e4%ba%8b%e3%81%ae%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bcid%e3%81%a8%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e5%90%8d%e3%81%ae/#post-130841)
 * mizubeさんのコードで試した結果、どのカテゴリーに属する記事であっても親A,B,C,D
   カテゴリーの内、子カテゴリーを持たないカテゴリーDの名前と投稿一覧がされました。
 *   フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   返信が含まれるトピック: [表示中の単一記事のカテゴリーIDとカテゴリー名の取得](https://ja.wordpress.org/support/topic/%e8%a1%a8%e7%a4%ba%e4%b8%ad%e3%81%ae%e5%8d%98%e4%b8%80%e8%a8%98%e4%ba%8b%e3%81%ae%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bcid%e3%81%a8%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e5%90%8d%e3%81%ae/)
 *  トピック投稿者 [eijiy](https://ja.wordpress.org/support/users/eijiy/)
 * (@eijiy)
 * [16年、 2ヶ月前](https://ja.wordpress.org/support/topic/%e8%a1%a8%e7%a4%ba%e4%b8%ad%e3%81%ae%e5%8d%98%e4%b8%80%e8%a8%98%e4%ba%8b%e3%81%ae%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bcid%e3%81%a8%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e5%90%8d%e3%81%ae/#post-130840)
 * 以下のコードAとコードBを試している最中、不思議な事に両方とも記述するとコードB
   が思い通りに動き、コードAを外すとコードBが思い通りに動きません。
 * コードA
 *     ```
       <?php
       if ( is_single() ) :
           $categories = get_the_category( $post->ID );
           // カテゴリー ID 順に並べ替える場合は下の行をアンコメント
           // if ( !empty( $categories ) ) usort( $categories, '_usort_terms_by_ID' );
           foreach ( $categories as $cnt => $cat ) :
       ?>
       	<div id="toggler-<?php echo $cnt+1; ?>" class="closed" title="<?php echo esc_attr( $cat->name ); ?> の投稿一覧">
       		<div>
       			<ul>
       <?php
               $single_posts = get_posts( "numberposts=-1&category=$cat->term_ID&order=asc" );
               foreach ( $single_posts as $post ) :
       ?>
       				<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
       <?php
               endforeach; // single_posts
       ?>
       			</ul>
       		</div>
       	</div>
       <?php
           endforeach; // categories
       endif; // is_single
       ?>
       ```
   
 * コードB
 *     ```
       <?php if (is_single()) : ?>
       <ul>
       <?php
       $cat = get_the_category(); $cat = $cat[0];
       //子孫が要る時
       remove_filter( 'pre_option_category_children', 'my_category_children' );
       //子孫が要らない時
       //add_filter( 'pre_option_category_children', 'my_category_children' );
       //
       $myposts = get_posts('category='. $cat->cat_ID);
       //$myposts = get_posts('category='. $cat->category_parent);
       foreach($myposts as $post) :
       ?>
       <li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
       <?php endforeach; ?>
       </ul>
       <?php endif; ?>
       ```
   
 * ここで言う思い通りの動きとは、単一記事表示中は同一カテゴリーの投稿一覧をサイド
   バーに表示させたいという事ですが、どうしてコードAを外すとコードBが機能しなくなる
   のでしょうか。
 * どなたかご教授頂けないでしょうか。
 * 尚、コードBの子孫が要る時と要らない時は、自作テーマのfunctions.phpに以下のコード
   を記述（フォーラムから引用）しています。
 *     ```
       function my_category_children( $return ) {
         return array();
       }
       add_filter( 'pre_option_category_children', 'my_category_children' );
       ```
   
 * 宜しくお願い致します。
 *   フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   返信が含まれるトピック: [表示中の単一記事のカテゴリーIDとカテゴリー名の取得](https://ja.wordpress.org/support/topic/%e8%a1%a8%e7%a4%ba%e4%b8%ad%e3%81%ae%e5%8d%98%e4%b8%80%e8%a8%98%e4%ba%8b%e3%81%ae%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bcid%e3%81%a8%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e5%90%8d%e3%81%ae/)
 *  トピック投稿者 [eijiy](https://ja.wordpress.org/support/users/eijiy/)
 * (@eijiy)
 * [16年、 2ヶ月前](https://ja.wordpress.org/support/topic/%e8%a1%a8%e7%a4%ba%e4%b8%ad%e3%81%ae%e5%8d%98%e4%b8%80%e8%a8%98%e4%ba%8b%e3%81%ae%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bcid%e3%81%a8%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e5%90%8d%e3%81%ae/#post-130826)
 * mizubeさん、返信ありがとうございます。
 * 紹介していただいたコードでも同じように、全ての投稿一覧が表示されてしまいます。
   
   カテゴリー名は表示されるようになりましたが、どのカテゴリーに属する記事であって
   も親カテゴリーABCDの内Dしか表示されません。尚、Dのみ子カテゴリーがありません。
 * 解説サイトで、get_the_categoryではIDが正しく取得できないことがあるとか書いてありま
   したが、どうなんでしょうか。
 *   フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   返信が含まれるトピック: [単一記事を開いた時に、同一カテゴリーの投稿一覧をサイドバーに表示さ](https://ja.wordpress.org/support/topic/%e5%8d%98%e4%b8%80%e8%a8%98%e4%ba%8b%e3%82%92%e9%96%8b%e3%81%84%e3%81%9f%e6%99%82%e3%81%ab%e3%80%81%e5%90%8c%e4%b8%80%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e3%81%ae%e6%8a%95%e7%a8%bf%e4%b8%80/)
 *  トピック投稿者 [eijiy](https://ja.wordpress.org/support/users/eijiy/)
 * (@eijiy)
 * [16年、 2ヶ月前](https://ja.wordpress.org/support/topic/%e5%8d%98%e4%b8%80%e8%a8%98%e4%ba%8b%e3%82%92%e9%96%8b%e3%81%84%e3%81%9f%e6%99%82%e3%81%ab%e3%80%81%e5%90%8c%e4%b8%80%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e3%81%ae%e6%8a%95%e7%a8%bf%e4%b8%80/#post-130712)
 * kvexさん、返信ありがとうございます。
 * そうですね、例えば親Aの子1のカテゴリーに属する記事が表示されている時は親Aの子
   1の投稿一覧、親Bの子2のカテゴリーに属する記事が表示されている時は親Bの子2の投稿
   一覧、という具合にサイドバーに表示させたいと思っています。
 *   フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   返信が含まれるトピック: [選択されたカテゴリーの投稿一覧をサイドバーに表示がおかしい。](https://ja.wordpress.org/support/topic/%e9%81%b8%e6%8a%9e%e3%81%95%e3%82%8c%e3%81%9f%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e3%81%ae%e6%8a%95%e7%a8%bf%e4%b8%80%e8%a6%a7%e3%82%92%e3%82%b5%e3%82%a4%e3%83%89%e3%83%90%e3%83%bc%e3%81%ab/)
 *  トピック投稿者 [eijiy](https://ja.wordpress.org/support/users/eijiy/)
 * (@eijiy)
 * [16年、 3ヶ月前](https://ja.wordpress.org/support/topic/%e9%81%b8%e6%8a%9e%e3%81%95%e3%82%8c%e3%81%9f%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e3%81%ae%e6%8a%95%e7%a8%bf%e4%b8%80%e8%a6%a7%e3%82%92%e3%82%b5%e3%82%a4%e3%83%89%e3%83%90%e3%83%bc%e3%81%ab/#post-130417)
 * 上記のコードを訂正します。
 *     ```
       <?php if (is_category() || is_single()) : ?>
                           <?php
                               if (is_category()) {
                                   $cat = get_query_var('cat');
                                   $catname = get_the_category_by_ID($cat);
                               } else {
                                   $cat = get_the_category();
                                   $cat = $cat[0];
                                   $cat = $cat->cat_ID;
                                   $catname = $cat->cat_name;
                               }
                               echo '<dt>' . $catname . 'の投稿一覧</dt>';
                               $category_posts = get_posts("order=asc&category=$cat&numberposts=-1");
                           ?>
                           <dd>
                               <ul>
                                   <?php foreach($category_posts as $post): ?>
                                        <li class="myEllipsis"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
                                   <?php endforeach; ?>
                                </ul>
                            </dd>
                       <?php endif; ?>
       ```
   
 * これで選択されたカテゴリーや記事を開いた時に、そのカテゴリーの投稿一覧がサイド
   バーに表示される様になりました。
 * ありがとうございました。
 *   フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   返信が含まれるトピック: [選択されたカテゴリーの投稿一覧をサイドバーに表示がおかしい。](https://ja.wordpress.org/support/topic/%e9%81%b8%e6%8a%9e%e3%81%95%e3%82%8c%e3%81%9f%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e3%81%ae%e6%8a%95%e7%a8%bf%e4%b8%80%e8%a6%a7%e3%82%92%e3%82%b5%e3%82%a4%e3%83%89%e3%83%90%e3%83%bc%e3%81%ab/)
 *  トピック投稿者 [eijiy](https://ja.wordpress.org/support/users/eijiy/)
 * (@eijiy)
 * [16年、 3ヶ月前](https://ja.wordpress.org/support/topic/%e9%81%b8%e6%8a%9e%e3%81%95%e3%82%8c%e3%81%9f%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e3%81%ae%e6%8a%95%e7%a8%bf%e4%b8%80%e8%a6%a7%e3%82%92%e3%82%b5%e3%82%a4%e3%83%89%e3%83%90%e3%83%bc%e3%81%ab/#post-130392)
 * mizubeさん、返信ありがとうございます。
 * 説明不足でした。
 * 選択したカテゴリーのタイトルと其れに含まれる全て（子も孫も）の投稿一覧をサイド
   バーに表示させたかったんです。
 * それで提示されたコードで以下の様にして、選択したカテゴリーのタイトルとその投稿
   一覧をサイドバーに表示させることが出来ました。
 *     ```
       <?php if (is_category() || is_single()) : ?>
            <?php
                $cat = get_query_var('cat');
           	 $catname = get_the_category_by_ID($cat);
       	 echo '<dt>' . $catname . 'の投稿一覧</dt>';
                $category_posts = get_posts("order=asc&category=$cat&numberposts=-1");
            ?>
            <dd>
                <ul>
                    <?php foreach($category_posts as $post): ?>
                        <li class="myEllipsis"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
                    <?php endforeach; ?>
                </ul>
            </dd>
       <?php endif; ?>
       ```
   
 * ありがとうございました。
 * もし間違っているところや修正すべき点があればご指摘ください。

15件の返信を表示中 - 31 - 45件目 (全102件中)

[←](https://ja.wordpress.org/support/users/eijiy/replies/page/2/?output_format=md)
[1](https://ja.wordpress.org/support/users/eijiy/replies/?output_format=md) [2](https://ja.wordpress.org/support/users/eijiy/replies/page/2/?output_format=md)
3 [4](https://ja.wordpress.org/support/users/eijiy/replies/page/4/?output_format=md)
[5](https://ja.wordpress.org/support/users/eijiy/replies/page/5/?output_format=md)
[6](https://ja.wordpress.org/support/users/eijiy/replies/page/6/?output_format=md)
[7](https://ja.wordpress.org/support/users/eijiy/replies/page/7/?output_format=md)
[→](https://ja.wordpress.org/support/users/eijiy/replies/page/4/?output_format=md)