php WPML:以不同语言的手风琴风格获取每个学期的帖子。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php WPML:以不同语言的手风琴风格获取每个学期的帖子。相关的知识,希望对你有一定的参考价值。

<?php
  /*=============================================================================
  =            WPML Get posts from each terms in accordion style for            =
  =============================================================================*/
  $args = array(
    'taxonomy' => 'TAXONOMY', // defaults to 'category'
    'parent'   => 0, // top level only
  );
  $terms = get_terms( $args );
?>

<ul class="list-accordions">
<?php foreach ( $terms as $term ) : ?>

  <li>
    <?php
      $query = new WP_Query(
        array(
          'post_type'        => 'POST_TYPE',
          'posts_per_page'   => -1,
          'order'            => 'ASC',
          'post__not_in'     => array( $post->ID ), // do not show current post
          'suppress_filters' => FALSE,
          'tax_query'        => array(
            array(
              'taxonomy' => $term->taxonomy,
              'terms'    => (int) apply_filters( 'wpml_object_id', $term->term_id, $term->taxonomy ),
            ),
          )
        )
      );
      var_dump($query);
    ?>

    <h4 class="heading"><?php echo $term->name; ?></h4>

    <div class="content">
      <ul>
        <?php $post_id = get_the_id(); ?>
        <?php while ( $query->have_posts() ) : $query->the_post(); ?>

          <li <?php if( $post_id == $post->ID ) { echo 'class="current-menu-item"'; } ?>>
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
          </li>

        <?php endwhile; ?>
      </ul>
    </div> <!-- .content -->

    <?php wp_reset_postdata(); ?>
  </li>

<?php endforeach; ?>
</ul> <!-- .list-accordions -->
<?php 
/* 
 * More examples can be found at
 * https://developer.wordpress.org/reference/functions/get_terms/
*/

get_terms( string|array $args = array() ); // return array of objects
Retrieve the terms in a given taxonomy or list of taxonomies.

// Returned Array
array(1) {
  [0] = ;
  object(WP_Term) (11) {
    ["term_id"]          = ; //int
    ["name"]             = ; //string 
    ["slug"]             = ; //string 
    ["term_group"]       = ; //int
    ["term_taxonomy_id"] = ; //int
    ["taxonomy"]         = ; //string
    ["description"]      = ; //string
    ["parent"]           = ; //int
    ["count"]            = ; // int
    ["filter"]           = ; //string
    ["meta"]             = ; array(0) { // presumably this would be some returned meta-data?
    }
  }
}

/* Args default values */
 array (
  'taxonomy'               => 'category', //empty string(''), false, 0 don't work, and return empty array
  'orderby'                => 'name',
  'order'                  => 'ASC',
  'hide_empty'             => true, //can be 1, '1' too
  'include'                => 'all', //empty string(''), false, 0 don't work, and return empty array
  'exclude'                => 'all', //empty string(''), false, 0 don't work, and return empty array
  'exclude_tree'           => 'all', //empty string(''), false, 0 don't work, and return empty array
  'number'                 => false, //can be 0, '0', '' too
  'offset'                 => '',
  'fields'                 => 'all',
  'name'                   => '',
  'slug'                   => '',
  'hierarchical'           => true, //can be 1, '1' too
  'search'                 => '',
  'name__like'             => '',
  'description__like'      => '',
  'pad_counts'             => false, //can be 0, '0', '' too
  'get'                    => '',
  'child_of'               => false, //can be 0, '0', '' too
  'childless'              => false,
  'cache_domain'           => 'core',
  'update_term_meta_cache' => true, //can be 1, '1' too
  'meta_query'             => '',
  'meta_key'               => array(),
  'meta_value'             => '',
);

以上是关于php WPML:以不同语言的手风琴风格获取每个学期的帖子。的主要内容,如果未能解决你的问题,请参考以下文章

php WPML:只有标志的语言切换器

php WPML语言选择器修复

php WPML语言菜单

php 自定义选择语言下拉列表wpml

php WPML - 检查当前语言

php 将当前的WPML语言添加到body类