特定の親カテゴリ ID を指定して、子カテゴリからの投稿を表示するページがあるサイトを設計しています。各投稿のタイトルが質問になり、内容が回答になります。質問をクリックしたときに回答を非表示/表示する、つまり、タイトルをクリックしたときにコンテンツを非表示/表示するために達成したいこと。ここでの主なことは、div が手動で作成されていないため、このスクリプトをポスト クエリと一緒に実行する必要があることです。そのため、特定の ID またはクラスをトグルに割り当てることはできません。トグルは、投稿の数に関係なく、すべての投稿で機能する必要があります。
これは、親カテゴリ (ID 327) から投稿を照会するために使用しているコードです。
<div id="subcat" class="m-t-1 f13 georgia bold dark-grey">
<?php
//get all child categories for a certain category ID, then for each child category display the posts
$parent_cat = 327;
$taxonomy = 'category';
$cat_children = get_term_children( $parent_cat, $taxonomy );
if ($cat_children) {
foreach($cat_children as $category) {
$args=array(
'cat' => $category,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
// echo 'Category name??' . $category;
$cat_name = get_cat_name($category);
echo <<<EOD
<div id="x">{$cat_name}</div>
EOD;
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h5 class="m-v-10"><a href="<?php the_permalink() ?>" class="f13 blauet bold arial" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h5>
<div id="mini-content" class="f12 dark-grey w-normal arial dotted-1-bottom m-b-3"><?php the_content();?></div>
<?php
endwhile;
}
}
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
</div><!-- #subcat -->
私が望むのは、(投稿へのリンクになった)をクリックすることで、 div id="mini-content" をオフに切り替えることです。
お手伝いいただきありがとうございます。
よろしく、良い一日を。