在档案 functions.php 中,我创建了一个自定义类别
$labels = array(
'name' => _x('Partners', 'post type general name'),
'singular_name' => _x('Partners', 'post type singular name'),
'add_new' => _x('Add New', 'partners'),
'add_new_item' => __("Add New Partners"),
'edit_item' => __("Edit Partners"),
'new_item' => __("New Partners"),
'view_item' => __("View Partners"),
'search_items' => __("Search Partners"),
'not_found' => __('No partners found'),
'not_found_in_trash' => __('No partners found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'menu_icon' => 'dashicons-groups',
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','thumbnail','excerpt', 'editor')
);
register_post_type('partners',$args);
在合作伙伴的模板中,我写道:
<?php
$args = array(
'posts_per_page' => -1, // Get all posts
'post_type' => 'partners', // Query for the default Post type
'order_by' => 'post_date' // Order by date posted
);
$last_five_posts = get_posts( $args );
foreach ( $last_five_posts as $post ) : setup_postdata( $post );
?>
它工作正常。该页面显示我在自定义类别中编辑的所有帖子。
翻译问题出现了。我使用WMPL插件,我使用两种语言:意大利语和英语。合作伙伴页面向我展示了两种语言:
意大利语页面:
发布ORIGINAL1
发布TRANSLATED1
发布ORIGINAL2
发布TRANSLATED2
...
英文页面:
发布ORIGINAL1
发布TRANSLATED1
发布ORIGINAL2
发布TRANSLATED2
...
我认为问题在于代码,我遗漏了一些东西。
你知道怎么解决吗?
答案 0 :(得分:1)
支持人员回答了我。在Partner的模板中,而不是使用get_posts()函数,我不得不使用WP_Query类:
<?php
$args = array(
'posts_per_page' => -1, // Get all posts
'post_type' => 'partners', // Query for the default Post type
'order_by' => 'post_date' // Order by date posted
);
$last_five_posts = new WP_Query( $args );
if( $last_five_posts->have_posts() ): while( $last_five_posts->have_posts() ) : $last_five_posts->the_post();
?>
<?php
$args = array(
'posts_per_page' => -1, // Get all posts
'post_type' => 'partners', // Query for the default Post type
'order_by' => 'post_date' // Order by date posted
);
$last_five_posts = new WP_Query( $args );
if( $last_five_posts->have_posts() ): while( $last_five_posts->have_posts() ) : $last_five_posts->the_post();
?>