What's New Generatorというプラグインを使用して
カスタム投稿(お知らせ)の一覧を表示させています。
詳細な説明が必要なお知らせは本文を見る必要があるためリンクをつけ、
その他の記事はタイトルしかなく本文がないためリンク無しにしたいと考えています。
タクソノミー'link_arinasi'、ターム'link_ari'が付与されている記事だけをリンクつきにするため以下のように記述しましたが、'link_ari'のタームを付与した記事もリンクなしで表示されてしまいます。
whats-new-generator.phpの変更部分
php
1class WhatsNewItem{ 2 var $date; 3 var $raw_date; 4 var $title; 5 var $url; 6 var $newmark; 7<!-- 追記 -->var $term; 8 private static $number = 0; 9 10 public function __construct( $post ){ 11 $options = WNG::get_option(); 12 $orderby = $options['wng_orderby']; 13 $this->raw_date = $orderby == '公開日順' ? $post->post_date : $post->post_modified; 14 $this->date = date(get_option('date_format'), strtotime($this->raw_date)); 15 $this->title = esc_html( $post->post_title ); 16 $this->url = get_permalink($post->ID); 17 $this->newmark = $this->is_new(); 18<!-- 追記 -->$this->term = get_the_terms($post->ID,'link_arinasi'); 19 self::$number++; 20 }
whatsnew-view.phpの変更部分
php
1 <hr/> 2 <?php foreach($info->items as $item): ?> 3 <dl> 4<!-- 変更 --> 5 <?php $info->term; ?> 6 <?php if($term == 'link_ari'): ?> 7 <a href="<?php echo $item->url; ?>"> 8 <?php else : ?> 9 <a> 10 <?php endif; ?> 11<!-- 変更 --> 12 <dt> 13 <?php echo $item->date; ?> 14 </dt> 15 <dd> 16 <?php if ( $item->newmark ): ?> 17 <span class='newmark'>NEW!</span> 18 <?php endif; ?> 19 <?php echo $item->title; ?> 20 <?php echo $item->term; ?> 21 </dd> 22 </a> 23 </dl> 24 <hr/> 25 <?php endforeach; ?>
phpは全くの初心者ですので、初歩的なミスでしたら申し訳ないです。
どうぞよろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/27 22:37