admin管理员组文章数量:1405153
How can I load a particular template based on part of a slug ?
Say I have 3 urls that I want to load the same template for so I want to match based on the 'advice-on' Please note I don't want a single page for each creating in the backend. I want to generate the content dynamic.
This is more specific part of the wider question here- Dynamic URL generates dynamic content
domain/advice-on-twitter
domain/advice-on-facebook
domain/advice-on-instagram
How can I load a particular template based on part of a slug ?
Say I have 3 urls that I want to load the same template for so I want to match based on the 'advice-on' Please note I don't want a single page for each creating in the backend. I want to generate the content dynamic.
This is more specific part of the wider question here- Dynamic URL generates dynamic content
domain/advice-on-twitter
domain/advice-on-facebook
domain/advice-on-instagram
Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Jan 13, 2017 at 18:13 landedlanded 1316 bronze badges1 Answer
Reset to default 1You can filter template_include
, check the request URL for your search words and return a custom template.
Here is a primitive example:
add_filter( 'template_include', function( $template ) {
$template_map = [
'advice-on' => 'advice',
'links-' => 'link-collection',
];
foreach ( $template_map as $find => $match )
{
if ( 0 === strpos( $_SERVER[ 'REQUEST_URI' ], $find ) )
return get_template_directory() . "/$match.php";
}
return $template;
});
本文标签: url rewritingLoad a template page based on part of slug in wordpress
版权声明:本文标题:url rewriting - Load a template page based on part of slug in wordpress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744882544a2630292.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论