最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

blog - Unable to add template to page set as Posts page in WP V 4.6.1

programmeradmin1浏览0评论

I'm trying to set a template to our blog page which is set as Posts page in WP Admin. The theme is Twenty Fifteen. The issue is that the option Template selector which appears for all other pages under Page attribute menu doesn't appear only on pages set as Posts page. Is this an error tied to this version or theme? There are multiple templates used in this website, but none seems to appear for this page.

I'm trying to set a template to our blog page which is set as Posts page in WP Admin. The theme is Twenty Fifteen. The issue is that the option Template selector which appears for all other pages under Page attribute menu doesn't appear only on pages set as Posts page. Is this an error tied to this version or theme? There are multiple templates used in this website, but none seems to appear for this page.

Share Improve this question edited Aug 29, 2018 at 12:17 Sandeep C. Nath asked Aug 29, 2018 at 12:08 Sandeep C. NathSandeep C. Nath 1033 bronze badges 2
  • how are you trying to set up the template? – Castiblanco Commented Aug 29, 2018 at 12:15
  • Template file was created as php files and its already applied to other pages, here's the image of my page settings i.sstatic/lC0Pg.png – Sandeep C. Nath Commented Aug 29, 2018 at 12:17
Add a comment  | 

2 Answers 2

Reset to default 2

You cannot set a custom template for the latest posts page. This setting is ignored for it. The template that is used for this page is determined by the Template Hierarchy.

So if you start at the left for Blog Posts Index Page you'll see that it uses home.php for its template, if it exists, otherwise it uses index.php.

But if your homepage is set to show the latest posts then front-page.php will be used if that exists.

PS: You're running a 2 year old version of WordPress, and should update as soon as possible.

If you want to use template file, you need to write functions.php.

Hook is theme_page_templates.
like this


 * @param array $post_templates Array of page templates. Keys are filenames, values are translated names.
 * @return array Filtered array of page templates.
 */
function makewp_exclude_page_templates($post_templates)
{
  if (version_compare($GLOBALS['wp_version'], '4.7', '<')) {
    unset($post_templates['templates/my-full-width-post-template.php']);
  }
  return $post_templates['page-templates/blog.php'];
}

add_filter('theme_page_templates', 'makewp_exclude_page_templates');
发布评论

评论列表(0)

  1. 暂无评论