6 years ago (2015-01-13)  Hundred Encyclopedias |   First to comment  9 
post score 0 times, average 0.0

WordPress template basic file

Template base file (at your site root /wp-content/themes/)

Style.css stylesheet file index.php home page single.php log single page file page.php page file archvie.php category and date archive page file searchform.php search form file search.php search page file comments.php message zone file (including message list and message box) 404.php 404 error page header.php web header file sidebar.php web sidebar file footer.php bottom page file

WordPress Header Head PHP code (Note: This is the PHP code between <head> and </head>)

<?php bloginfo('name'); ?> Site title <?php wp_title(); ?> Log or page title <?php bloginfo('stylesheet_url'); ?> Relative address of WordPress theme stylesheet file style.css <?php bloginfo('pingback_url'); ?> WordPress blog's Pingback address <?php bloginfo('template_url'); ?> WordPress theme file relative address <?php bloginfo('version'); ?> Blog WordPress Version <?php bloginfo('atom_url'); ?> WordPress blog's Atom address <?php bloginfo('rss2_url'); ?> WordPress blog's RSS2 address <?php bloginfo('url'); ?> WordPress blog Absolute address <?php bloginfo('name'); ?> Name of WordPress blog <?php bloginfo('html_type'); ?> HTML version of website <?php bloginfo('charset'); ?> Character encoding of website format

WordPress body template PHP code

<?php the_content(); ?> Log content <?php if(have_posts()) : ?> Check if there is a log <?php while(have_posts()) : the_post(); ?> If yes, all logs are displayed <?php endwhile; ?> End PHP function "while" <?php endif; ?> End PHP function "if" <?php get_header(); ?> Content of header.php file <?php get_sidebar(); ?> The contents of the sidebar.php file <?php get_footer(); ?> The contents of the footer.php file <?php the_time('md-y') ?> The date in the format "02-19-08" <?php comments_popup_link (); ?> display a log message link <?php the_title(); ?> display a log or page title <?php the_permalink() ?> display a log or page permalink/URL address < ?php the_category(', ') ?> Display the category of a log or page <?php the_author(); ?> Display the author of a log or page <?php the_ID(); ?> Display a log or ID of the page <?php edit_post_link(); ?> Displaying an edit link for a log or page <?php get_links_list(); ?> Displaying links in Blogroll <?php comments_te Mplate(); ?>The contents of the comments.php file <?php wp_list_pages(); ?> Display a list of blog pages <?php wp_list_cats(); ?> Display a blog's category list <?php next_post_link(' %link ') ?> The URL of the next log <?php previous_post_link('%link') ?> The URL of the previous log <?php get_calendar(); ?> Call the calendar <?php wp_get_archives() ? > Display a list of date archives for a blog <?php posts_nav_link(); ?> Show newer log links (previous page) and older log links (next page) <?php bloginfo('description'); ?> Display blog description information

Some other WordPress template code

/%postname%/ Displays the blog's custom persistent link <?php the_search_query(); ?> Search form value <?php _e('Message'); ?> Printout message <?php wp_register(); ?> Display Register link <?php wp_loginout(); ?> Display login/logout link <!–next page–> Insert page break in log or page <!–more–> Truncate log <?php wp_meta(); ?> Display Management The player's relevant control information <?php timer_stop(1); ?> shows the time the page was loaded <?php echo get_num_queries(); ?> Show loading page query

WordPress calls the latest, hottest, random article

1. WordPress call latest articles

The latest WordPress call can be implemented using a very simple line of template tags wp_get_archvies. The code is as follows: <?php get_archives('postbypost', 10); ?> (showing 10 latest updates) or <?php wp_get_archives('type=postbypost&limit=20&format=custom'); ?> This code shows your blog Among the latest 20 articles, format=custom is used here to customize the display style of this article list.For specific parameters and usage, you can refer to the official instructions - wp_get_archvies.(fromat=custom can also not, the default is to display the article title in the UL list.) Added: WP's query_posts() function can also call the latest article list. Although the code will be a bit more, it can better control the display of the Loop. For example, you can set whether or not to display the summary.The specific method of use can also check the official instructions.

2. WordPress call random articles


3. WordPress call latest message

The following is the latest message code that I had previously received in a WordPress theme. I cannot remember which theme it is.This code directly calls the database to display a new message.LIMIT 10 limits the number of message displays.The green part is the output style of each message.


4.wordpress call related articles


5.wordpress call specified classification article


6.wordpress comment output to the commenter link


7.wordpress calls comment output with gravatar avatar

  The above code changes the value of comment_author to your ID, 18 is the size of the avatar and 10 is the number of comments.

8.wordpress call website statistics

Number of logs: <?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish;?> 2. Number of drafts: <?php $count_posts = wp_count_posts(); echo $draft_posts = $count_posts-> Draft; ?> 3, the total number of comments: <?php echo $wpdb->get_var ("SELECT COUNT (*) FROM $ wpdb->comments");?> 4, set up time: <?php echo floor ((time ( )-strtotime("2008-8-18"))/86400); ?> 5, Total number of tags: <?php echo $count_tags = wp_count_terms('post_tag'); ?> 6. Total number of pages: <?php $count_pages = wp_count_posts('page'); echo $page_posts = $count_pages->publish; ?> 7, total number of categories: <?php echo $count_categories = wp_count_terms('category'); ?> 8, total number of links: <?php $ Link = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = 'Y'"); echo $link; ?> 9, Total users: <?php $users = $wpdb-> Get_var("SELECT COUNT(ID) FROM $wpdb->users"); echo $users; ?> Last updated: <?php $last = $wpdb->get_results("SELECT MAX(post_modified) AS MA X_m FROM $wpdb->posts WHERE (post_type = 'post' OR post_type = 'page') AND (post_status = 'publish' OR post_status = 'private')");$last = date('Yn-j', strtotime ($last[0]->MAX_m));echo $last; ?>

9.wordpress judgment statement

Is_single() Determine if the page is a specific article is_single('2') Determine whether it is a page of a specific article (id=2) is_single('Beef Stew') Determine whether it is a page of a specific article (header judgment) is_single('beef -stew') Whether it is a specific article (slug judgment) page comments_open () whether to leave a message open pings_open () whether to open pingis_page () is a page is_page ('42') id judgment, that is, whether the page is id 42 is_page ('About Me') Judging the heading is_page('about-me') Slug judging whether is_category() is a classification is_category('6') id judging, that is, whether the class is id 6 is_category('Cheeses') classification judgment Is_category('cheeses') classification slug judgment in_category('5') determine whether the current article belongs to the classification 5is_author() displays all authors' pages as is_author('1337') displays pages whose author number is 1337 is_author('Elite Hacker') Shows the current author's page is_author('elite-hacker') by nickname The following is achieved by different judgments with year, month, date, time The way to display the archive is_date () is_year () is_month () is_day () is_time () to determine whether the current is is archived page is_archive () to determine whether it is search is_search () to determine whether the page is 404: is_404 () to determine whether to page, for example, you The current blog is http://domain.com When displaying http://domain.com?paged=2, this decision will return true. This function can be used with is_home to control certain interfaces that can only be displayed on the home page.



10.wordpress non-plug-in call comments expression

  Copy the above code to a suitable location in comments.php:


This article has been printed on copyright and is protected by copyright law. It must not be reproduced without permission.If you need to reprint, please contact the author or visit the copyright to obtain the authorization. If you feel that this article is useful to you, you can click on the "sponsored author" below to reward the author!

Reprinted Note Source: Baiyuan's Blog>>https://wangbaiyuan.cn/en/wordpress-filestructure-function-api-2.html

Post comment


No Comment


Forget password?