简体   繁体   中英

Create custom page in Wordpress with no theme elements

I'm trying to create a custom home page for a Wordpress site that's using the KnowledgePress theme. I'm not a PHP or Wordpress developer but I've spent hours researching this. No matter what I attempt, the page ends up taking on all kinds of theme elements from the site's custom theme.

I've tried creating an empty template, and then using this template from my custom page. Template:

<?php
/**
    Template Name: Empty Template
*/
?>
<html>
<head>
<style type="text/css">
body { background-color: #cccccc; }
#page-content { width: 800px; margin: 20px auto; }
</style>
<title><?php wp_title( '|', true, 'right' ); bloginfo('url'); ?></title>
</head>
<body>
<div id="page-content">
</div>
</body>
</html>

The result still showed the page's content wrapped in the site theme.

I've tried creating a custom page-pagename.php file in the theme root, eg page-welcome.php:

<html>
<head>
</head>
<body>
<h1>MySite.com</h1>
</body>
</html>

The content is still wrapped in the site's look and feel. The template includes:

  • base.php
  • index.php
  • page.php

if that's helpful. I have FTP access and am currently testing with a custom page but eventually would like this to work for the home page of the site. So far nothing I do breaks me out of the Wordpress theme, though.

Your template is typically included as "content part" either in page.php or single.php , which also include the header, footer and sidebar of the theme. that's why you always see them.

To avoid that, you have to create a "child theme" of the theme you use (ie an own folder in the theme directory) and put own versions/additions of/to all those files in there which you want to change - usually at least style.css and functions.php .

All this is too much to be explained in a short post here, you really have to get into Wordpress theme development, at least how to create child themes and an own page template (you'll need to know some php and some wordpress API knowledge for that).

ADDITION AFTER COMMENTS:

The problem with extending the actual theme is: As soon as the theme gets updated (which happens often in commercial themes), all changes are lost. So it's better to set up a child theme. But that's not THAT complicated, since you only have to create those few files that are different from the main theme - everything else is inherited, in a kind of cascading way. So basically you need the files style.css , often (not always) functions.php and the page template file/s you want to add (can be named anything, but must contain certain meta info as comments to be recognized as template). style.css also needs to contain information about the main theme (google...) to be recognized as a child theme by WP, but it only needs to contain the additional CSS rules you need - the others are fetched from the original theme, as all the other necessary stuff.

NEXT ADDITION AFTER COMMENT

Usually you first activate the child theme in the WP backend, then you go to pages > new page. There (in the right sidebar) you select your page template (which has to be in the child theme directory), insert your content in the WP editor and click "Publish". However, your template has to contain something like this to include the content you just inserted into the WP editor (the content is saved in the database):

 <?php while (have_posts()) : the_post(); ?>
   <?php the_content(); ?>
 <?php endwhile; ?>

You could also put "fixed content" right into the template, but one way or the other, you have to create a "new page" via the WP admin interface in order to integrate it into your site.

Have a look (well, a lot of looks...) at: https://developer.wordpress.org/themes/

FTP into your wordpress site, go to your current theme or child theme folder. You will find it in /wp-content/themes/ directory. Save copies of all your themes, then delete the originals.

Edit the .htaccess file in the root of the site. Add a rewrite rule to point to a static HTML file. Configure the rule to only apply to the home page (or whatever static URL you want to replace with your own custom HTML instead of the WP theme). Example .htaccess file before modification:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

After modification:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^$ somefile.html [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

The [L] tells the rewrite engine that a given rule is the last rule that should be evaluated (if it matches). More on rewrite rules here: Rewrite Tips and Tricks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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