The specific implementation steps based on WordPress theme _php Tutorial

Source: Internet
Author: User
Tags create index
Copy CodeThe code is as follows:
/*
Create MyTheme folder under Themes, wp-content, root directory to create a new theme template

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

Open style.css File input
*/
?>
/*
Theme Name: Fill in the title here
Theme URI: Here to fill out the theme of the URL, not just fill in your blog URL it
Description: Here is a short introduction to the topic
Author: Author name
Author URI: Author's URL
Version: Revision number
Tags: tags, multiple comma separated by half-width
*/
/*
Topic related information can be seen in background theme management, and the content of theme information in CSS must be enclosed in annotation notation.

Find a 300*225 PNG image, named Screenshot.png in the theme directory (MyTheme folder), you can see the preview picture of the new theme in the topic Management page

==================================================header===================================================== ===========
You can put the same header content of the site in a header file, in the subject directory of the new header.php file into which input 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 in the header.php to the current PHP file

/*
On the topic Management page, the content of the header.php page is introduced in a live preview of the theme in the 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 the title are not the same, and the title of the settings will also directly affect the effect of SEO, so it should be carefully set. The following provides a SEO optimization of the title of the wording,
Add on header.php page
*/
?>
<title><br><?php<br>if (Is_home ()) {//Is_home () return true<br> bloginfo (' name ') when the current page is a home,//Return to site title <b r> echo "-";<br> bloginfo (' description '); Returns the site subtitle, site description <br>} elseif (Is_category ()) {//Is_category () The current page is a category page when the true<br> Single_cat_title () is returned; < ;br> echo "-";<br> bloginfo (' name '); <br>} elseif (Is_single () | | Is_page ()) {//Is_single () returns True when the current page is a single article page. Is_page () returned when the current page is a single page true<br> single_post_title (); <br>} elseif (Is_search ()) {//Is_search () The current page is returned as a search page true<br> echo "Search results";<br> echo "-";<br> bloginfo (' name '); <br>} elseif (is_404 ()) { is_404 () The current page is 404 pages back true<br> echo ' page not found! '; <br>} else {<br> wp_title ("', true);<br>}<br>?><br></title>
/*
The above added PHP code to use the conditional judgment, for different pages with different title
Add a default Style.css file to the header.php page
*/
?>

/*
Bloginfo (' Stylesheet_url '); Returns the absolute URL path of the subject's 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 a style picture in a template, such as
Http://localhost/wordpress/wp-content/themes/mytheme
Add the Pingback notification feature on the header.php pageAdd code inside the tag:
*/
?>

/*
Add a subscription feed link on the header.php pageTag to add:
*/
?>


/*
Add Wp_head, some plug-ins need to add some JS or CSS in the head of the Web page, to allow these plug-ins to work properly, but also for better compatibility of themes, should add wp_head () function
header.php pagetag to add the
*/
?>

/*
Displays the menu bar, which lists the category and page pages only in the menu bar, and you can list what you want according to your preferences. In header.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 a footer.php in the theme directory and use it in index.php or pages that you want to invoke the footer.php page
*/
Get_footer ();//function and Get_header () similar
/*
Add Wp_footer on the footer.php page for improved compatibility
*/
Wp_footer ();
/*
Wp_footer () and Wp_head () are mostly used to improve the theme compatibility, after all, there are a lot of plug-ins to output something in the footer to work properly.
*/
==================================================sidebar==================================================== ============
/*
Create a new sidebar.php page in the theme directory and add it in index.php or the page where you want to call the sidebar.php page
*/
Get_sidebar ();
/*
Invoke sidebar.php page Content
To make WordPress background---appearance--widgets, you can normally drag gadgets to the sidebar
The list format on the sidebar.php page should be formatted as follows
*/
?>

if (! function_exists (' Dynamic_sidebar ') | |! Dynamic_sidebar (' First_sidebar '))://first_sidebar is the widget name, and function The corresponding widget name is the same in s.php
?>

Category Catalogue






if (! function_exists (' Dynamic_sidebar ') | |! Dynamic_sidebar (' Second_sidebar ')):
?>

Latest Articles



      $posts = get_posts (' numberposts=6&orderby=post_date ');
      foreach ($posts as $post) {
      Setup_postdata ($post);
      Echo '
    • ' . Get_the_title (). '
    • ';
      }
      $post = $posts [0];
      ?>


if (! function_exists (' Dynamic_sidebar ') | |! Dynamic_sidebar (' Third_sidebar ')):
?>

Tag Cloud




if (! function_exists (' Dynamic_sidebar ') | |! Dynamic_sidebar (' Fourth_sidebar ')):
?>

Article archive







/*
At the same time, create the contents of the functions.php file in the theme directory
*/
/** Widgets */
if (function_exists (' Register_sidebar ')) {
Register_sidebar (Array (
' Name ' = ' First_sidebar ',//name is to give the widget its own name so that it can be called separately in sidebar.php. So just take two names for the two widgets.
' Before_widget ' + ',//statement that defines the front and back identifiers of the widget content
' After_widget ' = ',
' Before_title ' = '

',//statement that defines the front and back identifiers of the widget 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, you can drag widgets to the sidebar as you would normally with the widgets, such as WordPress background.

Make a list of index.php articles
Example
*/
?>





"Rel=" Bookmark ">



• •




/images/610x150.gif "/>




"Class=" button right "> Read full text







> ', 0);?>



Not found


No articles found!




/*
Have_posts (); Determine if there is a next article
The_post (); Change current article point to next article

The_permalink (); The connection address currently pointing to the article
The_title (); Title currently pointing to the article
The_tags (' Tags: '); Label currently pointing to the article
Comments_popup_link (' 0 reviews ', ' 1 comments ', '% comments ', ' ', ' comments closed '); Displays a comment link that prints the current point to the article
Edit_post_link (' edit ', ' • ', '); Currently pointing to the article, showing the edit link that is currently pointing to the article
The_excerpt (); Currently point to the article, as long as the article in the "Summary" box to fill in the summary, on the home page is a summary, if not fill out the full text!
The_content (' Read the full text ... '); Used to export the current article to the full text unless used in the article
The_permalink (); Returns the connection address currently pointing to the article read full text
Previous_posts_link (' << view new article ', 0); Show the print current display list paging connection (number of articles per page depending on the number of articles that can be displayed per page in background settings)
Next_posts_link (' View old articles >> ', 0); Show 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 the same as the production process, just need to add a function in functions.php

Single article page single.php, you can add what you want to show here according to the index.php page

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

Common functions
Get_avatar ($comment, 48); Get the reviewer's gravatar avatar, size 48 * 48
Comment_reply_link () Reply to the message link
Get_comment_time (' y-m-d h:i '); Get Comment Release time
Edit_comment_link (' modification '); Link for administrator to modify comments
Comment_text () Output Comment content

Is_user_logged_in () Determine if the user is logged in
Wp_login_url (Get_permalink ()); Blog Login Address
Get_comment_author_link () to get the reviewer's blog address
$comment _author Read the cookie and automatically help the user fill in the user name if the user has previously commented
$comment _author_email Read the cookie and automatically help the user fill in the email if the user has previously commented
$comment _author_url Read the cookie and automatically help users fill out the blog address if the user has previously commented
Do_action (' Comment_form ', $post->id) This function is reserved for some plugins
Wp_logout_url (Get_permalink ()) sign-out link
*/

/*
Create a template file
*/


/*
Template Name: Self-built templates
*/

/*
Template file to add such as the comment code, template file name arbitrary, when creating a new page template selection to display the self-built template to use this template
Can add the desired template style and page content, the new page only fill in the title does not write content, quite create a page link address, the new page exists data prefix _posts table
After you get to the page address, you can add parameters after the address is written, and you can receive it via $_get,$_post when you go to the page
Can be a separate table storage address, and the type of page, and the page face parent relationship, in the plug-in control


WordPress fixed Link
If modifying WordPress permalink is not good, open the option in 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 the 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 inside the PHP priority.

Creating gadgets
Create a new custom file under the theme directory mytool.php filename arbitrary, arbitrary content
Then add the following code in the functions.php
*/
Register_sidebar_widget ("My Gadget", "Mytool_fun"); My gadget displays the gadget name for the background, mytool_fun the method name for introducing the content of the self-built gadget page
function Mytool_fun () {
Include (TemplatePath. "/mytool.php");
}
/*
You can see the custom gadget in the background gadget and add it to the foreground page to see the contents of the self-built gadget page
*/
?>

http://www.bkjia.com/PHPjc/327175.html www.bkjia.com true http://www.bkjia.com/PHPjc/327175.html techarticle Copy the code as follows: PHP/* Create a MyTheme folder under the root directory-Wp-content-themes Create a new theme template in MyTheme directory to create index.php, style.css two ...

  • 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.