如何创建自定义WordPress页面?

时间:2023-01-03 21:12:42

I want my WordPress blog to have a page called music. On that page I will query the DB for posts with the category music and then change around the look and feel of the posts. So I can't just put a link to /categories/music/ because I want to do custom work on the posts.

我希望我的WordPress博客有一个名为音乐的页面。在该页面上,我将向DB查询具有类别音乐的帖子,然后更改帖子的外观。所以我不能只添加/ categories / music /的链接,因为我想在帖子上做自定义工作。

Should I put this code in a separate php file and link to it? I think I may lose access to all the nice WordPress API calls if I do that.

我应该将此代码放在一个单独的php文件中并链接到它吗?我想如果我这样做,我可能会失去对所有好的WordPress API调用的访问权限。

I was thinking about using a filter, but I am not sure which one to use. I was thinking something like the following except the_title has not been grabbed yet so I cannot check the title.

我正在考虑使用过滤器,但我不确定使用哪一个。我正在想类似下面的事情,除了the_title尚未被抓住所以我无法查看标题。

function show_music(){

    if( is_page() && the_title('','',false) == 'music' ){
        echo "got here";
    }
}
add_filter('pre_get_posts', 'show_portfolio');

How would you go about this?

你会怎么做?

2 个解决方案

#1


You need to put the below code in the file, and then put the file in the Theme folder. Then you can create a page using Wordpress pages and select a page template with the name you put in this comment:

您需要将以下代码放在文件中,然后将该文件放在Theme文件夹中。然后,您可以使用Wordpress页面创建页面,并选择一个页面模板,其中包含您在此评论中添加的名称:

/*
Template Name: Something Goes Here
*/

#2


You need to create custom page within your theme. If you dont have idea how to create custme page or template page in WordPress theme then view my easy tutorial How to create template page in WordPress

您需要在主题中创建自定义页面。如果您不知道如何在WordPress主题中创建custme页面或模板页面,那么请查看我的简单教程如何在WordPress中创建模板页面

#1


You need to put the below code in the file, and then put the file in the Theme folder. Then you can create a page using Wordpress pages and select a page template with the name you put in this comment:

您需要将以下代码放在文件中,然后将该文件放在Theme文件夹中。然后,您可以使用Wordpress页面创建页面,并选择一个页面模板,其中包含您在此评论中添加的名称:

/*
Template Name: Something Goes Here
*/

#2


You need to create custom page within your theme. If you dont have idea how to create custme page or template page in WordPress theme then view my easy tutorial How to create template page in WordPress

您需要在主题中创建自定义页面。如果您不知道如何在WordPress主题中创建custme页面或模板页面,那么请查看我的简单教程如何在WordPress中创建模板页面