The concrete realization step _php technique based on WordPress theme production

Source: Internet
Author: User
Tags create index

Copy Code code as follows:

<?php
/*
Create a MyTheme folder under the root directory-> wp-content-> themes to store a new theme template

Create index.php in the MyTheme directory, style.css two files, you can see the theme you just created in the WP background appearance-> theme

Open style.css File input
*/
?>
/*
Theme Name: Fill in the title here
Theme URI: Fill in the URL of the topic introduction here, do not fill in your blog URL
Description: Here's a brief introduction to the subject.
Author: Author name
Author URI: Author's URL
Version: Edition number
Tags: tags, multiple with a half-angle comma separated
*/
<?php
/*
In the background topic management can see the topic related information, the topic information content in the CSS must enclose with the annotation symbol

Find a 300*225 png picture, named Screenshot.png in the subject directory (MyTheme folder), and you'll see a preview of the new theme in the theme management page

==================================================header===================================================== ===========
You can put the same header content in a header file, in the subject directory under the new header.php file input to enter the unified header content
In index.php or the page where you want to call the header.php page, enter
*/

Get_header (); Get_header () is equivalent to copying the code from header.php to the current PHP file.

/*
In the Theme Management page, this topic is in real time preview, the content of the header.php page can be introduced by default open index.php page
Header.php will be included in all template pages (home page, category page, page, tab, etc.), so the code in header.php should be dynamic.
Different pages of title are not the same, and the title of the setting will directly affect the effect of SEO, so here should be carefully set. The following provides a title for SEO optimization,
Add on header.php page
*/
?>
<title>
<?php
if (Is_home ()) {//Is_home () returns True when the current page is home page
Bloginfo (' name '); Return to site title
echo "-";
Bloginfo (' description '); Return to site subtitle, site description
ElseIf (Is_category ()) {//Is_category () returns True when the current page is a category page
Single_cat_title ();
echo "-";
Bloginfo (' name ');
ElseIf (Is_single () | | | is_page ()) {//Is_single () returns True when the current page is a single story page. Is_page () returns True when the current page is a single page
Single_post_title ();
ElseIf (Is_search ()) {//Is_search () returns True when the current page is a search page
echo "Search results";
echo "-";
Bloginfo (' name ');
ElseIf (is_404 ()) {//is_404 () returns True when the current page is 404 pages
Echo ' page not found! ';
} else {
Wp_title (', true ');
}
?>
</title>
<?php
/*
The above added PHP code using the conditional judgment, for different pages using different title
Add a default Style.css file to the header.php page
*/
?>
<link rel= "stylesheet" href= "<?php bloginfo (' Stylesheet_url ')?>" type= "Text/css" media= "" Screen "/>
<?php
/*
Bloginfo (' Stylesheet_url '); Returns the absolute URL path of the theme default Style.css file, such as
Http://localhost/wordpress/wp-content/themes/myTheme/style.css
Bloginfo (' Template_url '); Returns the absolute URL path to the theme directory, which can be used to connect style pictures in the template, such as
Http://localhost/wordpress/wp-content/themes/mytheme
Add the Pingback notification feature to add code to the header.php page */
?>
<link rel= "Pingback" href= "<?php bloginfo (' Pingback_url ');?>"/>
<?php
/*
Add a subscription feed link and add it to the header.php page */
?>
<link rel= "Alternate" type= "Application/rss+xml" title= "RSS 2.0-All articles" href= "<?php Echo get_bloginfo (' Rss2_url ') ;?> "/>
<link rel= "Alternate" type= "Application/rss+xml" title= "RSS 2.0-All Comments" href= "<?php bloginfo (' Comments_rss2_url ' );?> "/>
<?php
/*
Add Wp_head, some plug-ins need to add some JS or CSS in the head of the page, to allow these plug-ins to work properly, but also to improve the compatibility of topics, should add Wp_head () function
header.php pages */
?>

<?php Wp_head (); Used to include WordPress program output header information?>

<?php
/*
Displays the menu bar, where only the category and page pages are listed in the menu bar, and you can list what you want according to your preferences. In header.php
*/
?>
<ul id= "navigation" class= "Grid_8" >
<?php wp_list_categories (); Use to list blog category pages?>
<?php wp_list_pages (' Depth=1&title_li=0&sort_column=menu_order '); Used to list the blog page, you can not fill in the parameters?>
</ul>
<?php
==================================================footer===================================================== ===========
/*
Footer.php is similar to header.php, and the purpose of writing this file is to streamline the code and improve the reusability of the code.
Create footer.php in the topic directory, index.php or the page that you want to call the footer.php page to use
*/
Get_footer ()//function and Get_header () similar
/*
Add Wp_footer to footer.php page to improve compatibility
*/
Wp_footer ();
/*
Wp_footer () and Wp_head () are similar, are used to improve the theme of compatibility, after all, there are many plug-ins to output a few things in the footer to work properly.
*/
==================================================sidebar==================================================== ============
/*
Create a new sidebar.php page in the subject directory, add in index.php or the page that you want to call the sidebar.php page
*/
Get_sidebar ();
/*
Call sidebar.php page Content
In order to make the WordPress background-> appearance-> gadget, you can drag the gadget to the side bar normally
The list format for the sidebar.php page should be in the following example format
*/
?>
<div>
<?php
if (! function_exists (' Dynamic_sidebar ') | | |! dynamic_sidebar (' First_sidebar '))://first_sidebar for widget name, and function The corresponding widget name in the s.php is the same
?>
<ul>
<?php wp_list_categories (' Depth=1&title_li=&orderby=id&show_count=0&hide_empty=1&child_ Of=0 ');?>
</ul>
<?php endif;?>


    <?php
    if (! function_exists (' Dynamic_sidebar ') | |! dynamic_ Sidebar (' Second_sidebar '):
   
        <ul>
    <?php
    $posts = get_posts (' numberposts= 6&orderby=post_date ');
    foreach ($posts as $post) {
        setup_postdata ($ Post);
        Echo ' <li><a href= '. Get_permalink (). ' > '. Get_the_title (). ' </a></li> ';
   }
    $post = $posts [0];
   
    </ul>
    <?php endif


<?php
if (! function_exists (' Dynamic_sidebar ') | |! Dynamic_sidebar (' Third_sidebar ')):
?>
<p><?php wp_tag_cloud (' smallest=8&largest=22 ');?></p>
<?php endif;?>


<?php
if (! function_exists (' Dynamic_sidebar ') | |! Dynamic_sidebar (' Fourth_sidebar ')):
?>
<ul>
<?php wp_get_archives (' limit=10 ');?>
</ul>
<?php endif;?>
</div>
<?php
/*
Also create the functions.php file contents under the theme directory as
*/
/** Widgets * *
if (function_exists (' Register_sidebar ')) {
Register_sidebar Array (
' Name ' => ' First_sidebar ',//name specifies the name of the widget to be called separately in sidebar.php. So just give the two widgets two names.
' Before_widget ' => ',//define the statement of the front and back identifiers of the widget contents
' After_widget ' => ',
' Before_title ' => ' ' After_title ' => ' ));
Register_sidebar Array (
' Name ' => ' Second_sidebar ',
' Before_widget ' => ',
' After_widget ' => ',
' Before_title ' => ' ' After_title ' => ' ));
Register_sidebar Array (
' Name ' => ' Third_sidebar ',
' Before_widget ' => ',
' After_widget ' => ',
' Before_title ' => ' ' After_title ' => ' ));
Register_sidebar Array (
' Name ' => ' Fourth_sidebar ',
' Before_widget ' => ',
' After_widget ' => ',
' Before_title ' => ' ' After_title ' => ' ));
}
/*
This way the WordPress background-> appearance-> gadgets, you can drag the gadget to the side bar normally

Make a list of index.php articles
Example
*/
?>
<div class= "Grid_8" >
<!--Blog Post-->
<?php if (have_posts ()): while (Have_posts ()): The_post ();?>
<div class= "POST" >
<!--Post Title-->

<!--Post Data-->
<p class= "Sub" ><?php the_tags (' Tags: ', ', ', '); > <?php the_time (' Y year N-month J-day ')? > <?php Comments_pop Up_link (' 0 comments ', ' 1 reviews ', '% comments ', ', ' comments closed ');? ><?php edit_post_link (' edit ', ' ', ', ');?></p>
<div class= "hr dotted Clearfix" > </div>
<!--Post Image-->
/images/610x150.gif "/>
<!--Post Content-->
<?php//the_excerpt ();?>
<?php the_content (' Read the full text ... ');?>
<!--Read more Button-->
<p class= "Clearfix" ><a href= "<?php the_permalink ()?>" class= "button right" > read the full text </a></p >
</div>
<div class= "hr Clearfix" > </div>
<?php Endwhile;?>

<!--Blog navigation-->
<p class= "Clearfix" ><?php previous_posts_link (' << view new article ', 0);?> <span class= "float Right" > <?php Next_posts_link (' View old articles >> ', 0);?></span></p>
<?php Else:?>

<p> did not find any articles! </p>
<?php endif;?>
</div>
<?php
/*
Have_posts (); To determine if there is a next article
The_post (); Change the current article to point to the next article

The_permalink ();    The connection address that is currently pointing to the article
The_title ();        Current point to the title of the article
The_tags (' Tags: ');  the current label to the article
Comments_popup_link (' 0 comments ', ' 1 comments ', '% comment ', ', ' comment closed ');     Display Print current comment link to article
Edit_post_link (' edit ', ' • ', ');    currently points to an article that prints the edit link that is currently pointing to the article
The_ Excerpt ();                 The current point to the article, as long as the article in the "Summary" box to fill in the summary, on the home page is the summary, if not fill out the full text of the output!
The_content (' Read the full text ... ');    is used to output the current point to the full text, unless the article used <!--more;
The_permalink ();               return to the current connection address to read the full text of the article
Previous_posts_ Link (' << view new article ', 0); Display print current display list paging connection (the number of articles per page depends on the number of articles that can be displayed per page in the background)
Next_posts_link (' View old articles >> ', 0);      Display print current display list paging connection
The_time (' Y year n Month J Day '); show date as May 1, 1999

In addition, there is an archive page template archive.php, and index.php process exactly the same, just need to add a function in functions.php

Single post page single.php, you can add what you want to display based on the index.php page

Page.php is the page, all the pages on the blog are pages, here refers to a separate page of the page, such as "about", "contact" and so on, can be in the WordPress background-page, add changes to the page, and so on.
You can add this page based on the previous function
*/
while (Have_posts ()):
The_post (); Update_post_caches ($posts);
Endwhile;
/*
Update_post_caches ($posts); This function resets the article cache and is not logged. The second loop performs the basic loop only when the first iteration of the page retrieves a subset of the article.

Commonly used functions
Get_avatar ($comment,);       gets the Gravatar avatar of the reviewer, the size is the
Comment_ Reply_link ()                  Reply to the link to the message
Get_comment_time (' y-m-d h:i ');       get comment release time
Edit_comment_link (' modify ' ;           Administrator to modify comments
Comment_text ()                          Output Comment content

Is_user_logged_in () to determine whether a user is logged in
Wp_login_url (Get_permalink ()); Blog Login Address
Get_comment_author_link () to get the reviewer blog address
$comment _author read cookies and automatically help users fill in user names if they have commented previously
$comment _author_email read cookies and automatically help users fill out emails if they have previously commented
$comment _author_url read cookies and automatically help users fill out their blog address if the user has commented previously
Do_action (' Comment_form ', $post->id) This function reserves for some plug-ins
Wp_logout_url (Get_permalink ()) Exit link for Login
*/

/*
Create a template file
*/


/*
Template Name: Self-built templates
*/

/*
In the template file, add the annotation code above, the template file name is arbitrary, when the new page is selected, the template can display the template to use this template
You can add the template style and page content you want, when you create a new page, just fill in the title and not write the content, quite creating a page link address, a new page exists in the Data prefix _posts table
When you get to the page address, you can add parameters after the address, and you can go to the page by $_get,$_post to receive
Can be a separate table to store the address, and the type of page, and the page face of the parent-child relationship, in the plug-in control


WordPress fixed Link
If modifying the WordPress fixed link is not good, open the option in the Apache config file httpd.conf
#LoadModule Rewrite_module modules/mod_rewrite.so
Remove the front # and change all allowoverride none to allowoverride all
If it is not Apache server, but the use of IIS debugging, then you have to install a "isapi_rewrite3_0069_lite.msi" filter, and then in the site settings will be placed in the PHP priority.

Creating gadgets
Create a new custom file in the subject directory mytool.php file name arbitrary, content arbitrary
Then add the following code in the functions.php
*/
Register_sidebar_widget ("My Gadgets", "Mytool_fun"); "My gadgets" displays the gadget name in the background, Mytool_fun the method name for introducing the content of the self-built widget page
function Mytool_fun () {
Include (TemplatePath. "/mytool.php");
}
/*
In the background gadget can see the custom gadget, after adding, the foreground page can see the content of the self-built gadget page
*/
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.