简体   繁体   English

制作自定义WP主题,永久链接转到首页

[英]Making custom WP theme, permalinks go to top of frontpage

I've made multipage websites before but this is my first attempt at a WP theme and I'm not too familiar with how WP behaves. 我以前制作过多页网站,但这是我第一次尝试WP主题,而且我对WP的行为不太熟悉。 Can someone explain to me how Wordpress knows what file to use as a template for the permalink target? 有人可以向我解释Wordpress如何知道将哪个文件用作永久链接目标的模板吗?

I have a custom made frontpage (index.php) with a loop that generates "teasers" to my blog posts with the post titles containing the permalinks generated through the_permalink(). 我有一个定制的首页(index.php),带有一个循环,该循环会为我的博客帖子生成“预告片”,其帖子标题包含通过the_permalink()生成的永久链接。 But when I click on the link, it just takes me up to the top of the page. 但是,当我单击链接时,它只是将我带到页面顶部。 I'm assuming WP is using my index.php as a template for the permalink, but I want to use a different .php template, since index.php is my frontpage. 我假设WP使用我的index.php作为永久链接的模板,但是我想使用其他.php模板,因为index.php是我的首页。 How do I tell WP to go to use different page template? 如何告诉WP使用其他页面模板?

In Wordpress, a page is typically built up from a number of different template files. 在Wordpress中,页面通常是由许多不同的模板文件组成的。 The specific files used depend on the type of content being displayed and the options chosen, rather than the permalink. 使用的特定文件取决于显示的内容类型和选择的选项,而不取决于永久链接。

Typically index.php is your base template. 通常index.php是您的基本模板。 It may be a wrapper which performs a loop, and pulls in a sub-template for each post. 它可以是一个包装程序,它执行一个循环,并为每个帖子引入一个子模板。 Small content templates describe how to show specific things, like a post. 小型内容模板描述了如何显示特定内容,例如帖子。 So index.php would have the wrapper html and the loop, while content.php would have the template for each post. 因此index.php将具有包装器html和循环,而content.php将具有每个帖子的模板。

You then have a set of other page templates depending on the content type such as single.php - a single post page.php - a single page page-i-made.php - a custom page template, which you can choose when you create the page. 然后,根据内容类型,您还有一组其他页面模板,例如single.php单个帖子page.php单个页面page-i-made.php自定义页面模板,您可以在创建时选择它们这一页。 etc. 等等

There is a list of these content templates in the Theme Development page of the Wordpress codex. 这些内容模板的列表在Wordpress Codex的主题开发页面中。

So in your case to set up single post pages, you would be looking at single.php and perhaps content.php. 因此,在您设置单个帖子页面的情况下,您将查看single.php甚至content.php。

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

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