Write a search engine friendly article SEO paging class

Time:2021-10-15

How can pages generated by dynamic programs such as JSP / PHP / ASP be friendly to search engines? You may want to use the URL_ rewrite。 However, it is best to make the corresponding page content of the same website at any time the same or similar. Because search engines don’t like URLs where page content is always changing.

Generally, blog posts need to display the newly published articles in front, so SQL statements like “order by ID desc” will be used to query multiple articles contained 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.executeQuery(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. If we want to display the first page, we use getarticlearray (0,10) to query the latest 10 articles.

What’s the problem? The problem is that when you add an article, all the original pages change. In order for getarticlearray (0,10) to display the same articles every query, getarticlearray (0,10) should display 10 newly published articles. We can modify our paging class like this. Deleting and will affect the content of the page. The more new articles you delete, the greater the changes in the generated page.

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.executeQuery(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 how many articles are in the database, so add another method.

public int getArticleCount(){  int rowcount = 0;  String query = "SELECT COUNT(*) AS rowcount FROM ideabook";  try{    ResultSet rs = st.executeQuery(query);    if(rs.next()){      rowcount = rs.getInt("rowcount");    }  }catch(Exception e){    System.out.println(e);  }  return rowcount;}

Now let’s display the latest 10 articles in 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 transferred to the previous page int next = start - 10// The start value passed to the next page

In this way, whether the content of the generated page changes or not is related to whether you delete the first published article. As long as you don’t delete the article, showblog. JSP? Start = 0. The page corresponding to the URL with this parameter will not change. As long as you delete the nth article, the page corresponding to start < (n-pagesize) will not change. The article you add only affects the first page.

In my writingIdeabook message bookThis method is used.

Recommended Today

Swift advanced (XV) extension

The extension in swift is somewhat similar to the category in OC Extension can beenumeration、structural morphology、class、agreementAdd new features□ you can add methods, calculation attributes, subscripts, (convenient) initializers, nested types, protocols, etc What extensions can’t do:□ original functions cannot be overwritten□ you cannot add storage attributes or add attribute observers to existing attributes□ cannot add parent […]