Write a search engine-friendly Article Seo paging class

Source: Internet
Author: User
Tags rowcount

Use JSP, PHP, ASP, and other dynamicProgramHow are generated pages friendly to search engines? You may want to use url_rewrite. However, it is recommended that the content of the page corresponding to the same website address be the same or similar at any time. Because the search engine does not like the URLs where the page content is always changing.

Ordinary blogArticleYou need to display the new article in front, so you will use an SQL statement similar to "order by ID DESC" to query multiple articles on one page. For example, in Java + MYSQL:

Public Article [] getarticlearray (int from, int size ){
Article [] article = new article [0];
String query = "select * from blog order by desc id limit" + from + "," + size;
Try {
Resultset rs = st.exe cutequery (query );
Rs. Last ();
Size = Rs. getrow ();
Article = new article [size];
Rs. beforefirst ();
For (INT I = 0; RS. Next (); I ++ ){
Article [I] = new article (
Rs. getint ("ID"), RS. getstring ("time "),
Rs. getstring ("name"), RS. getstring ("blog ")
);
}
Rs. Close ();
} Catch (exception e ){
System. Out. println (E );
}
Return article;
}

This is a method in our Seo paging class myseopager. To display the first page, use getarticlearray () to query the latest 10 articles.

What's the problem? The problem is that after you add an article, all the original pages have changed. In order for getarticlearray () to display the same article for each query, getarticlearray () should display the first 10 new articles. We can modify our paging class in this way. Deleting and will affect the content of the page. The more you delete the new article, the larger the page that is generated.

Public Article [] getarticlearray (int from, int size ){
Article [] article = new article [0];
String query = "select * from blog order by ID limit" + from + "," + size;
Try {
Resultset rs = st.exe cutequery (query );
Rs. Last ();
Size = Rs. getrow ();
Article = new article [size];
Rs. beforefirst ();
For (INT I = 0; RS. Next (); I ++ ){
Article [I] = new article (
Rs. getint ("ID"), RS. getstring ("time "),
Rs. getstring ("name"), RS. getstring ("blog ")
);
}
Rs. Close ();
} Catch (exception e ){
System. Out. println (E );
}
Return article;
}

We also need to get the number of articles in the database, so we need to add another method.

Public int getarticlecount (){
Int rowcount = 0;
String query = "select count (*) as rowcount from ide1_k ";
Try {
Resultset rs = st.exe cutequery (query );
If (Rs. Next ()){
Rowcount = Rs. getint ("rowcount ");
}
} Catch (exception e ){
System. Out. println (E );
}
Return rowcount;
}

Now we will display the latest 10 articles on the JSP page.

 
Int start =-1;
Myseopager pager = new myseopager ();
Int artcount = pager. getarticlecount ();
Try {
Integer. parseint (request. getparameter ("START "));
} Catch (exception e ){
Start = artcount-10;
}
If (Start> artcount-10) Start = artcount-10;
If (start <0) Start = 0;

Article art = pager. getarticlearray (START, 10 );
// Do something with art here.
Int previous = start + 10; // start value uploaded to the previous page
Int next = start-10; // The start value uploaded to the next page.

In this way, whether the content of the generated page changes is related to whether you have deleted the first published article. As long as you do not delete the article, showblog. jsp? Start = 0 the page corresponding to the URL with this parameter does not change. As long as you delete the nth article, the page corresponding to start <(n-pagesize) does not change. Only the first page is affected when you add an article.

This method is used in the ideabook message book I wrote.

Related Article

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.