スニペット/WordPress archive category
archive
1 | <?php if (is_home() && !is_paged()) : ?> |
1 | <?php if (get_the_ID() == 15482 || get_the_ID() == 15484 || get_the_ID() == 15485): ?> |
1 2 3 4 5 | <?php global $wp_query; $total_results = $wp_query->found_posts; ?> <?php single_cat_title(); ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <ul> <?php $parent_ids = array(1, 2, 3); $categories = array(); foreach ($parent_ids as $parent_id) { $categories = array_merge ($categories, get_categories ('parent='.$parent_id) ); } $category_select = 3; $category_num = count ($categories); $selected_categories = array(); for ($i = 0; $i < $category_select; $i ++) { $selected_categories [] = $categories [rand (0, $category_num - 1)]; } ?> <?php foreach ($selected_categories as $category) : $cat_id = $category->cat_ID; $post_id = 'category_'.$cat_id; $cat_link = get_category_link ($cat_id); $model = get_field ('model', $post_id); $img = wp_get_attachment_image_src ($model, 'full'); $orderby = 'rand'; $posts_per_page = 3; ?><li><a href="<?php echo esc_url ($cat_link); ?>"><img src="<?php echo $img[0]; ?>"> <?php echo $category->cat_name; ?>(<?php echo $category->count; ?>)</a></li> <?php endforeach; ?> </ul> |
category
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // カテゴリ投稿数をaタグの中に add_filter('wp_list_categories', 'my_list_categories', 10, 2); function my_list_categories($output, $args) { $output = preg_replace('/<\/a>\s*\(([,\d]+)\)/', '($1)</a>', $output); $output = preg_replace('/,/', '', $output); return $output; } // カテゴリをID順に表示 add_filter('get_the_categories', 'get_the_category_orderby_id'); function get_the_category_orderby_id($categories) { usort( $categories, '_usort_terms_by_ID'); return $categories; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <ul> <?php $categories = get_categories('parent=1029'); foreach($categories as $category) : $cat_id = $category->cat_ID; $post_id = 'category_'.$cat_id; $cat_link = get_category_link($cat_id); $model = get_field('model', $post_id); $img = wp_get_attachment_image_src($model, 'full'); ?><li><a href="<?php echo esc_url($cat_link); ?>"><dl> <dt><img src="<?php echo $img[0]; ?>"></dt> <dd><?php echo $category->cat_name; ?>(<?php echo $category->count; ?>)</dd> </dl></a></li><?php endforeach; ?> </ul> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <?php $parent_ids = array(28); // 親カテゴリID $categories = array(); foreach ($parent_ids as $parent_id) { $categories = array_merge($categories, get_categories('parent='.$parent_id) ); } $post_categories = array(); // 現在の投稿が属するカテゴリーのみを選択 if (! empty ($categories) ) { foreach ($categories as $k => $category) { if (in_category ($category->cat_ID) ){ // 投稿が属しているか? $post_categories[] = $category; } } } if (!empty ($post_categories)): ?> <ul id="block-relation-series"> <li>この作品のサークル</li><?php foreach ($post_categories as $category) : $cat_id = $category->cat_ID; $post_id = 'category_'.$cat_id; $cat_link = get_category_link($cat_id); $model = get_field('model', $post_id); $img = wp_get_attachment_image_src($model, 'full'); ?><li><a href="<?php echo esc_url($cat_link); ?>"><dl> <dt><img src="<?php echo $img[0]; ?>"></dt> <dd><?php echo $category->cat_name; ?>(<?php echo $category->count; ?>)</dd> </dl></a></li><?php endforeach; ?> <!-- /#block-relation-series --></ul> <?php endif; ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?php $cats = get_the_category(); $print = ''; foreach ($cats as $category) { if ($category -> parent == 1) : $cat_url = get_category_link($category -> cat_ID); $print = $print . '<a href="' . $cat_url . '">' . $category -> cat_name . '</a>' . ', '; endif; } ?> <?php if (strlen($print)) { _e('<span>' . rtrim($print, ', ') . '</span>'); } else { _e('<span>-</span>'); } ?> |
コメントを投稿する