【发布时间】:2021-09-17 13:43:52
【问题描述】:
我想实现自定义帖子网址。
目前帖子的网址是这样的:http://example.org/post-url/
我想做类似 http://example.org/_blog/_blog_post/post-url/ 之类的事情 我想在帖子网址之前添加 /_blog/_blog_post/
如果作者的ID是7.自定义url会在博文url生效 如果不是,则帖子网址将保持为:http://example.org/post-url/
这是我在functions.php中的当前代码
$args = get_user_by( 'id', 7 );
$wp_posts = get_posts($args);
if (count($wp_posts)) {
global $wp_rewrite;
$wp_rewrite->set_permalink_structure( $wp_rewrite->root . '/_blog_/internship_blog/%postname%/');
}
else {
global $wp_rewrite;
$wp_rewrite->set_permalink_structure( $wp_rewrite->root . '/%postname%/');
}
【问题讨论】: