WordPress use Sitemap To improve the amount of Baidu included

Source: Internet
Author: User
Tags file url wordpress database

Sitemap can facilitate webmasters to inform the search engine on their own web site on what can be crawled on the Web page, for the improvement of the site's collection of data has a great help, we can regularly to search engines to provide their own site real-time page address to improve their own site collection rate, Baidu has provided webmaster tools to help us optimize the site's friendliness to Baidu.
First Step login http://zhanzhang.baidu.com add your own site domain name and verify (need to add a cname to a Baidu domain name)
Then you can submit their website to Baidu Link to make baiduspider more intelligent crawl their own site, Baidu provides three ways to the webmaster to submit their sitemap.
1, automatic push, by inserting the following JS code on the page, when the page is visited, this page will be submitted to Baidu.

<script>//<! [cdata[
(function () {var bp = document.createelement (' script '); bp.src = '//push.zhanzhang.baidu.com/push.js '; var s = document.g Etelementsbytagname ("script") [0]; S.parentnode.insertbefore (BP, s); })();
]]></script>
2, the active push (real-time), push the interface as follows:

Curl-h ' Content-type:text/plain '--data-binary @sitemap. txt ' http://data.zz.baidu.com/urls?site=sixther.me&amp ; Token=iykcfm6pqmorqzry&amp;type=original "
Sitemap.txt is the sitemap file path on the server, site parameter is the website domain name
Can be implemented by crontab timing to achieve real-time push, but here is a problem, sitamap.txt should also be real-time update, here we can query WordPress database to generate sitemap files in real time, please see the text.
3,sitemap method, this method through the Baidu Webmaster background set a sitemap file URL, and then Baidu will periodically crawl the file, sitemap file support three kinds of formats:
♣ Text Format: That is, a line of URLs, this is the same as the second unsolicited file format, so you can use the script to generate the file in this format, and then both methods can be used.
♣xml format, structured URL collection that can be viewed in sitemap file format
♣sitemap indexed format, a structured sitemap file address collection that can be used to submit URLs in a large number of sitemap files.
The following introduces a txt format from the wordpress database sitemap file method, the same can also generate XML format, WordPress published in all the contents of the Wp_posts table, can be used as follows SQL query to have published the article name:

Select Post_name from wp_posts where post_status= ' publish ' and post_type= ' post '
The URL of all articles can then be generated by concatenation of strings, with the following code:

#!/usr/bin/env python
Import MySQLdb

Class Wordpressdb:
def __init__ (self):
Self.conn=mysqldb.connect (host= ' 127.0.0.1 ', user= ' WordPress ', passwd= ' Hu Jintao ', db= ' WordPress ', charset= ' UTF8 ')
Self.cur=self.conn.cursor ()
def fetch_list (Self,sql):
Self.cur.execute (SQL)
Result=self.cur.fetchall ()
Self.cur.close ()
Return (Result)
if __name__ = = ' __main__ ':
Sitemap_file_fd=open (' Sitemap.txt ', ' W ')
Wd=wordpressdb ()
Query_post_sql= "Select Post_name from wp_posts where post_status= ' publish ' and post_type= ' post '"
For I in Wd.fetch_list (query_post_sql):
Post_url= ' https://sixther.me/' + i[0] + ". html" + ' \ n '
Sitemap_file_fd.write (Post_url)
Sitemap_file_fd.close ()
The results are as follows:

Https://sixther.me/monitor-haproxy-with-zabbix.html
Https://sixther.me/generate-thumbnail-images-with-nginx.html
Https://sixther.me/deploy-django-with-nginx.html
Https://sixther.me/c-point-concept.html
Https://sixther.me/vim-template-for-python-file.html
Https://sixther.me/wordpress-category-page-404.html

At this point, you can use the active push or Sitemap method to submit these URLs to Baidu, but only if these URLs must be valid

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.