编辑“WordPress:Creating a Static Front Page”
该编辑可以被撤销。 请检查下面的对比以核实您想要撤销的内容,然后发布下面的更改以完成撤销。
最后版本 | 您的文本 | ||
第1行: | 第1行: | ||
__TOC__ | __TOC__ | ||
'''UPDATE: With the release of [[WordPress:Version_2.1|WordPress Version 2.1]], the option to set your own front page can be accomplished via your [[WordPress:Administration_Panels|Administration]] > [[WordPress:Administration_Panels#Reading|Settings]] > [[WordPress:Settings_Reading_SubPanel|Reading]] panel. However unlike the old explanation that follows, you must NOT name your home page template file "home.php". If you do, this will cause a conflict with the WordPress 2.1 system. The approach that follows on this page is no longer necessary with WordPress 2.1 or newer''' | '''UPDATE: With the release of [[WordPress:Version_2.1|WordPress Version 2.1]], the option to set your own front page can be accomplished via your [[WordPress:Administration_Panels|Administration]] > [[WordPress:Administration_Panels#Reading|Settings]] > [[WordPress:Settings_Reading_SubPanel|Reading]] panel. However unlike the old explanation that follows, you must NOT name your home page template file "home.php". If you do, this will cause a conflict with the WordPress 2.1 system. The approach that follows on this page is no longer necessary with WordPress 2.1 or newer''' | ||
{{Oldpage|2.0}} | {{Oldpage|2.0}} | ||
Known as a '''static front page''' or '''splash page''', this is the first page seen by users entering your site. Unlike a traditional WordPress front page, featuring the [[WordPress:The Loop|WordPress Loop]] which generates a list of your most recent posts, the '''static front page''' is a customized page that lacks [[WordPress:The Loop]] and displays static information that can either invite people to "click through" to the real good stuff or offer highlighted post or article features and information that direct users to different areas of your WordPress site. It can have static information and links that do not change, or it can incorporate some automatically changing information. | Known as a '''static front page''' or '''splash page''', this is the first page seen by users entering your site. Unlike a traditional WordPress front page, featuring the [[WordPress:The Loop|WordPress Loop]] which generates a list of your most recent posts, the '''static front page''' is a customized page that lacks [[WordPress:The Loop]] and displays static information that can either invite people to "click through" to the real good stuff or offer highlighted post or article features and information that direct users to different areas of your WordPress site. It can have static information and links that do not change, or it can incorporate some automatically changing information. | ||
This page contains a technique that requires editing several files. There's a different, shorter [http://turbochargedcms.com/2006/11/building-a-true-home-page-into-your-wordpress-blog/ technique to get a static front page while maintaining a separate blog area], that is based on WordPress's static pages, and [http://www.nyceducated.info/blog/internet/the-real-ultimate-static-front-page/ another one that works entirely with template files]. Both of these techniques, unlike WordPress 2.1's front page setting, lend themselves to creating a richer, more interactive front page. | This page contains a technique that requires editing several files. There's a different, shorter [http://turbochargedcms.com/2006/11/building-a-true-home-page-into-your-wordpress-blog/ technique to get a static front page while maintaining a separate blog area], that is based on WordPress's static pages, and [http://www.nyceducated.info/blog/internet/the-real-ultimate-static-front-page/ another one that works entirely with template files]. Both of these techniques, unlike WordPress 2.1's front page setting, lend themselves to creating a richer, more interactive front page. | ||
===Using WordPress as CMS=== | ===Using WordPress as CMS=== | ||
If your goal is to have a WP-created Page with static information called "Home" at example.com/, and the standard blog index at example.com/news/, the method below may cause the [http://wordpress.org/support/topic/70417#post-369955 more tag to fail]. | If your goal is to have a WP-created Page with static information called "Home" at example.com/, and the standard blog index at example.com/news/, the method below may cause the [http://wordpress.org/support/topic/70417#post-369955 more tag to fail]. | ||
Use a plugin such as [http://www.ilfilosofo.com/blog/home-page-control Filosofo Home-Page Control] instead. It works fine with WP installed in root. | Use a plugin such as [http://www.ilfilosofo.com/blog/home-page-control Filosofo Home-Page Control] instead. It works fine with WP installed in root. | ||
== Create and Upload a Static Front Page == | == Create and Upload a Static Front Page == | ||
By default, most websites feature their main page as one of the following, and you can set yours to be any of these: | By default, most websites feature their main page as one of the following, and you can set yours to be any of these: | ||
* <tt>index.html</tt> | * <tt>index.html</tt> | ||
第54行: | 第26行: | ||
To create your static front page: | To create your static front page: | ||
# Using a [[WordPress:Glossary#Text editor|text editor]], open a blank document. | # Using a [[WordPress:Glossary#Text editor|text editor]], open a blank document. | ||
# Design the inside of your Static Front Page. | # Design the inside of your Static Front Page. | ||
# Save it with any name listed above (Example: <tt>home.php</tt>). | # Save it with any name listed above (Example: <tt>home.php</tt>). | ||
# If you have WordPress in another folder, upload your static page to your root HTML folder. | # If you have WordPress in another folder, upload your static page to your root HTML folder. | ||
Please note that your static page | Please note that your static page | ||
may need to have the file extension ".php" in order for the PHP code to be processed. | may need to have the file extension ".php" in order for the PHP code to be processed. | ||
If your static page is "index.html", then the PHP code may not be executed. | If your static page is "index.html", then the PHP code may not be executed. | ||
[[WordPress:Installing WordPress|Install WordPress]] in its own folder or, if you have already installed it, consider [[WordPress:Moving WordPress|moving WordPress]] to its own folder (or follow instructions below if you do not want to move entire WordPress core files -- ''but you might have some problems when [[WordPress:Upgrading WordPress|upgrading]]''). | [[WordPress:Installing WordPress|Install WordPress]] in its own folder or, if you have already installed it, consider [[WordPress:Moving WordPress|moving WordPress]] to its own folder (or follow instructions below if you do not want to move entire WordPress core files -- ''but you might have some problems when [[WordPress:Upgrading WordPress|upgrading]]''). | ||
=== If WordPress is in Root === | === If WordPress is in Root === | ||
'''If you do not want to move your WordPress installation''' to another folder, or you are in a hurry, you can use these instructions or look [[WordPress:#Change Apache Configuration File|below]]. | '''If you do not want to move your WordPress installation''' to another folder, or you are in a hurry, you can use these instructions or look [[WordPress:#Change Apache Configuration File|below]]. | ||
# Create a new folder on your site server for WordPress <tt>index.php</tt> file. | # Create a new folder on your site server for WordPress <tt>index.php</tt> file. | ||
# Download <tt>index.php</tt> WordPress file and open it in a [[WordPress:Glossary#Text editor|text editor]]. | # Download <tt>index.php</tt> WordPress file and open it in a [[WordPress:Glossary#Text editor|text editor]]. | ||
# Change the <tt>require('./wp-blog-header.php');</tt> line to <tt>require('../wp-blog-header.php');</tt> | # Change the <tt>require('./wp-blog-header.php');</tt> line to <tt>require('../wp-blog-header.php');</tt> | ||
# Save and upload the modified <tt>index.php</tt> file into the new folder. | # Save and upload the modified <tt>index.php</tt> file into the new folder. | ||
# Login into your WordPress [[WordPress:Administration Panels|Administration Panel]] and go to [[WordPress:Administration_Panels#Options_-_Configuration_Settings|Settings]] > [[WordPress:Settings_General_SubPanel|General]]. | # Login into your WordPress [[WordPress:Administration Panels|Administration Panel]] and go to [[WordPress:Administration_Panels#Options_-_Configuration_Settings|Settings]] > [[WordPress:Settings_General_SubPanel|General]]. | ||
# Change your Blog URI pointing to the new folder. For example, if your site is <tt><nowiki>http://example.com</nowiki></tt>, and the new folder is called <tt>blog</tt>, enter <tt><nowiki>http://example.com/blog</nowiki></tt>. | # Change your Blog URI pointing to the new folder. For example, if your site is <tt><nowiki>http://example.com</nowiki></tt>, and the new folder is called <tt>blog</tt>, enter <tt><nowiki>http://example.com/blog</nowiki></tt>. | ||
Now, upload your splash page to your root server folder. | Now, upload your splash page to your root server folder. | ||
==== Change Apache Configuration File ==== | ==== Change Apache Configuration File ==== | ||
There is another form to upload your static front page without moving all your WordPress files to another folder. | There is another form to upload your static front page without moving all your WordPress files to another folder. | ||
When you request a folder in a [http://www.apache.org Apache web server] (for example the folder called <tt>/chouette</tt>), the core of Apache will search for a file with any of the names in a list saved in <tt>httpd.conf</tt>. If your server lets you use <tt>.htaccess</tt> files for change the original configuration, you can follow these steps: | When you request a folder in a [http://www.apache.org Apache web server] (for example the folder called <tt>/chouette</tt>), the core of Apache will search for a file with any of the names in a list saved in <tt>httpd.conf</tt>. If your server lets you use <tt>.htaccess</tt> files for change the original configuration, you can follow these steps: | ||
# Open the <tt>.htaccess</tt> file from your root web folder in a [[WordPress:Glossary#Text editor|text editor]]. | # Open the <tt>.htaccess</tt> file from your root web folder in a [[WordPress:Glossary#Text editor|text editor]]. | ||
# At the top of the file, add: | # At the top of the file, add: | ||
<pre>DirectoryIndex home.php index.php</pre> | <pre>DirectoryIndex home.php index.php</pre> | ||
Save and upload the modified <tt>.htaccess</tt> file. | Save and upload the modified <tt>.htaccess</tt> file. | ||
You need to mention <tt>index.php</tt> as a second choice, otherwise you will not be able to access the <tt>index.php</tt> in directories below the wordpress root directory unless you explicitly mention it in the URL. For instance, the url: | You need to mention <tt>index.php</tt> as a second choice, otherwise you will not be able to access the <tt>index.php</tt> in directories below the wordpress root directory unless you explicitly mention it in the URL. For instance, the url: | ||
http://<wordpress root URL>/wp-admin/ | http://<wordpress root URL>/wp-admin/ | ||
would not work. | would not work. | ||
== Integrating WordPress == | == Integrating WordPress == | ||
To incorporate or integrate WordPress with your static front page, you can include the header, sidebar, footer, and even a mini-version of the WordPress Loop. | To incorporate or integrate WordPress with your static front page, you can include the header, sidebar, footer, and even a mini-version of the WordPress Loop. | ||
=== Include the Header === | === Include the Header === | ||
To include the header from your [[WordPress:Using Themes|WordPress Theme]] to maintain a consistent look, add this to the top of the page, using the folder path name you installed WordPress into: | To include the header from your [[WordPress:Using Themes|WordPress Theme]] to maintain a consistent look, add this to the top of the page, using the folder path name you installed WordPress into: | ||
<pre><?php | <pre><?php | ||
第184行: | 第83行: | ||
get_header(); | get_header(); | ||
?></pre> | ?></pre> | ||
The purpose of ''requiring'' or including wp-blog-header.php is to let you make use of any WordPress function or [[WordPress:Template Tags|template tag]]. When you include it in your page a function such as get_header() becomes available, just as it is in the standard WordPress [[WordPress:Templates|templates]]. | The purpose of ''requiring'' or including wp-blog-header.php is to let you make use of any WordPress function or [[WordPress:Template Tags|template tag]]. When you include it in your page a function such as get_header() becomes available, just as it is in the standard WordPress [[WordPress:Templates|templates]]. | ||
Note: In rare cases defining the <code>WP_USE_THEMES</code> constant to false may produce non-CSS formatted page output. To workaround this you can try replacing <code>('WP_USE_THEMES', false)</code> with <code>('WP_USE_THEMES', true)</code>. | Note: In rare cases defining the <code>WP_USE_THEMES</code> constant to false may produce non-CSS formatted page output. To workaround this you can try replacing <code>('WP_USE_THEMES', false)</code> with <code>('WP_USE_THEMES', true)</code>. | ||
=== Include The Sidebar or Footer === | === Include The Sidebar or Footer === | ||
To add the sidebar and/or footer from your WordPress Theme, include one or both of the following at the bottom of the page, using the same folder path: | To add the sidebar and/or footer from your WordPress Theme, include one or both of the following at the bottom of the page, using the same folder path: | ||
<pre><?php get_sidebar(); ?> | <pre><?php get_sidebar(); ?> | ||
第212行: | 第97行: | ||
=== Adding a Mini-Loop === | === Adding a Mini-Loop === | ||
You can incorporate a customized-version of the [[WordPress:The Loop|WordPress Loop]] in a ''static'' page to generate a short list of the latest posts on your WordPress blog. This "mini-Loop" acts like a feed, displaying your posts in a non-WordPress, PHP document. Change the value for '''$how_many''' to reflect the number of posts you want to show, and make sure the path to your wp-config.php file is correct. | You can incorporate a customized-version of the [[WordPress:The Loop|WordPress Loop]] in a ''static'' page to generate a short list of the latest posts on your WordPress blog. This "mini-Loop" acts like a feed, displaying your posts in a non-WordPress, PHP document. Change the value for '''$how_many''' to reflect the number of posts you want to show, and make sure the path to your wp-config.php file is correct. | ||
<pre> | <pre> | ||
第233行: | 第114行: | ||
</ol> | </ol> | ||
</pre> | </pre> | ||
Also, change "index.php" in the printf statement to include the path to the index.php in your installation directory. | Also, change "index.php" in the printf statement to include the path to the index.php in your installation directory. | ||
Alternatively, if using custom [[WordPress:Permalinks]] on your blog, you can set the code to retrieve the permalink for each article and use this as the link to the post. This helps with indexing of your site by search engines such as Google, which can blacklist your site if it considers that pages duplicate content (the same content would be accessible both by using the address <tt>{YourWordPressURL}/?p=x</tt> and <tt>{YourWordPressURL}/permalink-address/</tt>). To use permalinks on your static page: | Alternatively, if using custom [[WordPress:Permalinks]] on your blog, you can set the code to retrieve the permalink for each article and use this as the link to the post. This helps with indexing of your site by search engines such as Google, which can blacklist your site if it considers that pages duplicate content (the same content would be accessible both by using the address <tt>{YourWordPressURL}/?p=x</tt> and <tt>{YourWordPressURL}/permalink-address/</tt>). To use permalinks on your static page: | ||
<pre> | <pre> | ||
<?php | <?php | ||
第292行: | 第131行: | ||
</ol> | </ol> | ||
</pre> | </pre> | ||
In either case, posts will appear in an ordered list with the CSS ID <tt>whats-new</tt>. With [[WordPress:CSS]] you can change the look of the mini-Loop to suit your own site design. | In either case, posts will appear in an ordered list with the CSS ID <tt>whats-new</tt>. With [[WordPress:CSS]] you can change the look of the mini-Loop to suit your own site design. | ||
=== Using Feedburner? === | === Using Feedburner? === | ||
If you are already using [http://www.feedburner.com/ Feedburner] to manage your feeds, have a look at their "BuzzBoost" feature under Publicize. | If you are already using [http://www.feedburner.com/ Feedburner] to manage your feeds, have a look at their "BuzzBoost" feature under Publicize. | ||
With just a small piece of javascript you can add your recent posts to any html page. Very customizable as well. | With just a small piece of javascript you can add your recent posts to any html page. Very customizable as well. | ||
(More on [[WordPress:Using_FeedBurner]]) | (More on [[WordPress:Using_FeedBurner]]) | ||
== Examples == | == Examples == | ||
What you do with your static front page is up to you and your imagination. Here are a few examples to help you see the possibilities. | What you do with your static front page is up to you and your imagination. Here are a few examples to help you see the possibilities. | ||
=== Typical Page === | === Typical Page === | ||
[[WordPress:Image:wpdefault-without-dbcall.jpg|thumb|right|Look of the code on your left]] | [[WordPress:Image:wpdefault-without-dbcall.jpg|thumb|right|Look of the code on your left]] | ||
A typical welcome static page may feature a greeting that explains what the site is about and welcomes users to click on various links to enter the site. It could include summaries or links to articles or posts within, changed manually by the site administrator. | A typical welcome static page may feature a greeting that explains what the site is about and welcomes users to click on various links to enter the site. It could include summaries or links to articles or posts within, changed manually by the site administrator. | ||
Here is an example of a simple, typical page structure: | |||
<pre> | <pre> | ||
<?php | <?php | ||
第368行: | 第168行: | ||
<?php get_sidebar(); ?> | <?php get_sidebar(); ?> | ||
<?php get_footer(); ?></pre> | <?php get_footer(); ?></pre> | ||
=== Static Page with Mini-Loop === | === Static Page with Mini-Loop === | ||
To incorporate the mini-Loop into your static page review this example of a possible structure: | To incorporate the mini-Loop into your static page review this example of a possible structure: | ||
<pre> | <pre> | ||
第411行: | 第180行: | ||
?> | ?> | ||
<div id="content" class="narrowcolumn"> | <div id="content" class="narrowcolumn"> | ||
<h1>Welcome to my site | <h1>Welcome to my site</h1> | ||
<p>Hello and welcome to my site. You can go to my web page about how to improve your | <p>Hello and welcome to my site. You can go to my web page about how to improve your | ||
shoots with your digital camera; or you can go to my blog</p> | shoots with your digital camera; or you can go to my blog</p> | ||
第421行: | 第190行: | ||
# If you want to improve this code, you're welcome ;) | # If you want to improve this code, you're welcome ;) | ||
$how_many=7; //How many posts do you want to show | $how_many=7; //How many posts do you want to show | ||
?> | ?> | ||
<ul class="whats-new"> | <ul class="whats-new"> |