How to reset the WordPress database

There are always WordPress novice in the theme of the cat’s QQ user group asked this question: how to clear WordPress website data ah? How to restore the wordpress website to the initial state? The simpler rude solution is to empty the database and reinstall it. But today the theme cat to give you recommend a more simple way.
Even skilled use of WordPrss master, there will be such a demand: for example, sometimes need to test the new wordpress theme or plug-in, to delete all the contents of the wordpress site; or want to empty the site content, re-do a new blog.
Before we encounter this problem, we will delete the existing installation (mainly empty or delete the database, etc.); then re-install WordPress. But this is still a bit cumbersome, especially for users who are not familiar with the operation of the database. Now, the theme cat gives you a wordpress plugin that lets you easily reset the WordPress site.

WordPress Database Reset plugin
WordPress Database Reset, meaning “WordPress database reset”, is a free plug-in from WordPress official plug-in directory, you can restore the WordPress database to the default state. Since the various settings of the WordPress site are stored in the database, this also means that all content of the site will be erased and the site will be restored to the initial installation state.
The wordpress plugin is very easy to use, install and enable the plug-in, in the management of the background sidebar management options, find the “Tools (Tools) -” [database reset (Database Reset)].

Here, you can choose to empty a single table (table), such as delete all comments, delete all pages, etc .; you can also choose to empty all the tables.
Next, enter the plugin generated string, in this case s42Uz, and then click the [Reset Database] button. Then, the plugin will revert to WordPress initial settings and bring you back to the admin background home page.
The plugin will not delete or change your files, such as your uploaded images. It only removes custom options and content, including pages, articles and comments, and so on. However, if you want to reset the important site, in order to prevent mistakes, be sure to do a good job backup.

WordPress development tutorial: the original ecology of the wordpress ajax

Recently small V (site friends) in the development of an adaptive wordpress blog theme, the wordpress theme of a large number of data display and submission are used ajax technology, so small V specially written a tutorial record, to facilitate other wordpress developers do wordpress ajax application development time to do reference. If some small partners do not know what is ajax, please Baidu Baidu ~ ~, gossip is not to say, the tutorial began.
Many developers in the write plug-in like the following way to achieve ajax:

  1. require_once( ‘../../../../wp-config.php’ );

Even the Baidu webmaster platform official development of the wordpress structured data submitted plug-in is also the realization of ajax, which is a very irrational wording, because once the user set the directory is different, the relative path will be invalid. And if you Your plugin is using object-oriented writing, you will not be able to directly use some variables and private methods. The biggest drawback is that will lead to the entire WordPress framework to reload again, seriously affecting the efficiency of the site.
In fact, wordpress in order to facilitate the development of developers with ajax function plug-in theme has been pre-defined ajax method, we only need to use the official reservation method to use just fine. In the development of wordpress ajax you first understand that, whether it is the background or foreground any Ajax requests are in admin-ajax.php deal, send a request to admin-ajax.php, there is a required parameter is $ _REQUEST [‘action’] because admin-ajax.php needs to trigger different hooks depending on whether the user is logged in.

  1. if ( is_user_logged_in() ) {
  2.     /**
  3.      * Fires authenticated AJAX actions for logged-in users.
  4.      *
  5.      * The dynamic portion of the hook name, `$_REQUEST[‘action’]`,
  6.      * refers to the name of the AJAX action callback being fired.
  7.      *
  8.      * @since 2.1.0
  9.      */
  10.     do_action( ‘wp_ajax_’ . $_REQUEST[‘action’] );
  11. else {
  12.     /**
  13.      * Fires non-authenticated AJAX actions for logged-out users.
  14.      *
  15.      * The dynamic portion of the hook name, `$_REQUEST[‘action’]`,
  16.      * refers to the name of the AJAX action callback being fired.
  17.      *
  18.      * @since 2.8.0
  19.      */
  20.     do_action( ‘wp_ajax_nopriv_’ . $_REQUEST[‘action’] );
  21. }

The above code from the wordpress system file admin-ajax.php, from the above code we can see that we want to initiate a request first to know whether this request is initiated in the login state? Different state trigger hook is not the same, the following is a theme in the use of jquery achieve ajax example code:

  1. add_action (‘wp_head’, ‘v7v3AjaxScript’);
    function v7v3AjaxScript () {
    print ‘<script> var v7v3_ajaxurl = “‘. admin_url (‘admin-ajax.php’). ‘”‘. “; </ script> n”;
    print “<script>
    $ (docunment) .ready (function () {
    $ .ajax ({
    url: v7v3_ajaxurl,
    data: {
    action: ‘is_login’
    type: ‘post’,
    cache: false,
    success: function (data) {
    alert (data);
    </ scrip> “;

    add_action (‘wp_ajax_nopriv_is_login’, ‘v7v3_ajax_not_login’);
    add_action (‘wp_ajax_is_login’, ‘v7v3_ajax_is_login’);

    function v7v3_ajax_is_login () {
    global $ current_user;
    get_currentuserinfo ();
    printf (‘Login User Hello:% s!’, $ current_user-> display_name);
    / / Die before the end of the die or exit is very important, we must add.

    function v7v3_ajax_not_login () {
    print ‘Dear Visitors Hello! ‘;
    / / Die before the end of the die or exit is very important, we must add.

In the development of wordpress ajax application is the most important point before the end of the function must be added die or exit, if not add the wordpress framework will be reloaded again.

WordPress editor shortcuts – make writing more convenient

Occasionally seen on DeveWork, so reproduced to the wordpress theme download station. This is the default editor of the shortcut keys, but also very easy to remember, with this, you can more convenient to write.

Bold text: Ctrl + B
Text Italic: Ctrl + I
Text strikethrough: Alt + Shift + D
Underline: Ctrl + U
List of non-serial numbers: Alt + Shift + U
Serial number list: Alt + Shift + O
Quotation: Alt + Shift + Q
Left Alignment: Alt + Shift + L
Center: Alt + Shift + C
Right-aligned: Alt + Shift + R
Align at both ends: Alt + Shift + J
Insert the edit link: Alt + Shift + A
Delete the link: Alt + Shift + S
Insert multimedia: Alt + Shift + M
More tags: Alt + Shift + T
Next tab and post article: Alt + Shift + P
Switch spelling checker status: Alt + Shift + N
Full screen mode: Alt + Shift + G
Show / hide advanced features: Alt + Shift + Z
First level title: Ctrl + 1
Secondary title: Ctrl + 2
Level 3 Title: Ctrl +3
Level 4 Title: Ctrl +4
Level 5 Title: Ctrl +5
Six title: Ctrl +6
Paragraph: Ctrl + 7
Insert Div: Ctrl + 8
Address: Ctrl + 9
Select all: Ctrl + A
Cut: Ctrl + X
Copy: Ctrl + C
Paste: Ctrl + V
Undo: Ctrl + Z
Redo: Ctrl + Y
Insert line: Shift + Enter
HTML and visual mode switch: Alt + Shift + E
Help: Alt + Shift + H
Full-screen mode editor width:
Wider: Alt +
Narrower: Alt –
Default: Alt 0

How to limit the length of WordPress messages

WordPress message function (comment function), can encourage users to discuss the contents of the article to discuss the exchange. However, for some serious sites, the message is too long or too short, and is not conducive to communication. In this article, we will show you how to limit the length of WordPress comment message, both to prevent the message content is too short, but also to prevent the message content is too long.

Why limit the length of WordPress comments?
For some of the sites often discussed around a topic, the contents of the comments will be limited to a certain range, but more conducive to discussion, such as comments limited to more than 20 words, 1000 words or less. If someone commented only to write a word, such as “praise”, in fact, not much of a sense. This situation is more like to take links to spam comments. Likewise, if someone’s comments are over 1000 words, the scope of the discussion is largely beyond the scope of an article if it is not made with a lot of spam links. Therefore, by limiting the length of WordPress messages, you can better improve the discussion atmosphere of such sites.

Method 1: Use plugins to limit WordPress message length using plugins is relatively simple
In the WordPress management background, in the [plug-in] -> [install plug-in] page, search Control Comment Length; and then download and activate Control Comment Length plug-in.
Then, in the [Settings] -> [Control Comment Length] page to configure. This is a German plugin, I do not know, but fortunately the interface also includes English translation. In order to facilitate the understanding, I added the Chinese translation in the following figure.

Need to fill in, including the minimum number of words and the maximum number of words, and the message length beyond the limits of the prompt message. Limit the number of words, you can set according to their own website situation. Where the unit is byte, UTF8 encoding in each Chinese characters accounted for 3 bytes, English letters and numbers accounted for 1 byte; so we recommend that you set to 60 and 3000 respectively. If you only want to limit the maximum number of words, you only need to limit the minimum number of words to 1; Similarly, if you only want to limit the minimum number of words, you only need to set the maximum number of words to a large number (such as 99999) can be.
Prompt information content can be set up their own. The contents of the above are German, you should at least replace the same with your WordPress site front language. The message can contain HTML code, so you can define the contents and format of the output prompt. Note that there are three parameters: {CommentLength}, representing the length of the message; {minimalCommentLength}, the minimum number of bytes; {maximalCommentLength}, the maximum number of bytes.

Method 2: Limit WordPress Message Length by Code
If you do not want to use plug-ins, more willing to use code to solve the problem, this approach is more suitable for you. You only need to copy the following code to your wordpress theme funcitons.php file, or put your site dedicated plug-in, you can.

  1. add_filter( ‘preprocess_comment’, ‘wpb_preprocess_comment’ );
  2. function wpb_preprocess_comment($comment) {
  3.     if ( strlen$comment[‘comment_content’] ) > 3000 ) {
  4.         wp_die(‘Comment is too long. Please keep your comment under 3000 characters.’);
  5.     }
  6. if ( strlen$comment[‘comment_content’] ) < 60 ) {
  7.         wp_die(‘Comment is too short. Please use at least 60 characters.’);
  8.     }
  9.     return $comment;
  10. }

It is important to note that the wp_die () function’s quotation marks are messages that are output when the message limit is exceeded, and you can replace it with Chinese (or your site’s corresponding front language). It is important to note that if you want to output Chinese prompts, please remember to save the functions.php file or the website-specific plug-in file as utf8 no bom format to prevent the output garbled; use notepad ++ free editor or everedit charging editor The There is one, each character accounted for 3 bytes, do not forget to convert Oh!

WordPress program in the win and Linux system under the pseudo static settings

Today, this article I came to tell you about the wordpress program in the win and Linux system under the pseudo-static set method.
The first: win system under the wordpress program pseudo static.
wordpress in the win system under the pseudo-static premise is the need for space system to support pseudo-static settings, and we also know that the general win system supports pseudo-static rules for the httpd.ini format, then we first first create a text document, the following code Copy and paste in the inside (this is what I have so far collected the most perfect win system pseudo-static rules).
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# Protect httpd.ini and httpd.parse.errors files
# from access through HTTP
# wordpress pseudo static rules
# For tag (Chinese label and label page rules)
RewriteRule /tag/(.*)/page/(d+)$ /index.php?tag=$1&paged=$2
RewriteRule /tag/(.+)$ /index.php?tag=$1
# For category (Chinese classification and classification of the rules)
RewriteRule /category/(.*)/page/(d+)$/index.php?category_name=$1&paged=$2
RewriteRule /category/(.*) /index.php?category_name=$1
# For sitemapxml
RewriteRule /sitemap.xml /sitemap.xml [L]
RewriteRule /sitemap.html /sitemap.html [L]
RewriteRule /sitemap_baidu.xml /sitemap_baidu.xml [L]
RewriteRule /favicon.ico /favicon.ico [L]
# For file-based wordpress content (ie theme), admin, etc.
RewriteRule /wp-(.*) / wp- $ 1 [L]
# For normal wordpress content, via index.php
RewriteRule ^ / $ /index.php [L]
RewriteRule / (.*) /index.php/$1 [L]
Copy and paste the above code into the text document, we will save the text as httpd.ini, so that our pseudo-static rules on the well, we only need to upload this file to the space more directory, if in the background → fixed link selection Custom link input / %category%/%post_id%.html or / %post_id%.html click to save on it, which we also need a plug-in support, that is, to remove the category URL in the middle of the category, we only need In the background plug-in → install plug-in that search WP No Category Base, the installation is enabled on it. So we win system under the wordpress program pseudo static to complete.
The second: pseudo-static settings under Linux system
This is very simple, we know that the Linux system itself is the most perfect system using wordpress, its pseudo-static settings are very simple, we only need in the background → fixed link select custom link input /% category% /% post_id% .html or / %post_id%.html click Save on it. Similarly, it is also necessary to cooperate with WP No Category Base plug-in, the following I will support the Linux system. Htaccess pseudo-static rules to write out. The code is as follows:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^ index.php $ – [L]
RewriteCond% {REQUEST_FILENAME}! -f
RewriteCond% {REQUEST_FILENAME}! -d
RewriteRule. /index.php [L]
</ IfModule>
# END WordPress
The above code is the same, we need to create a new text document, and then paste the code into the paste, click Save as. Htaccess file, and then upload this file to the root of the space to complete.
This article is written here, and hope that those who use the wordpress program do not know how to set up a friend how to do some help, if you do not understand what, you can leave a message to me, thank you!

To all the wordpress novice, how to detect download the wordpress theme plugin contains the back door

Recently a lot of small partners have been discussing the site was black and download the free wordpress theme plugin hanging horse topic, then today V to teach you how to identify the wordpress theme plug is left behind the door. First of all, under the wordpress operating environment, I believe that a little bit of common sense of the owners know that wordpress is a run on the php + mysql system built on top of the system, and wordpress theme plug-ins are written as. Php suffix executable file this Is why wordpress’s free theme plugin is easy to stay behind the door problem. Since it is written by php, then we just know that the general use of PHP backdoor procedures can be a certain degree of awareness of the theme plug-in whether there is a backdoor Trojans, the following small V lists some common php backdoor function:
Execute system commands: system, passthru, shell_exec, exec, popen, proc_open (high risk)
Code execution: eval, assert, preg_replace (‘/ $ pattern / e’) (high risk)
File operations: file_get_contents, file_put_contents, fputs, fwrite (high-risk)
String encryption and decryption compression decompression hidden: base64_decode, gzinflate, gzuncompress, gzdecode, str_rot13, base64_decode, gzcompress, chr (suspicious)
wordpress Create backdoor user: wp_create_user, WP_User, set_role (high risk)
If the subject of small V mark the high-risk code can basically determine this theme is very problematic, and basically are to stay back door or do little tricks. If it is found in this article marked suspicious code that should be noted that the code is likely to encrypt the part of the back door. Many small partners certainly do not understand preg_replace (‘/ $ pattern / e’) What is the meaning of this code, the following small V to explain to you, preg_replace function using e modifier after the implementation of the reverse reference replacement will be replaced Of the code as php code to run, so it is also a very common backdoor code. In the detection of the theme plug contains the back door as long as the text search tool or software search theme plug-in php file contains the above keywords, in the search for preg_replace need to manually compare the code to see whether the inclusion of e modifier, if the subject file (5) .chr (3) .chr (58) This kind of code should be careful, and found that the subject file appears a lot of random characters have to be careful are generally encrypted code is likely to hide The back door.
PS: Because the usual beard finishing the theme and plug-ins are more, it is difficult to check all the documents are submitted side. Up to check the next few key files are hanging horse, so please download the theme as much as possible after their own check again.

WordPress change the domain name to pay attention to ten things

WordPress replacement domain name may have been experienced in the old and new domain name replacement process, how to make the loss to a minimum, which focus on SEO owners who is essential. One side of my own experience to talk about WordPress change domain name after the attention of ten things.
First, modify the database configuration file
If you change the domain name on the same host in the same space, this step can be saved. If the database is different, you have to open wp-config.php to properly configure the database to access the new domain.
Second, change the blog’s installation address and blog address
First use phpmyadmin to open your database, and then find the wp-options this data table, find the first record is siteurl this, there are 39 home, the two will be changed to your replacement after the domain name can be The Only to complete this step, you can successfully enter the background, or even if you enter the password, it will automatically jump to the original old domain name.
Third, modify the article all the links within the new domain name
I believe we published in the previous article must be added a lot of the chain, the domain name replaced, the old chain also no meaning. In this case, you should change the old domain name in the article to the new domain name. If the background from the editor of a search that is unrealistic, there is a way, universal phpmyadmin into your database, the implementation of the following statement can be all within the article within the chain of old domain name to the new domain name:
UPDATE wp_posts SET post_content = replace (post_content, ‘’, ‘’);
Four, to re-visit the search engine site
Because the replacement domain name, all from scratch, so if the search engine to re-submit a new domain name, submitted to the process, we must pay attention to my article mentioned several points of attention. After the submission, it is a long waiting process, do not worry, because the start again, that this waiting process, you only put the energy on the original article.
Fifth, the old domain name 301 redirect to the new domain name
Do not think of the old and new domain names are pointing to the same station, this will cause “domain name bombing.” The result of this will not only give your website more traffic, but the search engine that your cheating, down your weight is small, it is not impossible for your station K is not possible. If you want to retain the old domain name of the users, it would have to make a 301 redirect. 301 redirect to SEO or friendly, there are many specific methods, the specific operation is not in this one one detailed
Six, re-modify the statistical code
This should be a very simple thing, and then to the statistical site to apply for the new domain name statistics, the old domain name statistics can be covered.
7. Re-change the feed subscription address
RSS feed subscription is to maintain a station traffic is an important factor, when your domain name are replaced, how others also subscribe. So you should re-set the subscription address, and try to notify the old domain name has been changed friends. Also modify the RSS feed subscription address at the appropriate location on the home page.
8, inform your friendship link
Before your 301 redirect is still in effect, be sure to inform your link and change the old domain name to the new domain name. If 301 is invalid and your link has not been notified, then your link will be meaningless.
9, check the plug-in is working properly
Although the plug-in settings are part of the domain name has nothing to do, but we all know WordPress function is to rely on plug-ins, so replace the domain name, it is best to check whether a plug-in is working properly. Such as Baidu Sitemap Generator and Google XML Sitemaps two plug-ins, must be disabled and then enabled to work properly.
Ten, to your frequent visits to the blog message for rice
I have dozens of visits, basically every day to see, in the bloggers to comment on the time casually talk about your blog for the domain name. Played a hundredfold multiplication effect.

WordPress 4.0.1 fixes 8 security risks and 23 bugs

WordPress 4.0.1 is now available. This is a critical update for the previous version, and it is strongly recommended to update your site immediately.
Web sites that support automatic background updates will automatically be updated to WordPress 4.0.1 over the next few hours. If you are still using WordPress 3.9.2, 3.8.4 or 3.7.4, you will be updated to 3.9.3, 3.8.5, 3.7.5. (We do not support the old version, so please update to the latest best 4.0.1)
WordPress version 3.9.2 and earlier are subject to a critical cross-site scripting vulnerability that could allow anonymous users to compromise the site. This issue does not affect the 4.0 version, but the 4.0.1 version solves the following eight security issues:
3 cross-site scripting problems that can be used by the contributor or author to destroy the site
A cross-site request forged can be used to trick users into changing passwords
1 question that may result in a denial of service when checking the password
When WordPress sends an HTTP request, additional server-side requests for an attack
A very unlikely hash conflict could have affected the user’s account, which also requires them to have not logged in since 2008 (I wish I was kidding)
WordPress now password reset the link in the message, if the user remembers their password, log in, can modify their email address.
4.0.1 also fixed 4.0 of the 23 bug, and we also made two hardening changes, including a better validation of the excerpt from the upload photos of EXIF ​​data.

WordPress add color tag cloud

Tag cloud is a lot of WordPress theme has a theme element, today about how to add color for your theme tag cloud, including the sidebar call and page calls.

1. Call the tag cloud
We can use the wp_tag_cloud () function to implement the tag cloud call. For example, the following example:

  1. <?php wp_tag_cloud(‘smallest=12&largest=18&unit=px&number=0&orderby=count&order=DESC’);?>

Code Comments:
smallest represents the smallest size of the label
largest represents the largest font size
unit = px indicates that the font uses pixel units
number = 0 means that all labels are displayed, and if it is 40, it means 40
orderby = count means the number of articles associated with the label
order = DESC for descending order (ASC for ascending order, DESC for descending order)
For more information on wp_tag_cloud (), please refer to the WordPress documentation wp tag cloud

2. Add a color function
According to the above parameters, you can already call out the tag cloud and add the following code to the last one of the theme’s functions.php?> In front of the color:

  1. //边栏彩色标签
  2. function colorCloud($text) {
  3.     $text = preg_replace_callback(‘|<a (.+?)>|i’,’colorCloudCallback’, $text);
  4.     return $text;
  5. }
  6. function colorCloudCallback($matches) {
  7.     $text = $matches[1];
  8.     $color = dechex(rand(0,16777215));
  9.     $pattern = ‘/style=(‘|”)(.*)(‘|”)/i’;
  10.     $text = preg_replace($pattern“style=”color:#{$color};$2;””$text);
  11.     return “<a $text>”;
  12. }
  13. add_filter(‘wp_tag_cloud’, ‘colorCloud’, 1);

3. Make the tag cloud page
You can take a look at the theme cat tag cloud page:
1) Copy your theme page.php file at the top of the file Add:

  1. <?php
  2. /*
  3. Template Name: Tags
  4. */
  5. ?>

2) Replace the page.php with the following code:

  1. <?php wp_tag_cloud(‘smallest=12&largest=18&unit=px&number=0&orderby=count&order=DESC’);?>

3) The page generally does not require comment function, remove the following code in page.php:

  1. <?php if (comments_open()) comments_template( , true ); ?>

4) You can also according to their own needs, delete some of the functions in page.php, and finally save the file as page-tags.php, so that a tag cloud template to do a good job.
5) visit the WP background – page – create a new page, the page name to fill their own, just in the page properties, select the tags template can:

4. Call the tag cloud in the sidebar
You can use the following function call, the specific method of modification, on your own toss the theme:

  1. <?php wp_tag_cloud(‘smallest=12&largest=18&unit=px&number=20’);?>

However, the general production of more standardized WordPress theme, support Widget gadget, you can in the WP background – appearance – gadget to see whether to support the tag cloud gadget.
Note: This article just tells you how to implement the color tag cloud and how to call it. But the specific style, it is necessary to rely on your own through the CSS code to achieve.

WordPress template architecture

header.php (website head)
This is a global file (easy IT Note: WordPress generated each page will contain the header.php code), display the page header (header) and navigation menu, also contains the HTML file head code (<head> … </ head>). </ p>
The loop (the page body)
The main content of the site is displayed in the main area of ​​the site through a template file containing the “loop” structure.
sidebar.php (sidebar)
This file controls what sidebar shows. If there are multiple sidebars, you can set in the functions.php file, the sidebar “widgets” content can be set in WordPress management control panel (wp-admin).
footer.php (bottom)
The code that contains the global bottom file and closes the HTML tag (</ html>).
The WordPress theme is made up of a series of files in the template folder (.. / wp-contents / themes / template name /), each of which controls the different parts of the template. No matter which page on the site, some parts of these pages are generally static, controlled by the header, siderbar, and footer files. You can modify these files to see which parts of the site are controlled by which files.
Home page
index.php is used to control how the home page of the site is displayed. The index.php defaults to a query and displays the loop of the latest article and displays a hyperlink at the bottom to view the previous article.
Alternatively, you can set any page you created in wordpress as the home page in wp-admin> settings> read. In other words, you can set a different page (or url) as a regular blog article as a home page to display, and that page or through the index.php template generated.
Posts (posts)
single.php is used to control how the article page is displayed. This file contains queries and displays the current article loop.
If you want to display the sidebar (and other elements you want to display), you can specify it in this file. You can also modify the file to make the article page and other pages are different.
Pages (pages)
page.php controls the display of WordPress Page (page, different and post). You can choose to remove the sidebar or other elements, or add some elements only the page.
WordPress also allows you to create different page templates that are used to display different types of pages. Create a page template is very simple, you just copy page.php, change your favorite name, and then add the following code at the top of the file:
<? php
/ *
Template Name: The name of the page template file you named
/ *
archive.php, category.php, tag.php
You can use the above files to control the display of various archive class pages. If the archive page template is not archived, the archive page will use index.php as a template; however, you can create an archive.php instead of index.php as the template for the archive class page. If you created category.php, this file will replace archives.php as a template for the categories. If you created tag.php, this file will be preferred as a template for the tag page.
The Loop
The loop may be the most powerful part of the wordpress template. It starts from a query (to decide which article or page data to grab) and has an end loop. The loop shows what depends on your needs. You can display the title of the article in the loop, the content of the article, the metadata (author, date, etc.), custom fields and comments, etc. These elements are the output of an article or page. You can also create multiple queries and loops on an article or page; for example, in single.php, you can create a loop to display the contents of a single article and then use another loop to display under the article content The title and thumbnail of the article related to this article.
Article and page query mechanism
Start the cycle
(Repeat this and endwhile between all the contents until all the relevant content of the article are finished)
(Output the title of the article)
(The introduction of the article)
(The main content of the output article)
(The name of the output article)
(The author of the output article)
(The date of the output article)
other tags
(Can be inserted in the cycle of the various templates used in the label)
(Repeated until all queries have been output)
Behind the scenes of other mechanisms
To make the wordpress theme template work, you also need some important files in the background. You can modify these files according to their own needs, to customize the function of the site and how to display.
This file controls how the comments are displayed, and the file contains a loop that queries all the comments for an article. comments.php can be overridden by some plugins, such as Disques, that these plugins can take over the comments of the site.
functions.php allows you to add your own php code to modify the core elements of the wordpress theme. Usually this can be used to add multiple sidebars to their own theme, modify the number of characters in the article (excerpt), or add your own admin panel options to wp-admin.
This is the main template style file for the theme template. At the same time at the top of the file, contains the subject name, the author and your site URL and other related text, so WordPress to know the subject of this information.
In addition to the core features of WordPress, other similar plugins, custom fields and wedgets allow you to customize your website further.
There are a lot of open source developer community developed a lot of plug-ins, you can add them to your website for free, including e-commerce, slideshow (slideshow), cache and social function.
Custom Fields
The custom field is when you create an article and can be entered in the input box below the article content input box. Through the custom domain, you can create your own options or content, and then you can use them in the theme template or display them. It is often used with thumbnails and used to include javascript code (include).
The gadget is a small module for the sidebars. In wp-admin, you can configure the default gadget, you can also add a variety of plug-ins provided by the gadget, or php code. Gadgets typically include content such as search forms, popular article lists, and ad blocks.

WordPress do not use plugin with ajax refresh sidebar random article

A friend sent me to ask me, my sidebar that refresh the effect is how to achieve. Can share
In fact, I intend to share these days, that is, time is not allowed, and now we share under how to use ajax refresh wordpress sidebar random article bars
Click on the blog sidebar “refresh” you can see.
How to achieve?
First make sure your theme is called in the js library, and the following code can be found in the topic file header.php. If you do not have it, please copy and paste it before the label.
<script type = “text / javascript” src = “”> </ script>
1, to determine the scope of the article code id. The blog’s random article html code is roughly as shown below. You can also find similar code in your website template. Each topic calls the same function, the middle of a string of code can be ignored.
<h2 class = “sub”> recommended reading </ h2>
<div id = “postlist1”>
<ul class = “spy”>
<? php $ my_query = new WP_Query (‘orderby = rand & showposts = 5’);?>
<? php while ($ my_query-> have_posts ()): $ my_query-> the_post ();?>
<li> <? php $ screen = get_post_meta ($ post-> ID, ‘screen’, $ single = true);?>
<h2 style = “overflow: hidden;”> <a href=”<?php the_permalink()>> “title =” <? php the_title ();?> “> <? php the_title ();?> < a> </ h2>
</ li>
? php endwhile;?>
</ ul>
</ div>
<a href=”#” id=”another”> refresh </a>
Among them, you also need to add a “refresh” to your immediately article code. That is the following code.
<a href=”#” id=”another”> refresh </a>
Also note that the ID “frontlist1” and the last parcel “refresh” ID “another” in front of the ul tag will be used.
2. Create a page template named Random Post. PS: Do not copy the following code. Where the article call function is copied directly from the sidebar.php in the currently used theme.
<? php
/ *
Template Name: Random Post
* /
<? php $ my_query = new WP_Query (‘orderby = rand & showposts = 5’);?>
<? php while ($ my_query-> have_posts ()): $ my_query-> the_post ();?>
<li> <? php $ screen = get_post_meta ($ post-> ID, ‘screen’, $ single = true);?>
<h2 style = “overflow: hidden;”> <a href=”<?php the_permalink()>> “title =” <? php the_title ();?> “> <? php the_title ();?> < a> </ h2>
</ li>
<? php endwhile;?>
3, create a page using the above template, and publish.
We can click here to view this page of this site / random
4, jQuery
Copy and paste the following code into your subject header.php file before placing it on the label.
Where # polist1 and #another are found in step one, combined with your own theme changes.
<script type = “text / javascript” charset = “utf-8”>
$ (). ready (function () {
$ (“# postlist1”). load (“/ random /? offset =” + offset);
$ (“# another”). click (function () {
offset = offset + 5;
$ (“# postlist1”)
.slideUp ()
.load (“/ random /? offset =” + offset, function () {
$ (this) .slideDown ();
</ script>
5 until all ends, you’re done!

WordPress Integrated Alipay

How to integrate in the WordPress program Alipay is to achieve WordPress e-commerce must break through a bottleneck. WordPress has a lot of e-commerce class plugins, like the more famous WP e-Commerce and so on. But the only drawback of these plug-ins is not enough localized, do not support Alipay. Perhaps because WordPress Alipay integrated business application value is relatively high, few people are willing to share the relevant experience free of charge. There are generally WP master are relatively low-key, busy to make money to go. In the online collection of relevant information I have nothing, in addition to that was reprinted hundreds of times I do not know who wrote the so-called tutorial. Here is not to link, because it is not clear who is already original. First explain: This operation requires you to be familiar with the wordpress template and understand the WordPress custom domain related knowledge, understand a little HTML and CSS. Nonsense does not say, the following is a detailed step.
1, first of all if you want to pay a business contract, and apply for a secured transaction or immediately to the transaction, (I apply for immediate arrival) to apply for a general audit period, but Alipay staff efficiency is still very high.
2, after the application you will get an Alipay security check code (key) and a partner identity (Partner ID). This is the official help (graphic). These two numbers are very important, the following will be used.
3, landing Alipay account business service page download integrated technical documents. Or you can go to Alipay Forum download. (Note: download php + utf8).
4, followed by the parameter configuration, you only need to modify the alipay_config.php this file can be.
// partner ID, 16-bit pure number beginning with 2088
$ partner = “”;
// security check code, 32-bit characters consisting of numbers and letters
$ key = “”;
/ / Signed Alipay account or seller Alipay account
$ seller_email = “”;
/ / Transaction process server to notify the page to use http: // format full path, not allowed to add id = 123 such custom parameters
$ notify_url = “http: //www.yourdomain/alipay/notify_url.php”;
/ / Pay the page after the trip to use http: // format full path, not allowed to add id = 123 such a custom parameter
$ return_url = “http: //www.yourdomain/alipay/return_url.php”;
/ / Site products display address, not allowed to add id = 123 such a custom parameter
$ show_url = “”;
// Name of recipient, eg company name, website name, payee name, etc.
$ mainname = “”;
5, will modify the file upload to your site’s root directory, be careful not to change the original directory structure and file name. Quick payment entry template file (index.php), picture, CSS style folder (images) without upload. These two files can be integrated into your wordpress theme. For example I was at / alipay
6, in fact, where the Long March has been the first step, and then the treasure will be integrated into your theme in the desired location. Such as a single article page (single.php). Integration of the overall idea is to use WordPress custom domain, the value through the form hidden domain or URL parameters with POST way to pass to the interface, and assigned to the interface form to achieve. Here are three very important parameters: product name, description of goods and commodity prices.
Note: form a name is to pay the official file provided by the official treasure naming, generally do not change. If you have a high level of exception.
7, the following is a specific example of code, I integrated it into a single log file. Of course, your WP theme is best designed to change the door of the product page template, rather than the article page common to a template.
<div class = “alipay”>
<FORM name = alipayment action = / wordpress / alipay / alipayto.php method = post target = “_ blank”>
<INPUT type = “hidden” size = 30 name = aliorder value = “<? Php echo get_post_meta ($ post-> ID,” P_name “, true);?>” Maxlength = “200”
<INPUT type = “hidden” maxLength = 10 size = 30 name = alimoney value = “<? Php echo get_post_meta ($ post-> ID,” P_price “, true);?>”
<input type = “hidden” name = alibody value = “<? php echo get_post_meta ($ post-> ID,” P_description “, true);?>”>
<input type = “hidden” name = “pay_bank” value = “directPay”>
<input type = “submit” class = “btn” value = “buy” />
</ FORM>
</ div>
8, here in fact Alipay function has been used. Add a new article, add the appropriate custom field, and then publish. See if you can buy online already? The next step is to beautify the work, if you are proficient in CSS, proficient in HTML form design, proficient in JQURY, you can make payment more beautiful and more secure.
9, if you still have the energy, you can consider the integration of Alipay into plug-ins, improve the relevant configuration options to achieve WordPress background order query and tracking. This is achievable, WordPress has the potential to create a more than ECSHOP or SHOPEX also want to play online shop, and in the search engine optimization performance will be better than the latter two.

WordPress Recycle Bin feature configuration

WordPress Recycle Bin is a feature introduced by WordPress 2.9.
Starting with WordPress 2.9, we can put any content, comments, attachments into the WordPress Recycle Bin. Into the Recycle Bin, we can restore the contents of the Recycle Bin, you can also completely delete the contents of the Recycle Bin.
On the WordPress Recycle Bin function, in addition to the above description, you need to know the following.
First, customize the WordPress Recycle Bin to delete the time
WordPress Recycle Bin content, the default will be deleted after 30 days, the logic is very simple, otherwise the WordPress Recycle Bin will be more bloated.
Of course, if you think 30 days is too long, we can also customize the content storage time, we need to add the following code to wp-config.php Lane.
define (‘EMPTY_TRASH_DAYS’, num);
num = days. By default, here should be the number of days, according to their own hobbies, set the corresponding number of days. After this expires, the content is automatically deleted.
Second, the WordPress Recycle Bin set to delete function.
But that does not mean that we have to always use this recycle bin function, just like some friends know this feature after the evaluation, WordPress official is more and more “out of business”.
Some people still like to immediately delete the content, do not want to operate again in the Recycle Bin, the implementation method is very simple, just need to:
define (‘EMPTY_TRASH_DAYS’, num);
In the num into 0 can be, then moved to the Recycle Bin will become permanently deleted, will not be put into the Recycle Bin, delete directly.

WordPress access slow solution

First, disable Google resources
WordPress many themes using Google’s services, and now Google is a large-scale shielding, a serious impact on the site’s visit speed, so banned! There are two ways to do this, one using plugins: Disable Google Fonts (or other Google Fonts plugins); another way is to add code directly in functions.php:
/ **
* remove google fonts
* by:
* /
function remove_open_sans () {
wp_deregister_style (‘open-sans’);
wp_register_style (‘open-sans’, false);
wp_enqueue_style (‘open-sans’, ”);
add_action (‘init’, ‘remove_open_sans’);

Second, modify the Gravater head to the wall
2014 Gravatar server wall, leading to the head are not shown, causing the site speed was slowed down. You can use the following code to solve the problem by the wall, of course, you can also use the Gravatar header cache approach to speed up.
/ **
* by:
* /
function quickly_gravatar ($ avatar) {
$ avatar = str_replace (‘? s =’, ‘.png? s =’, $ avatar);
$ avatar = preg_replace (“/ ([0-9]).. gravatar / i”, “en.gravatar”, $ avatar);
return $ avatar;
add_filter (‘get_avatar’, ‘quickly_gravatar’);

Third, delete the extra plugin
One of the strengths of wordpress is that it’s easy to scale, and there are a lot of great plug-ins that can meet all your needs, but for that reason, most of us have installed a lot of plug-ins, which affect the site’s Access speed. So here, it is recommended that you ban the extra plug-ins, only for their own plug-in is the best. So how do you start deleting the extra plugin?
1, audit each plug-in to see if it is necessary, if not please delete
2, check the plug-in version, keep the latest version of the plug-in, if the plug-in update time is a few years ago, please delete it
3, plug-ins as far as possible in the wp official download, to avoid the impact of bad plug-ins

Fourth, optimize the picture resources
Each site will have picture resources, the picture is often loaded into a website inside the file one of the largest resources, so we must manage the picture. Picture format suggested that you use the commonly used format jpg, png and gift, save the picture, try to reduce the size of the compression, but can not affect the use. Can be optimized
1, use the height and width attributes, make up the alt attribute (for seo friendly)
2, the use of tools to optimize the picture
3, the use of reliable image storage services

Five, the subject of the code efficiency
Wordpress theme can be said to be all-inclusive online, there are free, there are paid, but also have their own production, a theme determines a site shell containers, if the container is not good, then we can not even good things. So we should be careful choice, not only need to have a good interface, but also requires a reliable, excellent code of the theme.
In some time ago, re-customized a new theme, which optimized the efficiency of the implementation of php code, the effect is still very good, compared to a blog theme, the size of the first page reduced by half, sql query also reduced by half, the pressure on the server Greatly reduced. Here mention the theme code efficiency, in fact, PHP code level optimization, you can start from the following aspects:
1, optimize the efficiency of PHP implementation
2, to reduce the number of sql inquiries
3, delete some of the functions to static
4, set the php cache

Six, the host server
This is an optimization of the server, for example, can be lightweight, high-performance Nginx, load balancing, etc., the specific program is not described in detail. Here to suggest that the website, the server must be good, spend money can buy you a lot of time, energy.

WordPress forget the background login password solution

After the installation of wordpress forget to record the default password or use the wordpress for some time after the forgotten password how to do? CMS concentration camps sorted out six kinds of wordpress forget the password solution, recommended to the owners.
1, reinstall WordPress. We do not recommend this method, reinstall the installation file to download more trouble.
2, use the password recovery function. WordPress itself supports e-mail password recovery function, if the administrator account e-mail is valid, in the background login interface, click “forget the password?” Link, enter the correct e-mail address, you can receive a reset password with the message.
3, the WP directory under the wp-config.php file to delete, and then re-visit the site, which will allow you to re-install the last step, so you can get a new password.
4, log phpMyAdmin, find WP database wp_users table, where you can see the default user admin, its password is encrypted. At this time, we can modify this data, find the user_pass this domain, put it a long string of data deleted, write your password, such as 123456. At this point, you will see a function drop down box, select it as MD5. This is to put your password MD5 algorithm encryption, and then save. This way, through your domain name / wp-admin visit to the management of the entrance, with this password can be landing.
5, through the SQL statement to change the password. Log in to phpMyAdmin to enter the WordPress database and execute the following SQL statement:
UPDATE wp_users SET user_pass = MD5 (‘PASSWORD’) WHERE wp_users.user_login = ‘admin’ LIMIT 1;
6, use PHP to retrieve the password. PHP method in the final analysis is also the way SQL query changes, but to provide a user interface. Copy and save the following code as the password-resetter.php file, upload it to the WordPress root directory, and then run the file and enter the password to reset it.
<? php
// password resetter
include (“wp-config.php”);
include (“wp-blog-header.php”);
if (empty ($ _ POST [’emergency_pass’])) {
<form method = “post”>
set admin password: <input name = “emergency_pass” type = “password” />
<input type = “submit” />
</ form>
<? php
} else {
$ sql = “UPDATE”. $ wpdb-> users. “‘SET user_pass ='” .md5 ($ _ POST [’emergency_pass’]). ” WHERE User_login = ‘admin’ “;
$ link = $ wpdb-> query ($ sql);
wp_redirect (‘wp-login.php’);
exit ();