duanmeng7865 2014-10-02 17:25
浏览 70
已采纳

Wordpress自定义发布语言WPML

Hi I have a custom type post and it has a translation. When am calling all the custom post i get every items in double. Is there a way to check which language is the post set to?

Thank you

  • 写回答

1条回答 默认 最新

  • dougan6402 2014-10-02 17:35
    关注

    I think this could help you http://wpml.org/faq/how-to-translate-custom-types/

    Assuming that you setted up your custom type post, according to wpml: If you are using the Translation Management module, go to WPML->Translation Managementand click on the Multilingual Content Setup tab. Otherwise, without the Translation Management module, you will find these options under WPML->Translation Options.

    Edit:

    <?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; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 哪个tomcat中startup一直一闪而过 找不出问题
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳