簡體   English   中英

WordPress自定義帖子語言WPML

[英]Wordpress custom post language WPML

嗨,我有一個自定義類型的帖子,它有翻譯。 當我打電話給所有自定義帖子時,我將所有物品都加倍。 有沒有辦法檢查帖子設置為哪種語言?

謝謝

我認為這可以幫助您http://wpml.org/faq/how-to-translate-custom-types/

假設您已根據wpml設置了自定義類型的帖子:如果您正在使用翻譯管理模塊,請轉至WPML->翻譯管理,然后單擊“多語言內容設置”選項卡。 否則,如果沒有翻譯管理模塊,則可以在WPML->翻譯選項下找到這些選項。

編輯:

<?php
  // set up or arguments for our custom query
  $paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
  $query_args = array(
    'post_type' => 'tutorials',
    'posts_per_page' => 5,
    'paged' => $paged
  );
  // create a new instance of WP_Query
  $the_query = new WP_Query( $query_args );
?>

<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); // run the loop

//I try to access to the translated object, where ICL_LANGUAGE_CODE specify the language
$translated = icl_object_id($post->ID,'tutorials',ICL_LANGUAGE_CODE);

 ?>
  <article>
    <h1><?php echo get_the_title($translated->ID); ?></h1>
    <div class="excerpt">
      <?php echo get_the_excerpt($translated->ID); ?>
    </div>
  </article>
<?php endwhile; ?>

<?php if ($the_query->max_num_pages > 1) { // check if the max number of pages is greater than 1  ?>
  <nav class="prev-next-posts">
    <div class="prev-posts-link">
      <?php echo get_next_posts_link( 'Older Entries', $the_query->max_num_pages ); // display older posts link ?>
    </div>
    <div class="next-posts-link">
      <?php echo get_previous_posts_link( 'Newer Entries' ); // display newer posts link ?>
    </div>
  </nav>
<?php } ?>

<?php else: ?>
  <article>
    <h1>Sorry...</h1>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
  </article>
<?php endif; ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM