WordPressで更新日付を表示したり特定カテゴリーだけ表示する ※ TCDテーマCore専用

メモ。

前にも書いたが忘れないようにもう一度メモ。

TCD ThemaのCore用だが、同じCoreなら互換性はあるかも。互換性なくてもphpの部分は同じでも動くので参考にしてみてください。single.phpの任意の場所に追記した。

<!--公開日表示202304-->

<?php if ($options['show_date']){ ?><li class="post_date"><time class="entry-date updated" datetime="<?php the_modified_time('c'); ?>"><?php the_time('Y/n/j'); ?></time></li><?php }; ?>

<!--更新日表示202304-->

<?php if ($options['show_date']){ ?><?php if (get_the_modified_date('Y/m/d') != get_the_time('Y/m/d')) : ?><li class="post_date"><time class="entry-date updated" datetime="<?php the_modified_time('c'); ?>">最終更新:<?php the_modified_date('Y/n/j') ?></time></li><?php endif; ?><?php }; ?>

 

ここまでは、単に公開日と更新日の表示。

以下は、さらにアレンジして特定カテゴリーだけで表示。

<!--公開日表示 特定カテゴリーだけ202304-->

 <?php if(in_category(array('4466','3115'))): ?><li class="post_date"><time class="entry-date updated" datetime="<?php the_modified_time('c'); ?>"><?php the_time('Y/n/j'); ?></time></li><?php endif; ?>

 <!--更新日表示 特定カテゴリーだけ202304-->

 <?php if(in_category(array('4466','3115'))): ?><?php if (get_the_modified_date('Y/m/d') != get_the_time('Y/m/d')) : ?><li class="post_date"><time class="entry-date updated" datetime="<?php the_modified_time('c'); ?>">更新日:<?php the_modified_date('Y/n/j') ?></time></li><?php endif; ?><?php endif; ?>

 

特定カテゴリーは私の仕様で、4466と3115が入っているが、ここは人によって違うので必要なカテゴリーIDを入れてください。増やす場合はカンマで区切って増やして行けばオーケー

コメント

タイトルとURLをコピーしました