我有一个名为“新闻”的页面,我为新闻创建了一个自定义的帖子类型。在“新闻”页面中,我需要显示所有新闻自定义帖子,它们需要可点击。“新闻”页面url为http://example.com/media/lajmet. 当我点击新闻时,它会出现在url上”http://example.com/news/article1“.如何在自定义帖子上重写URL单击进入”http://example.com/media/lajmet/article1“?我也在使用polylang语言。
以下是我为新闻创建自定义帖子类型的方法:
function news_custom_post() {
$labels = array(
\'name\' => _x( \'News\', \'post type general name\' ),
\'singular_name\' => _x( \'News\', \'post type singular name\' ),
\'add_new\' => _x( \'Add new\', \'news\' ),
\'add_new_item\' => __( \'Add new news\' ),
\'edit_item\' => __( \'Edit news\' ),
\'new_item\' => __( \'New news\' ),
\'all_items\' => __( \'All news\' ),
\'view_item\' => __( \'View news\' ),
\'search_items\' => __( \'Search news\' ),
\'not_found\' => __( \'No news found\' ),
\'not_found_in_trash\' => __( \'No news found in the Trash\' ),
\'parent_item_colon\' => \'\',
\'menu_name\' => \'News\'
);
$args = array(
\'labels\' => $labels,
\'description\' => \'Holds our media news data\',
\'public\' => true,
\'menu_position\' => 6,
\'supports\' => array( \'title\', \'editor\', \'page-attributes\', \'thumbnail\'),
\'has_archive\' => true
);
register_post_type( \'news\', $args );
}
add_action( \'init\', \'news_custom_post\' );