お知らせで条件分岐のしかた
6件の返信を表示中 - 1 - 6件目 (全6件中)
-
テンプレートタグ/post class – WordPress Codex 日本語版
こちらを活用いただければタグベースのスタイル切り分けはできると思います。
ご回答ありがとうございます。
しかしちょっと理解が及ばず…もう少しお願いします。
現在は下記の通りなのですが、どうやってcssが読み込まれてるかすらちょっと理解できない状況です。
もしよろしかったら…教えていただきたいです。<?php /*-------------------------------------------*/ /* info /*-------------------------------------------*/ $biz_vektor_options = biz_bektor_option_validate(); if(isset($biz_vektor_options['infoTopCount']) && $biz_vektor_options['infoTopCount'] != 0): $infoTopCount = $biz_vektor_options['infoTopCount']; $loop = new WP_Query( array( 'post_type' => 'info', 'posts_per_page' => $infoTopCount, ) ); ?> <?php if ($loop->have_posts()) : ?> <div id="topInfo" class="infoList"> <h2><?php echo esc_html($biz_vektor_options['infoLabelName']); ?></h2> <div class="rssBtn"><a href="<?php echo home_url(); ?>/feed/?post_type=info" id="infoRss" target="_blank">RSS</a></div> <?php if ( isset($biz_vektor_options['listInfoTop']) && $biz_vektor_options['listInfoTop'] == 'listType_set' ) { ?> <?php while ( $loop->have_posts() ) : $loop->the_post();?> <?php get_template_part('module_loop_post2'); ?> <?php endwhile ?> <?php } else { ?> <ul class="entryList"> <?php while ( $loop->have_posts() ) : $loop->the_post();?> <?php get_template_part('module_loop_post'); ?> <?php endwhile; ?> </ul> <?php } $infoTopUrl = (isset($biz_vektor_options['infoTopUrl']) && $biz_vektor_options['infoTopUrl'])? $biz_vektor_options['infoTopUrl'] : home_url().'/info/'; echo '<div class="moreLink right"><a href="'.esc_url($infoTopUrl).'">'; printf( __( '%s List page', 'biz-vektor' ), esc_html($biz_vektor_options['infoLabelName']) ); echo '</a></div>'; ?> </div><!-- [ /#topInfo ] --> <?php endif; wp_reset_query(); endif; // if ($infoTopCount != 0) : ?>どうやってcssが読み込まれてるかすらちょっと理解できない状況です。
その辺りは申し訳ないのですが ‘WordPress CSS 基礎’ などで検索をして調べてみてください。
その上で
post_classの使いどころについてご質問がある場合は<?php if ( isset($biz_vektor_options['listInfoTop']) && $biz_vektor_options['listInfoTop'] == 'listType_set' ) { ?> <?php while ( $loop->have_posts() ) : $loop->the_post();?> <?php get_template_part('module_loop_post2'); ?> <?php endwhile ?> <?php } else { ?> <ul class="entryList"> <?php while ( $loop->have_posts() ) : $loop->the_post();?> <?php get_template_part('module_loop_post'); ?> <?php endwhile; ?> </ul> <?php }上記コードで
get_template_partにより読み込まれているmodule_loop_post2.php、module_loop_post.phpのコードを見せてください。こちらとこちらでよろしいでしょうか?
ご教示お願いいたします。<?php $postType = get_post_type(); if ($postType == 'post') { $taxonomySlug = 'category'; } else { $taxonomies = get_the_taxonomies(); if ($taxonomies) { foreach ( $taxonomies as $taxonomySlug => $taxonomy ) {} } else { $taxonomySlug = ''; } } $taxo_catelist = get_the_term_list( $post->ID, $taxonomySlug, ' ','',''); ?> <li id="post-<?php the_ID(); ?>"> <span class="infoDate"><?php echo esc_html( get_the_date() ); ?></span> <span class="infoCate"><?php echo $taxo_catelist; ?></span> <?php if ( is_user_logged_in() == TRUE ) : edit_post_link(__('Edit', 'biz-vektor'), '<span class="edit-link edit-item">[ ', ' ]</span>');endif ?> <span class="infoTxt"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span> </li><?php $postType = get_post_type(); if ($postType == 'post') { $taxonomySlug = 'category'; } else { $taxonomies = get_the_taxonomies(); if ($taxonomies) { foreach ( $taxonomies as $taxonomySlug => $taxonomy ) {} } else { $taxonomySlug = ''; } } $taxo_catelist = get_the_term_list( $post->ID, $taxonomySlug, ' ','',''); ?> <!-- [ .infoListBox ] --> <div id="post-<?php the_ID(); ?>" class="infoListBox ttBox"> <div class="entryTxtBox<?php if ( has_post_thumbnail()) echo ' ttBoxTxt haveThumbnail'; ?>"> <h4 class="entryTitle"> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <?php if ( is_user_logged_in() == TRUE ) : edit_post_link(__('Edit', 'biz-vektor'), '<span class="edit-link edit-item">[ ', ' ]</span>');endif ?> </h4> <p class="entryMeta"> <span class="infoDate"><?php echo esc_html( get_the_date() ); ?></span><span class="infoCate"><?php echo $taxo_catelist; ?></span> </p> <p><?php the_excerpt(); ?></p> <div class="moreLink"><a href="<?php the_permalink(); ?>"><?php _e('Read more', 'biz-vektor'); ?></a></div> </div><!-- [ /.entryTxtBox ] --> <?php if ( has_post_thumbnail()) { ?> <div class="thumbImage ttBoxThumb"> <div class="thumbImageInner"> <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> </div> </div><!-- [ /.thumbImage ] --> <?php } ?> </div><!-- [ /.infoListBox ] -->/* Before */ <li id="post-<?php the_ID(); ?>"> // ↓ /* After */ <li id="post-<?php the_ID(); ?>" <?php post_class(); ?>>/* Before */ <div id="post-<?php the_ID(); ?>" class="infoListBox ttBox"> // ↓ /* After */ <div id="post-<?php the_ID(); ?>" <?php post_class( array( 'infoListBox', 'ttBox' ) ); ?>>カスタマイズ前に今回背景色の変更をしたい部分の
htmlソースを見て、どちらのテンプレートが使用されているか確認し、どちらか一方に手を加えれば十分です。こうすることで、各要素に
tag-{タグのスラッグ}、またはtag-{タグのID}クラスが付与されます。
参考: テンプレートタグ/post class – WordPress Codex 日本語版 #デフォルトの使い方スタイルシートでそのクラスにスタイルを当てて下さい。
6件の返信を表示中 - 1 - 6件目 (全6件中)
トピック「お知らせで条件分岐のしかた」には新たに返信することはできません。