How to create a custom page(not a template) in a theme

admin2025-01-07  5

I have been searching for theme developing info but all that are related to this subject are talking about a custom page at page.php.

What I am trying to achieve is different. The scenario is that I have to create a page where the content is hard-coded, so I can have more creative freedom on the design. That is to say, I don't want to have it generated through adding pages from the CMS, since there are more restrictions to it.

Can I create a new static .php (a page.php with specific content), and linked to it from menu nav bar? It is similar to making a static home page, but not a "home" page.

I have been searching for theme developing info but all that are related to this subject are talking about a custom page at page.php.

What I am trying to achieve is different. The scenario is that I have to create a page where the content is hard-coded, so I can have more creative freedom on the design. That is to say, I don't want to have it generated through adding pages from the CMS, since there are more restrictions to it.

Can I create a new static .php (a page.php with specific content), and linked to it from menu nav bar? It is similar to making a static home page, but not a "home" page.

Share Improve this question edited Jul 13, 2018 at 12:46 adrian li asked Jul 13, 2018 at 12:38 adrian liadrian li 1431 silver badge7 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 0

No you can't link directly to a template file.

What you can do is either:

  1. Create a custom page template with your markup and content hardcoded into it. Then create a 'dummy' page in the back-end and assign the template to it. Then you can link to that page from the menu.
  2. Also create a 'dummy' page in the back-end, but instead of a custom template, create a page-{slug}.php template (where {$slug} is the slug of the page) with your markup and content hardcoded into it. Then when you view that page the page-{slug}.php will be used instead of page.php. Then you can link to that page from the menu.

You can have all the freedom you want. First create a page in the database. Name it Example. Then create a file page-example.php.

<?php get_header(); ?>
<h1>Example page</h1>
<?php get_footer(); ?>

This is your specific template for the example page. Ommiting the get_header and get_footer will leave you with a blank page.

There are two ways to approach this:

  1. You can write a complete html page and put it in a directory of your WordPress installation. You then link directly to that page. WP will treat it like an external link and of course you can put that link in your menu. This means the complete content is outside your installation, so it won't turn up in search either.

  2. You can write an almost empty template which only uses the_title and the_content to retrieve the data from the database (take into account the template hierarchy for naming of the template). You put all the content including the html in the content field. In this way the content is inside the database and will turn up in search.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736259485a592.html

最新回复(0)