Specific implementation steps based on wordpress theme production

  • 2020-06-03 05:58:29
  • OfStack


<?php
/*
 In the root directory  -> wp-content -> themes  create mytheme A folder is used for creating new theme templates 
 in mytheme Create under directory  index.php  . style.css  Two files in wp The background   appearance -> The theme   You can see the theme you just created 
 Open the style.css File input 
*/
?>
/*
Theme Name:  Fill in the subject name here 
Theme URI:  Fill in the url of the subject, if not your blog url 
Description: Here is a brief introduction to the subject 
Author:  The author's name 
Author URI:  Author's website 
Version:  The version number 
Tags:  Tags separated by half - corner commas 
*/
<?php
/*
 You can see theme-related information in the background theme management. css The subject information content must be enclosed in comment symbols 
 Looking for a 1 a 300*225 the png Picture. I'll call it  screenshot.png  Under the subject directory ( mytheme In the Theme manager page, you can see the preview image of the new theme 
//==================================================header================================================================
 You can put the same header content on your site 1 In the header file, create in the theme directory  header.php  The file enters input into it   system 1 Head contents of 
 in  index.php  Or you want to call that header.php In the page of the page   The input 
*/
get_header(); //get_header() Is equivalent to header.php Copy the code in php file 
/*
 In the Theme management page, the theme live preview, is opened by default  index.php  It can be introduced from the page  header.php  The content of the page 
header.php  Will be included by all template pages (home page, category page, page, TAB, etc.), so  header.php  Code should be dynamic. 
 Different page title It is not 1 Sample, and title The Settings of the SEO So it should be set carefully here. The following offer 1 Kind of SEO Optimization of the title Writing, 
 in header.php The page to add 
*/
?>
<title>
<?php
if (is_home ()) { // is_home()  Returns when the current page is the home page true
    bloginfo ( 'name' ); //  Return site title 
    echo " - ";
    bloginfo ( 'description' ); //  Returns the site subtitle, site description 
} elseif (is_category ()) { // is_category()  Returns when the current page is a category page true
    single_cat_title ();
    echo " - ";
    bloginfo ( 'name' );
} elseif (is_single () || is_page ()) { // is_single()  Returns when the current page is a single article page true  .  is_page()  Returns when the current page is a single page true
    single_post_title ();
} elseif (is_search ()) { // is_search()  The current page is returned when searching for a page true
    echo " The search results ";
    echo " - ";
    bloginfo ( 'name' );
} elseif (is_404 ()) { // is_404()  Current page is 404 Page to return to true
    echo ' Page not found !';
} else {
    wp_title ( '', true );
}
?>
</title>
<?php
/*
  Added above php The code USES conditional judgment, which is different for different pages title
 in  header.php  Add a default to the page  style.css  file 
*/
?>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
<?php
/*
bloginfo('stylesheet_url'); The theme default is returned style.css File absolute url path, such as 
http://localhost/wordpress/wp-content/themes/myTheme/style.css
bloginfo('template_url'); Returns the absolute url path of the theme directory, which can be used to link style images in templates, such as 
http://localhost/wordpress/wp-content/themes/mytheme
 add  pingback  Notification function in header.php page  <head>  Add code in the tag: 
*/
?>
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<?php
/*
 Add a subscription feed Links, in header.php page  <head>  Add: 
*/
?>
<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 be added in the header 1 some js or css For these plugins to work properly and for theme compatibility, you should add them wp_head() function 
header.php  page  <head>  Add to tag 
*/
?>
<?php wp_head(); // Used to contain WordPress Program output header information  ?>
<?php
/*
 Displays the menu bar, where only category pages and are listed in the menu bar page Page, you can list by preference what you want. header.php In the 
*/
?>
<ul id="navigation" class="grid_8">
    <?php wp_list_categories(); // Used to list blog categories  ?>
    <?php wp_list_pages('depth=1&title_li=0&sort_column=menu_order'); // Use to list blog pages without parameters  ?>
</ul>
<?php
//==================================================footer================================================================
/*
footer.php with header.php Similarly, the purpose of writing this file is also to simplify the code, improve code reuse. 
 Create in the theme directory  footer.php  In the  index.php  Or you want to call that footer.php Used in pages of pages 
*/
get_footer();// Function and get_header() similar 
/*
 in footer.php The page to add  wp_footer Improve compatibility 
*/
wp_footer();
/*
wp_footer() and wp_head() More or less, it's all for theme compatibility, since there are a lot of plugins to output in the footer 1 Things that work. 
*/
//==================================================sidebar================================================================
/*
 Create a new one in the theme directory  sidebar.php  The page,  index.php  Or you want to call that sidebar.php Add to the page of the page 
*/
get_sidebar();
/*
 call  sidebar.php  The page content 
 In order to make WordPress The background  ->  appearance  ->  Widgets. Drag widgets to the sidebar normally 
 in  sidebar.php  The list format of the page should follow the following example format 
*/
?>
<div>
    <?php
    if (! function_exists ( 'dynamic_sidebar' ) || ! dynamic_sidebar ( 'First_sidebar' )) ://First_sidebar for widget Name, want and functions.php In the corresponding widget name The same 
    ?>
    <h4> catalog </h4>
    <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' )) :
    ?>
    <h4> The latest article </h4>
    <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' )) :
    ?>
    <h4> A tag cloud </h4>
    <p><?php wp_tag_cloud('smallest=8&largest=22'); ?></p>
    <?php endif; ?>

    <?php
    if (! function_exists ( 'dynamic_sidebar' ) || ! dynamic_sidebar ( 'Fourth_sidebar' )) :
    ?>
    <h4> The article archive </h4>
    <ul>
    <?php wp_get_archives('limit=10'); ?>
    </ul>
    <?php endif; ?>
</div>
<?php
/*
 Also create in the theme directory  functions.php  File content is 
*/
/** widgets */
if( function_exists('register_sidebar') ) {
    register_sidebar(array(
        'name' => 'First_sidebar', //name Is to give widget Specify the respective names , In order to sidebar.php Respectively call in . So you just have to give these two widget Just have two names. 
        'before_widget' => '', // define Widget A statement for an identifier before and after the content 
        'after_widget' => '',
        'before_title' => '<h4>', // define Widget A statement for an identifier before and after a title 
        'after_title' => '</h4>'
    ));
    register_sidebar(array(
        'name' => 'Second_sidebar',
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '<h4>',
        'after_title' => '</h4>'
    ));
    register_sidebar(array(
        'name' => 'Third_sidebar',
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '<h4>',
        'after_title' => '</h4>'
    ));
    register_sidebar(array(
        'name' => 'Fourth_sidebar',
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '<h4>',
        'after_title' => '</h4>'
    ));
}
/*
 such WordPress The background  ->  appearance  ->  Widgets can be dragged to the sidebar as normal 
 making index.php  The article lists 
 example 
*/
?>
<div class="grid_8">
    <!-- Blog Post -->
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="post">
        <!-- Post Title -->
        <h3 class="title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h3>
        <!-- Post Data -->
        <p class="sub"><?php the_tags(' Tags: ', ', ', ''); ?> &bull; <?php the_time('Y years n month j day ') ?> &bull; <?php comments_popup_link('0  comments ', '1  comments ', '%  comments ', '', ' Comments are closed '); ?><?php edit_post_link(' The editor ', ' &bull; ', ''); ?></p>
        <div class="hr dotted clearfix">&nbsp;</div>
        <!-- Post Image -->
        <img class="thumb" alt="" src="<?php bloginfo('template_url'); ?>/images/610x150.gif" />
        <!-- Post Content -->
        <?php //the_excerpt(); ?>
        <?php the_content(' To read the full article ...'); ?>
        <!-- Read More Button -->
        <p class="clearfix"><a href="<?php the_permalink(); ?>" class="button right"> To read the full article </a></p>
    </div>
    <div class="hr clearfix">&nbsp;</div>
    <?php endwhile; ?>

    <!-- Blog Navigation -->
    <p class="clearfix"><?php previous_posts_link('&lt;&lt;  View new articles ', 0); ?> <span class="float right"><?php next_posts_link(' View old articles  &gt;&gt;', 0); ?></span></p>
    <?php else : ?>
    <h3 class="title"><a href="#" rel="bookmark"> Not found </a></h3>
    <p> No articles found! </p>
    <?php endif; ?>
</div>
<?php
/*
have_posts();        Determine if there is 1 An article 
the_post();          Change the current article to point to the bottom 1 An article 
the_permalink();     The link address currently points to the article 
the_title();         Currently points to the title of the article 
the_tags(' Tags: ');   The current tag pointing to the article 
comments_popup_link('0  comments ', '1  comments ', '%  comments ', '', ' Comments are closed ');     Displays the link that prints the comment currently pointing to the article 
edit_post_link(' The editor ', ' &bull; ', '');     Currently pointing to the article, displays the edit link that prints the current pointing to the article 
the_excerpt();                  Currently points to the article, as long as it is in the context of writing the article " Abstract " Fill in the box, the first page is the summary, if you do not fill in the output full text! 
the_content(' To read the full article ...');     Used to output the current point to the full article unless used in the article <!-- more -->
the_permalink();               Returns the link address currently pointing to the article to read the full text 
previous_posts_link('&lt;&lt;  View new articles ', 0);  Display prints the current display list paging connection ( The number of posts per page depends on the number of posts per page set in the background )
next_posts_link(' View old articles  &gt;&gt;', 0);       Display prints the current display list paging connection 
the_time('Y years n month j day '); Display date as  1999 years 5 month 1 day 
 In addition, there is a template for archiving pages archive.php , with index.php The making process is complete 1 Like, just need in functions.php add 1 A function 
 Single article page single.php , can be based on index.php The page adds what it wants to display here 
page.php  So pages, all pages on a blog are pages, in this case pages 1 A separate page, such as " about " , " contact " Wait, yes WordPress The background   �   Page, page to add and modify. 
 You can add the contents of this page based on previous functions 
*/
while (have_posts()) :
    the_post(); update_post_caches($posts);
endwhile;
/*
update_post_caches($posts);   This function resets the article cache and is not logged. Only at the top of the page 1 When the subloop retrieves a subset of the article, the 2 A secondary loop can perform a basic loop. 
 Commonly used functions 
get_avatar($comment, 48);        Get commenter's gravatar Head, size is 48 * 48
comment_reply_link()                  A link to reply to your message 
get_comment_time('Y-m-d H:i');        Get the comment Posting time 
edit_comment_link(' Modify the ');            The administrator modifies the link to the comment 
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()             Used to get the commenter's blog address 
$comment_author                       read cookie , automatically help the user fill in the user name if the user has previously commented 
$comment_author_email                 read cookie If the user has previously posted a comment, the user is automatically helped to fill it out Email
$comment_author_url                   read cookie , automatically helps the user fill in the blog address if the user has previously commented 
do_action( ' comment_form', $post->ID)  This function is reserved for certain plug-ins 
wp_logout_url(get_permalink())        Log out of the login link 
*/
/*
 Create template file 
*/

/*
 Template Name:  Self-built template 
*/
/*
  Add the above comment code in the template file, the template file name is arbitrary, the template selection can be displayed when the new page   Self-built template   To use this template 
 You can add the desired template style and page content , When you create a new page, just fill in the title and don't write the content 1 Page link address, new page exists   Data prefix _posts  In the table 
 After the page address is obtained, parameters can be added later when the address is written, and can be passed when going to the page $_GET,$_POST receive 
 You can build it separately 1 The storage address of the table, and the page type it belongs to, and the parent relationship of each page face are controlled in the plug-in 

wordpress Fixed link 
 If you change wordpress Fixed links are not working well in apache The configuration file  httpd.conf  Open options in 
#LoadModule rewrite_module modules/mod_rewrite.so
 In front of the  #  Get rid of it and get rid of all of it  AllowOverride None  to  AllowOverride all
 If it is not Apache The server, the server IIS To debug, you have to install 1 A" ISAPI_Rewrite3_0069_Lite.msi Filter, and then in the site Settings will PHP Make it a priority. 
 Create widgets 
 Create a new custom file in the theme directory  mytool.php  Any file name, any content 
 Then, in  functions.php  Add the following code to 
*/
register_sidebar_widget ( " My gadget ", "mytool_fun" ); // " My gadget " Display the gadget name for the background, mytool_fun A method name for introducing the content of your own widget page 
function mytool_fun() {
    include (TEMPLATEPATH . "/mytool.php");
}
/*
 Custom widgets can be seen in the background widgets, after adding, the front page can see the content of the self-built widgets page 
*/
?>


Related articles: