简体   繁体   English

WordPress-所有页面链接到index.php文件

[英]Wordpress - all pages link to the index.php file

[NEW AT WORDPRESS] [WORDPRESS上的新功能]

I'm creating my own wordpress theme with own css etc etc. I've managed to get everything good in the index.php file, and I'm trying to make the other pages as well now. 我正在使用自己的CSS等创建自己的wordpress主题。我设法在index.php文件中获得了所有不错的东西,而且我现在也尝试制作其他页面。

When I make the home.php, blog.php, about.php and contact.php file (in my theme folder) they don't link to it. 当我制作home.php,blog.php,about.php和contact.php文件(在我的主题文件夹中)时,它们没有链接到该文件。 I'm following the "WordPress 3: Creating and Editing Custom Themes with Chris Coyier" on Lynda.com and the example shows that whenever you make a file with the same name as your page, it takes that directly (which works at his tutorial). 我遵循Lynda.com上的“ WordPress 3:使用Chris Coyier创建和编辑自定义主题”,该示例显示,只要您制作与页面名称相同的文件,它就会直接采用该名称(在他的教程中有效)。

Anyone that could know what is going on? 有人知道发生了什么吗?

Example: I got a file blog.php in my theme folder, and when I go to www.mydomain.com/blog the loaded file is the index.php file, instead of the blog.php file 示例:我的主题文件夹中有一个文件blog.php,当我转到www.mydomain.com/blog时,加载的文件是index.php文件,而不是blog.php文件。

There are two ways you can get this working using custom page templates. 您可以通过两种方式使用自定义页面模板来实现此目的。

  1. Create a template for one specific page using the page slug or ID. 使用页面标签或ID为一个特定页面创建模板。 In this case, change the name of the php files like this to match the name of the page you created in the UI: page-home.php, page-blog.php, page-about.php and page-contact.php 在这种情况下,请像这样更改php文件的名称,以匹配您在UI中创建的页面的名称:page-home.php,page-blog.php,page-about.php和page-contact.php。

  2. Much more flexible is to create a custom template that can be used on ANY page. 更加灵活的是创建可以在任何页面上使用的自定义模板。 Just add the template name to the top of the php file like so (inside the php block): 只需将模板名称添加到php文件的顶部即可,如下所示(在php块内部):

    /* Template Name: My Home Page Template */ / *模板名称:我的主页模板* /

Then edit the pages and select your custom template from the template dropdown menu (on the right hand side I think, if its visible). 然后编辑页面,然后从模板下拉菜单中选择您的自定义模板(我认为在右侧,如果可见)。

Reference this page for more info: https://developer.wordpress.org/themes/template-files-section/page-template-files/ 请参考此页面以获取更多信息: https : //developer.wordpress.org/themes/template-files-section/page-template-files/

Found the solution to my (silly) problem. 找到了解决我(傻)问题的方法。

Creating a page in your theme directory & adding the template comment at the top of your php file isn't enough. 在主题目录中创建页面并在php文件顶部添加模板注释是不够的。 You need to go to the admin panel->pages->YOUR PAGE-> and check out the page attributes. 您需要转到管理面板->页面->您的页面->并检出页面属性。 There you can link the page to a certain template: http://d.pr/i/a0m0 您可以在此处将页面链接到特定模板: http : //d.pr/i/a0m0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM