【问题标题】:Custom template page for several permalinks wordpress几个永久链接 wordpress 的自定义模板页面
【发布时间】:2020-02-23 21:26:21
【问题描述】:

我构建了一个名为 Single Listing 的自定义模板页面。此页面的永久链接是 /homes /

但我想为所有格式为 home/* 的 url 显示此自定义模板页面

我是 wordpress 新手,因此欢迎任何帮助或建议。

谢谢。

【问题讨论】:

  • homes 是一个页面吗?您想用相同的自定义模板显示它的子页面吗?如果是这样:wordpress.stackexchange.com/questions/130971/…
  • @caiovisk 抱歉,这对我没有帮助。也许我确实做了错误的步骤,或者我的问题解释不正确。是的,我想为localhost:8888/homes/* 的所有网址显示相同的模板,而不仅仅是localhost:8888/homes
  • @Prodev525 同样的解决方案也适用于您的问题。但是您需要更新 URL 模式的条件。

标签: wordpress templates


【解决方案1】:

未经测试,但这可能对您有所帮助。

add_filter( 'template_include', 'portfolio_page_template', 99 );

function portfolio_page_template( $template ) {
   global $wp;
   $current_url_path =  home_url( $wp->request );
   $url_pattern = '/(^homes[\/\w]*)/gim'

   if ( is_page()  && preg_match($pattern, $current_url_path)) {
      $new_template = locate_template( array( 'home-page-template.php' ) );

      if ( '' != $new_template ) {
         return $new_template ;
      }
   }

   return $template;
}

【讨论】:

    猜你喜欢
    • 2012-05-18
    • 1970-01-01
    • 2016-06-08
    • 1970-01-01
    • 2013-09-10
    • 1970-01-01
    • 1970-01-01
    • 2012-09-12
    • 2018-12-11
    相关资源
    最近更新 更多