我想在一个单独的页面上有一个专门的模板,只针对特定类别(slug Shop)的帖子发表评论。示例:mysite。com/post-incatshops-->mysite。com/post-incatshops/comment
为此,我创建了不同的函数,并将其放入函数中。php。问题是,对于某些帖子,它会随机返回404错误。我的永久链接结构是:/%postname%。我正在使用插件WP No Category Base.
Monkeyman Rewrite Analyzer 此行中该类别中每个帖子的返回值
^我的帖子标题/评论p:16138
你能帮帮我,告诉我哪里错了吗?提前感谢
function setup_permastruct() {
add_rewrite_tag(\'%opinioni%\',\'([^/]+)\');
add_rewrite_tag(\'%codici-sconto%\',\'([^/]+)\');
}
function eg_add_rewrite_rules() {
global $wp_rewrite;
global $wp, $wpdb, $post;
$loop = new WP_Query(array(\'post_type\' => \'post\',
\'posts_per_page\' => -1,
\'category_name\' => \'shops\',
\'orderby\' => \'date\',
\'order\' => \'DESC\')
);
while ( $loop->have_posts() ) : $loop->the_post();
$custom = get_post_custom($post->ID);
add_rewrite_rule( \'^\'.$post->post_name.\'/comment\', \'index.php?p=\'.$post->ID, \'top\' );
endwhile;
$loop = null;
wp_reset_query();
$wp_rewrite->flush_rules(false);
}
add_action( \'template_redirect\', \'eg_add_rewrite_rules\' );
function change_template_include( $t ) {
$url = explode( \'/\', $_SERVER[\'REQUEST_URI\'] );
$url = array_filter( $url );
$url = array_pop( $url );
if( $url == \'comment\' ) {
$t = str_replace( \'/single.php\', \'/template-single-comment.php\', $t );
}
return $t;
}
add_filter( \'template_include\', \'change_template_include\',10, 1 );