前提・実現したいこと
wordpressの投稿ページのサイドバーに表示される
「最新の投稿」ウィジェットに
タグ情報を表示したいです。
発生している問題
$recent_postからタグ情報が取得できないかと思っていたのですが
現在のsingle.phpのループ内のタグを取得してしまいます。
該当のソースコード
/wp-includes/widgets/class-wp-widget-recent-posts.php
<ul> <?php foreach ( $r->posts as $recent_post ) : ?> <?php $post_tags = get_the_tags($recent_post->ID); $post_title = get_the_title( $recent_post->ID ); $title = ( ! empty( $post_title ) ) ? $post_title : __( '(no title)' ); ?> <li> <a href="<?php the_permalink( $recent_post->ID ); ?>"><?php echo $title ; ?></a> <?php if( get_the_tags($post_tags) ){ echo '<br><span class="post-tags">'; the_tags(); echo '</span>'; } ?> <?php if ( $show_date ) : ?> <span class="post-date"><?php echo get_the_date( '', $recent_post->ID ); ?></span> <?php endif; ?> </li> <?php endforeach; ?> </ul>
試したこと
<ul> <?php foreach ( $r->posts as $recent_post ) : ?> <?php $post_tags = get_the_tags($recent_post->ID); $post_title = get_the_title( $recent_post->ID ); $title = ( ! empty( $post_title ) ) ? $post_title : __( '(no title)' ); ?> <li> <a href="<?php the_permalink( $recent_post->ID ); ?>"><?php echo $title ; ?></a> <!--ここから--> <?php if( get_the_tags($post_tags) ){ echo '<br><span class="post-tags">'; the_tags(); echo '</span>'; } ?> <!--//ここまで--> <?php if ( $show_date ) : ?> <span class="post-date"><?php echo get_the_date( '', $recent_post->ID ); ?></span> <?php endif; ?> </li> <?php endforeach; ?> </ul>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/04/06 07:52