function create_posttype() {
register_post_type( \'events\',
array(
\'labels\' => array(
\'name\' => __( \'Events\' ),
\'singular_name\' => __( \'Event\' )
),
\'public\' => true,
\'has_archive\' => true,
\'rewrite\' => array(\'slug\' => \'%city%/events\'),
)
);
}
add_action( \'init\', \'create_posttype\' );
register_taxonomy(\'cities\', array(\'events\'), array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'city\' ),
));
function wpa_permalinks( $post_link, $post ){
if ( is_object( $post ) && $post->post_type == \'events\' ){
$terms = wp_get_object_terms( $post->ID, \'cities\' );
if( $terms ){
return str_replace( \'%city%\' , $terms[0]->slug , $post_link );
}
}
return $post_link;
}
add_filter( \'post_type_link\', \'wpa_permalinks\', 1, 2 );
permalink结构正确(例如。
http://www.example.org/new-york/events/event-name
) 但我有两个问题:
模板单一事件。php未显示,显示404存档模板也是如此。http://www.example.org/new-york/events
应显示存档如何解决?