admin管理员组文章数量:1130349
I've changed the permalinks to add a string at the beginning of the url like this: /london/%postname%/ This works perfect for all the pages but not for my home page.
I set my home page to be a single custom post type in settings->reading->static page so the url was like this:
But now it's:
How can i change it so the home page is just the single custom post type without the "/destination/london" part?
Edit:
After adding this code it almost work:
function enable_front_page_destination( $query ){
if('' == $query->query_vars['post_type'] && 0 != $query->query_vars['page_id'])
$query->query_vars['post_type'] = array( 'page', 'destination' );
}
add_action( 'pre_get_posts', 'enable_front_page_destination' );
But now the home url is / and it should be
Thank you.
I've changed the permalinks to add a string at the beginning of the url like this: /london/%postname%/ This works perfect for all the pages but not for my home page.
I set my home page to be a single custom post type in settings->reading->static page so the url was like this: http://example/destination/london
But now it's: http://example/london/destination/london
How can i change it so the home page is just the single custom post type without the "/destination/london" part?
Edit:
After adding this code it almost work:
function enable_front_page_destination( $query ){
if('' == $query->query_vars['post_type'] && 0 != $query->query_vars['page_id'])
$query->query_vars['post_type'] = array( 'page', 'destination' );
}
add_action( 'pre_get_posts', 'enable_front_page_destination' );
But now the home url is http://example/ and it should be http://example/london
Thank you.
Share Improve this question edited Oct 10, 2018 at 9:32 Oterox asked Oct 10, 2018 at 9:04 OteroxOterox 3521 gold badge4 silver badges13 bronze badges1 Answer
Reset to default 0EDIT Since, as you mentioned it in comments, it can have several values, maybe we could retrieve the city list and set corresponding rewrite rules like so?
assuming $city_list is an array of cities
foreach ($city_list as $city) {
add_rewrite_rule('/^'. $city .'/destination/'. $city .'$/','index.php?p=idofyourhomepage','top');
}
How about trying some rewrite rules.
add_rewrite_rule('/^london/destination/london$/','index.php?p=idofyourhomepage','top');
Or
add_rewrite_rule('/^london/destination/london$/','index.php?pagename=nameofyourhomepage','top');
Go validate your permalink settings to refresh the rules.
I've changed the permalinks to add a string at the beginning of the url like this: /london/%postname%/ This works perfect for all the pages but not for my home page.
I set my home page to be a single custom post type in settings->reading->static page so the url was like this:
But now it's:
How can i change it so the home page is just the single custom post type without the "/destination/london" part?
Edit:
After adding this code it almost work:
function enable_front_page_destination( $query ){
if('' == $query->query_vars['post_type'] && 0 != $query->query_vars['page_id'])
$query->query_vars['post_type'] = array( 'page', 'destination' );
}
add_action( 'pre_get_posts', 'enable_front_page_destination' );
But now the home url is / and it should be
Thank you.
I've changed the permalinks to add a string at the beginning of the url like this: /london/%postname%/ This works perfect for all the pages but not for my home page.
I set my home page to be a single custom post type in settings->reading->static page so the url was like this: http://example/destination/london
But now it's: http://example/london/destination/london
How can i change it so the home page is just the single custom post type without the "/destination/london" part?
Edit:
After adding this code it almost work:
function enable_front_page_destination( $query ){
if('' == $query->query_vars['post_type'] && 0 != $query->query_vars['page_id'])
$query->query_vars['post_type'] = array( 'page', 'destination' );
}
add_action( 'pre_get_posts', 'enable_front_page_destination' );
But now the home url is http://example/ and it should be http://example/london
Thank you.
Share Improve this question edited Oct 10, 2018 at 9:32 Oterox asked Oct 10, 2018 at 9:04 OteroxOterox 3521 gold badge4 silver badges13 bronze badges1 Answer
Reset to default 0EDIT Since, as you mentioned it in comments, it can have several values, maybe we could retrieve the city list and set corresponding rewrite rules like so?
assuming $city_list is an array of cities
foreach ($city_list as $city) {
add_rewrite_rule('/^'. $city .'/destination/'. $city .'$/','index.php?p=idofyourhomepage','top');
}
How about trying some rewrite rules.
add_rewrite_rule('/^london/destination/london$/','index.php?p=idofyourhomepage','top');
Or
add_rewrite_rule('/^london/destination/london$/','index.php?pagename=nameofyourhomepage','top');
Go validate your permalink settings to refresh the rules.
本文标签: permalinksCustom post type as home page with custom url
版权声明:本文标题:permalinks - Custom post type as home page with custom url 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749255267a2340369.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论