0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Bogoで言語別にタグ毎の記事一覧を出力

Last updated at Posted at 2020-02-07

動作確認バージョン

  • WordPress: 5.3.2
  • Bogo: 3.2.1

サンプル


<?php
// 現在のロケールを取得
$locale = get_locale();
?>

<div class="entry_content">
  <h1>tag list</h1>
  <?php
    $original_query = $wp_query;
    // slug順にタグを取得
    $tag_all = get_terms( 'post_tag', array(
      'fields' => 'all',
      'orderby' => 'slug'
      )
    );
    foreach( $tag_all as $value ):
  ?>
  <h2>tag-name: <?php echo $value->name; ?> <small>tag-slug: <?php echo $value->slug; ?></small></h2>
  <?php
    $arg_tag = array(
      // 現在のロケールの記事
      'suppress_filters' => false,
      'lang' => $locale,
      // 全件取得
      'numberposts' => '-1',
      'orderby' => 'ASC',
      'tag' => $value->slug
    );
    $posts = get_posts( $arg_tag );
    global $post;
  ?>
  <ul>
    <?php foreach( $posts as $post ): ?>
    <li><?php the_time( 'Y.m.d' ); ?> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
  </ul>
  <?php
    endforeach;
    $wp_query = $original_query;
    wp_reset_postdata();
  ?>
</div>

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?