WordPress 中文文档
Site Architecture 1.5
出自WordPress Chinese 中文文档
目录 |
The following is a description of the general site architecture for WordPress v1.5. WordPress Theme authors are encouraged to maintain much of the core site architecture of XHTML tags and CSS selectors, but they are not required to. Therefore, this is just a general outline and your Theme may be different.
Template Driven Pages
Before we get to the Core Structure of the WordPress page architecture, you need to understand that WordPress uses template files to generate the final page look and content. For example, when viewing the front page of your WordPress site, you are actually viewing several template files:
- ttindex.php/tt
- ttheader.php/tt
- ttsidebar.php/tt
- ttfooter.php/tt
When you view a single post page, you might be viewing the following template files:
- ttsingle.php/tt
- ttheader.php/tt
- ttsidebar.php/tt
- ttfooter.php/tt
- ttcomments.php/tt
On a multi-post page like categories, archives, and search, you might be viewing any combination of the following template files:
- ttindex.php/tt
- ttcategory.php/tt
- tt404.php/tt
- ttsearch.php/tt
- ttheader.php/tt
- ttsidebar.php/tt
- ttfooter.php/tt
We've specified which CSS selectors belong in which template files as much as possible in the following architecture specifications.
Core Structure
The core structure of a WordPress site represents the main containers which hold the page's content. The core structure of a WordPress site features, at a minimum, are:
- Header
- Sidebar/Menu
- Content
- Footer
These are the main containers in which the most important parts of the page are contained. Remember, the core structure is like building blocks. They are dependent upon each other. If you change one, you have to change the others.
Classic Theme
prebody div id=rap h1 id=header/h1 div id=content/div div id=menu/div p class=credit/p /div /body/pre
Default Theme
prebody div id=page div id=header/div div id=content class=narrowcolumn/div div id=sidebar/div div id=footer/div /div!-- end page -- /body/pre
While one calls their sidebar ttsidebar/tt and the other ttmenu/tt, the main difference between the two Theme's core structures is the use of the header and footer. For the Classic Theme, the header is in an tth1/tt tag and the footer is in a paragraph tag. In the Default Theme, the header is in a ttdiv/tt called ttheader/tt and the footer is in the ttfooter div/tt.
Both Themes feature a container that encompasses or wraps itself around the entire page. This wrapping container allows for more definitive control over the overall structure, often used in combination with the ttbody/tt tag. In different WordPress Themes, these are also found by these names:
- container
- page
- wrap
- rap
Some Themes may add a second, third, or even fourth sidebar, creating a column effect. Or they may include additional wrappers around the entire page or specific containers, but this is the core structure.
The Modular Template Files
Based upon the premise of building blocks, WordPress Themes divide up the core structure between blocks called template files. These are the template files:
- Header - ttheader.php/tt
- Sidebar/Menu - ttsidebar.php/tt
- Content - ttindex.php/tt, ttsingle.php/tt, ttpage.php/tt, ttcategory.php/tt, ttauthor.php/tt, ttsearch.php/tt, etc.
- Footer - ttfooter.php/tt
As you can see, the content container can be found across many other template files. These are generated dependent upon the user's request. If they click on a category, the category template is displayed. If they choose a Page, the page template is used. And so on.
Combined with the WordPress Loop and queries, a variety of templates can be generated, and the web page designer can style all of these differently and independently from each other.
Interior Structures
Within these core structural containers are smaller building blocks that hold the specific content within the parent container. WordPress Themes can feature a variety of these, but we are going to concentrate on the two Themes that come with WordPress. Most WordPress Themes are based on these two Themes.
Header
The header is the structure that traditionally sits at the top of a web page. It contains the title of the website. It may also be referred to as the masthead, head, title, and banner. In all WordPress Themes, the ttheader/tt is found within the ttheader.php/tt template file.
The Classic Theme features the simplest header code:
prelt;h1 id=headerlt;/h1/pre
The Default Theme has a more complex header code:
prelt;div id=header
div id=headerimg
h1/h1
div class=description/div
/div
/div /pre
While the styles for the Classic Theme are found within the Theme's ttstyle.css/tt style sheet file, styles for the Default Theme are found within the ttstyle.css/tt and the ttlt;head/tt of the ttheader.php/tt template file. Working with these styles is extensively covered in Designing Headers.
Content
The content container in WordPress plays the most important role. It holds the WordPress Loop which dictates the generation of content on the page depending upon the request by the user.
The Classic Theme has the simplest content structure:
prediv id=content
h2Date/h2
div class=post id=post-1
h3 class=storytitlePost Title/h3
div class=metaPost Meta Data/div
div class=storycontent
pWelcome to WordPress./p
/div
div class=feedbackComments (2)/div
/div
/div/pre
The Classic Theme hosts containers for the Date, Title, Post Meta Data, Post Content, and Feedback (number of comments). It also showcases a powerful feature. The ability to individually style a single post's look.
prelt;div class=post id=post-1/pre
The ttpost/tt CSS class selector applies the ttpost/tt styles to this container, but it also has an ID which is generated automatically by WordPress. The code looks like this:
prelt;div class=post id=post-lt;?php the_ID(); ?/pre
The use of the template tag ttthe_ID()/tt generates the ID number of the post. This provides a unique identifier for internal page links as well as for styles. This post could have a style for ttpost-1/tt, as could ttpost-2/tt. While it is a bit excessive to feature a style for every post, there may be a post or two you need to have look a little different. Some plugins may use this identifier to automatically change the look of different posts, too.
The Default Theme content container features a different look for multi-post views like the front page, categories, archives, and searches, and a different single post view for single posts. The multi-post view looks like this:
prediv id=content class=narrowcolumn
div class=post id=post-1
h2Post Title/h2
smallDate/small
div class=entry
pPost Content./p
/div
p class=postmetadataPost Meta Data Section/p
/div
div class=navigation
div class=alignleftPrevious Post/div
div class=alignrightNext Post/div
/div
/div/pre
There is a lot going on here. Let's break it down.
- ttlt;div id=content class=narrowcolumn/tt
- In the multi-post views, it features a ttclass=narrowcolumn/tt and in the single post views, it features ttclass=widecolumn/tt and the sidebar is not generated on that page, allowing the post to be viewed wide across the width of the content area.
- ttlt;div class=post id=post-1/tt
- Like the Classic Theme, this division sets up the style for ttpost/tt and the identifier for ttpost-X/tt, with ttX/tt representing the post's unique ID number. This allows for customizing the specific post's look.
- ttlt;h2Post Titlelt;/h2/tt
- This encompasses the post's title code, styled by the ttlt;h2gt;/tt tag.
- ttlt;smallDatelt;/small/tt
- The date code is surrounded and styled by the ttsmall/tt tag.
- ttlt;div class=entry/tt
- The post content is styled by a combination of the styles within the ttentry/tt CSS selectors and the paragraph tag.
- ttlt;p class=postmetadataPost Meta Data Sectionlt;/p/tt
- The Post Meta Data Section contains the data details about the post such as the date, time, and categories the post belongs to.
- ttlt;div class=navigation/tt
- The Next and Previous Links are styled in the ttnavigation/tt. They also include classes for ttalignleft/tt for the Previous Post and ttalignright/tt for the Next Post in chronological order.
These elements are shifted around in the single post view content structure:
prediv id=content class=widecolumn
div class=navigation
div class=alignleft/div
div class=alignright/div
/div
div class=post id=post-1
h2Post Title/h2
div class=entrytext
pPost content./p
p class=postmetadata alt
smallPost Meta Data/small
/p
/div
/div
/div/pre
The ttwidecolumn/tt class is featured to stretch the content across the page to fill in the absence of the sidebar. The ttnavigation/tt has been moved up to the top. And the Post Meta Data is now incorporated into the ttentrytext/tt parent container and styled differently with an ttalt/tt style added.
These two examples from the Default Theme give you just a glimpse into the myriad ways your WordPress site can be customized.
Comments
Comments may be featured on the single post view or in a popup window. The overall styles for the two sets of comments remain basically the same. The two template files are ttcomments.php/tt and ttcomments-popup.php/tt
Classic Theme Comments
preh2 id=comments1 Comment
a href=#postcomment title=Leave a commentraquo;/a/h2
ol id=commentlist
li id=comment-1
pHi, this is a comment./p
pciteComment by Person/cite /p
/li
/ol
p
a href='http://example.com/archives/name-of-post/feed/' abbr title=Really Simple SyndicationRSS/abbr feed for comments on this post./a a href=http://example.com/name-of-post/trackback/ rel=trackback TrackBack abbr title=Uniform Resource IdentifierURI/abbr /a
/p
h2 id=postcommentLeave a comment/h2 form action=http://example.com/blog/wp-comments-post.php
method=post id=commentform
p
input type=text name=author id=author value= size=22 tabindex=1 /
label for=author
smallName (required)/small
/label
/p
p
input type=text name=email id=email value= size=22 tabindex=2 /
label for=email
smallMail (will not be published) required)/small
/label
/p
p
input type=text name=url id=url value= size=22 tabindex=3 /
label for=url
smallWebsite/small
/label
/p
p
smallstrongXHTML:/strong List of Tags you
can use in comments/small
/p
p
textarea name=comment id=comment cols=100% rows=10 tabindex=4
/textarea
/p
p
input name=submit type=submit id=submit tabindex=5 value=Submit Comment /
input type=hidden name=comment_post_ID value=1 /
/p
/form
/div/pre
While individual sections of the comments feature styling reference, the Classic Theme has no general comment division or group style reference, one could be easily added.
- 35;comments h2
- Styles the title at the top of the comments list which says Comments 4 Leave a Comment, with the latter part of the sentence in a link that jumps to ttlt;h2 id=postcommentLeave a commentlt;/h2/tt.
- 35;comment-n :Comments are given a unique ID number, signified here by the letter ttn/tt. This allows them to be styled individually.
- 35;comments ol :This begins the ordered list of the comments, counting down from one, and sets the overall style of the comments list.
- 35;comments li :Style reference for each comment on the list.
- 35;comments p :This paragraph tag styles the actual comments on the comment list.
- 35;comment cite :This use of the ttcite/tt controls the look of the commenter's name. It usually states Name says: in the comments list.
- 35;comments h2 or #35;postcomment :The tth2/tt heading can be styled two ways, as tt#35;comments h2/tt or tt#35;postcomment/tt. The latter is used by the Leave a Comment link from the top of the comments section, too.
- 35;commentform :Style reference for the overall form for inputting comments. Each input area has it's own ID.
- 35;author :ID reference for the comment author's input area.
- 35;comments small :The ttlt;small/tt tag is used in several places in the Classic Theme. This usage surrounds the text in the comment submit form and the text for the list of tags that can be used in the comment.
- 35;email :ID reference for the comment author's email.
- 35;url :ID reference for the comment author's URL.
- 35;comment :ID reference for the comment input textarea. It does not style the final generated comment, just the input box.
- 35;comment #35;submit :There are two submit buttons in the Classic Theme, for search and comment submissions. This is the submit comment button.
Default Theme Comments
The Default Theme comments feature a loop query within the ttcomments.php/tt and ttcomments-popup.php/tt which changes some of the information depending upon if comments are open, closed, and any present. If the comments are open or closed and no comments have been made, this information will be displayed within the ttlt;h3 id=comments/tt tag.
preh3 id=commentsOne Response to Hello world!/h3
ol class=commentlist
li class=alt id=comment-1
cite
a href=http://example.org/ rel=external nofollowMr WordPress/a
/cite Says:br /
small class=commentmetadata
a href=#comment-1 title=Date and Time/a
/small
pHi, this is a comment./p
/li
/ol
h3 id=respondLeave a Reply/h3
form action=http://example.com/blog/wp-comments-post.php method=post id=commentform
p
input name=author id=author value= size=22 tabindex=1 type=text
label for=author
smallName (required)/small
/label
/p
p
input name=email id=email value= size=22 tabindex=2 type=text
label for=email
smallMail (will not be published) required)/small
/label
/p
p
input name=url id=url value= size=22 tabindex=3 type=text
label for=url
smallWebsite/small
/label
/p
p
smallstrongXHTML:/strong You can use these
tags:..../small
/p
p
textarea name=comment id=comment cols=100 rows=10 tabindex=4
/textarea
/p
p
input name=submit id=submit tabindex=5 value=Submit Comment type=submit
input name=comment_post_ID value=1 type=hidden
/p
/form /div/pre
While individual sections of the comments feature styling reference, the Default Theme has no general comment division or group style reference, though one could be easily added.
- h3 #35;comments
- Styles the ttlt;h3/tt tag for the number of responses to the post heading.
- 35;commentlist ol
- Styles the ordered list of the comments list.
- .alt li and #35;comment-n
- The comment list items have two style references. The first one is the class ttalt/tt and the second is the comment ID number signified here by the letter ttn/tt. This allows them to be styled individually.
- cite
- The tag ttcite/tt frames the Name says: and link to the comment author's URL.
- .commentmetadata small
- The ttlt;small/tt tag has a class of ttcommentmetadata/tt which allows the date and time of the post to be styled.
- ol #35;commentlist p
- Styles the paragraph within the ordered list of comments.
- 35;respond h3
- Styles the heading for Leave a Reply.
- 35;commentform :Style reference for the overall form for inputting comments. Each input area has it's own ID.
- 35;author :ID reference for the comment author's input area.
- 35;comments small :The ttlt;small/tt tag is used in several places in the Classic Theme. This usage surrounds the text in the comment submit form and the text for the list of tags' that can be used in the comment.
- 35;email :ID reference for the comment author's email.
- 35;url :ID reference for the comment author's URL.
- 35;comment :ID reference for the comment input textarea. It does not style the final generated comment, just the input box.
- 35;comment #35;submit :There are two submit buttons in the Classic Theme, for search and comment submissions. This is the submit comment button.
Popup Comments
The Classic and Default Themes' ttcomments-popup.php/tt template file is essentially the same. They use the layout for the Classic Theme comment structure. While the Classic Theme uses ttlt;h2/tt headings and the Default Theme uses ttlt;h3/tt headings for the title headings in their comments, in the ttcomments-popup.php/tt template file, they both use the ttlt;h2/tt heading tag.
prebody id=commentspopup h1 id=header/h1 h2 id=commentsComments/h2 ....Classic Theme commment section..... ...Classic Theme footer..../pre
The ttbody/tt tag sets the style for the overall page with tt#commentspopup/tt. The tth2/tt heading begins the comments section.
If you make modifications to the structure of the tags within the header and footer of the overall Theme, ensure those structural changes are applied to the comments popup template, especially if you will be releasing the Theme to the public.
Sidebar
As you saw with the Default Theme, the sidebar can be visible or not, depending upon the template file in use. The sidebar, in general, can be simple or complex. WordPress Themes often feature information within the sidebar in nested lists. There is a step-by-step guide for the sidebar at Customizing Your Sidebar and more information on Styling Lists with CSS, too.
In general, the WordPress sidebar features titles of the various sections within a list, with the section items in a nested list below the title.
The Classic Theme sidebar looks like this, with the links removed for simplification:
prediv id=menu
ul
li class=pagenavPages
ul
li class=page_itemContact/li
li class=page_itemAbout/li
/ul
/li
li id=linkcat-1h2Blogroll/h2
ul
liBlogroll Link 1/li
liBlogroll Link 1/li
liBlogroll Link 1/li
/ul
/li
li id=categoriesCategories:
ul
liCategory Link 1/li
liCategory Link 2/li
/ul
/li
li id=search
label for=sSearch:/label
form id=searchform method=get action=/index.php
div
input type=text name=s id=s size=15 /br /
input type=submit value=Search /
/div
/form
/li
li id=archivesArchives:
ul
liArchives Month Link 1/li
liArchives Month Link 2/li
/ul
/li
li id=metaMeta:
ul
liRSS Feed Link/li
liRSS Comments Feed Link/li
liXHTML Validator/li
liXFN Link/li
liWordPress Link/li
/ul
/li
/ul
/div/pre
Most of these are self-explanatory. Each set of links has its own CSS selector: Pages, categories, archives, search, and meta.
Pages and Link Categories
The Pages and Links category, labeled Blogroll, uses the ttlt;?php get_links_list(); ?/tt and ttlt;?php wp_list_pages(); ?/tt template tags which automatically generates a heading.
For the Links category, it generates an tth2/tt heading for that set of links. This means you can style the ttmenu h2/tt heading to look differently from the rest of the headings, or, if you want them to all look the same, make sure that the ttmenu h2/tt style matches the rest of the category styles which are not automatically generated.
The Pages template tag generates ttpagenav/tt as the heading and then identifies the pages in a new way. As a general list viewed on multi-post and single post views, the Page list items feature a ttclass=page_item/tt to style those links. When viewing an individual Page, that Page's link will change to ttclass=current_page_item/tt, which can then be styled to look differently from the rest of the Page links.
Categories, Archives, and Meta
The other sidebar section titles, categories, archives, meta, and others, do not use template tags which generate their own titles. These are set inside of PHP statements which print the text on the page. While these could be put inside of heading tags, WordPress uses the tt_e()/tt function to display or echo the text titles while also marking the text as a possible target for language translation. If you will be developing your theme for public release, using the echo functions is highly recommended.
You can style these individually or all the same. Some Themes, like the Default Theme, put all these in ttlt;h2/tt headings so the list headings will all look the same. Therefore, they may or may not use style references for each section. You may add them if you need them to change the look of each section of links.
Search Form
The search form is found within the ttsearchform.php/tt. It may be found in different locations within the sidebar. To style the overall search form, use the ttsearch/tt ID. Here is a list of the individual areas of the search form which may be styled by default. You may add style classes to gain more control over the look of your search form.
preli id=search
label for=sSearch:/label
form id=searchform method=get action=/index.php
div
input type=text name=s id=s size=15 /br /
input type=submit value=Search /
/div
/form/pre
- tt#search/tt
- The overall style for the search form.
- tt#search label/tt
- Used to style the ttlabel/tt tag, if necessary.
- tt#searchform/tt
- Used to style the form itself.
- tt#search div/tt
- This unlabeled ttdiv/tt is a child container of the parent container ttsearch/tt and maybe styled from within that selector.
- tt#searchform input/tt
- To style the input area for the search, this selector combination will work.
- tt#searchsubmit/tt
- Used by the Default Theme, this selector may be used to style the search or submit button.
The search form area, input, and button can be styled in many ways, or left with the default input and button look.
Meta Feed Links
The Meta links may be shown as text or icons representing the various links. The XHTML and CSS validation links may use the W3 icons. The various Feeds can also be represented as icons. Or left as text. It's up to you. Use of the feeds within your sidebar with text or icons is covered by the article WordPress Feeds.
Footer
The footer is found within the ttfooter.php/tt template file. In both the Default and Classic Themes, the footer contains little information.
Classic Theme
prep class=credit
!--15 queries. 0.152 seconds. --
cite
Powered by a href='http://wordpress.org'
title='Powered by WordPress, state-of-the-art
semantic personal publishing platform.'
strongWordPress/strong/a
/cite
/p /div/pre
The footer's content is styled with the ttcredit/tt class and the paragraph and ttcite/tt tags.
The tag displays the number of mysql queries used on the page and the time it took for the page to load, in HTML commented code. It is there for the administrator's convenience and use. It is only visible within the page's source code. If you would like to display this visible on the page, remove the comments. It's look will be influenced by the ttcredit/tt class style of the paragraph tag. On the template file, it looks like this:
prelt;!--lt;?php echo $wpdb-num_queries; ? queries. lt;?php timer_stop(1); ? seconds. --/pre
Default Theme
prediv id=footer
pBlogging in the WordPress World
is proudly powered by
a href=http://wordpress.org/WordPress/abr /
a href=feed:http://example.com/feed/Entries (RSS)/a
and
a href=feed:http://example.com/comments/feed/
Comments (RSS)/a.
!-- 18 queries. 0.186 seconds. --
/p
/div/pre
The Default Theme's footer is styled by the ttfooter/tt ID and the paragraph tag. While the footer area itself maybe styled by the ttfooter/tt, the paragraph tag controls the text within it. To style the paragraph tag differently within the ttfooter/tt than the rest of your page:
#footer p {styles}
Resources
- CSS
- Finding Your CSS Styles
- CSS Troubleshooting
- Using Themes
- Theme Development
- Designing Themes for Public Release
- WordPress Lessons
- Blog Design and Layout
- Stepping Into Template Tags
includeonlydiv style=clear:both; background-color:#EEEEFF; border:1px solid #CCCCCC; color:#000000; padding:7px; margin:0.5em auto 0.5em auto; vertical-align:middle;This article is marked as in need of editing. You can help Codex by editing it./div/includeonlynoinclude
Description
This Template is used by Codex:Template Messages.
Usage
pre 已侦测回归模板: Template:Message /pre
Result
已侦测回归模板: Template:Message
/noinclude

