wpml-在存档页显示所有CPT,如果未翻译,则显示默认语言
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了wpml-在存档页显示所有CPT,如果未翻译,则显示默认语言相关的知识,希望对你有一定的参考价值。
shows list of cpt for example on archive page when wpml is installed. if particular post has no translation, it shows it in default language
<?php // save current language $current_lang = apply_filters( 'wpml_current_language', null ); //get the default language $default_lang = apply_filters( 'wpml_default_language', null ); //fetch posts in default language do_action( 'wpml_switch_language', $default_lang); //query args 'cat' => 1 ); //build query $custom_query = new wp_query($custom_query_args); //loop while ( $custom_query->have_posts() ) : $custom_query->the_post(); //check if a translation exist $t_post_id = apply_filters( 'wpml_object_id', $post->ID, 'post', false, $current_lang ); $t_post = get_post( $t_post_id); ?> <a href="<?php echo get_permalink($t_post_id); ?>" title="<?php echo get_the_title($t_post_id); ?>"><?php echo get_the_title($t_post_id); ?></a> <?php } //no translation? display default language else{ ?> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> <?php } endwhile; wp_reset_query(); do_action( 'wpml_switch_language', $current_lang);
以上是关于wpml-在存档页显示所有CPT,如果未翻译,则显示默认语言的主要内容,如果未能解决你的问题,请参考以下文章