The background management of the Web page

Source: Internet
Author: User

For example, many CMS home page will have real-time update of the need for a chart:



Recently, in the process of doing a CMS, we encountered such a demand.


I used to do a campus website project (do it myself), but the foreground of the chart is written dead on the page, that is:

<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:18PX;" ><div><span style= "White-space:pre" ></span><ul><span style= "White-space:pre" > </span><li><a href= "#" >                    </a> </li>                <li><a href= "#" >                    </a> </li>                <li><a href= "#" >                    < /a></li>                <li><a href= "#" >                     </a></li>           <span style= "White-space:pre" ></span></ul></div></span>

But in the actual project must be to work, that is, can be in the background management, dynamic modification of the home page display pictures and link address.

This is the only way to share ideas with you.

For example, the demand is this: The page turns to show the pictures are the pictures in the news, click on the image to jump to the corresponding news content page, so the background can set each news in the homepage display pictures, if displayed, then select this news in the home page display pictures (each news may have more than one picture), after selection, Update the database, of course, can also be canceled on the first page display.

In the database, the main fields of the news table are:

NewsId Newstitle Newscontent Isshow ImageUrl IsEnabled

Newscontent is the news content, after the Rich text editor edited, stored in HTML (which will contain the picture path in the news), Isshow indicates whether to display on the first page ("Yes" or "no"), ImageUrl indicates the path of the displayed picture if it is displayed on the first page.

First say cancel the news on the homepage display:

Cancel on the first page display is very simple, directly update the database field Isshow to "no", because when the first page loads, only the Isshow field is queried for "yes" news.


Besides setting up a news on the homepage shows:

If you want to set a news picture on the first page, you need to find out what images are included in this news content (just get their path), and the core code for getting these image paths in the news content is as follows (C # implementation):

 #region interceptimagesurl-get the picture path from the HTML-formatted news content-Hu Yuyang/// Lt;summary>/////From HTML-formatted news content///</summary>//<param name= "Content" > news content </ param>///<returns>List<String> type </returns> list<string> interceptimagesurl (stri            ng content) {Regex R;            Match m;            int i = 0;            list<string> imageurllist = new list<string> ();            String imageUrl = ""; R = new Regex ("src\\s*=\\s* (?: \") (? <1>[^\ "]*) \" | (? <1>\\s+)) ", Regexoptions.ignorecase |            regexoptions.compiled); for (M = R.match (inputstring); m.success; m = M.nextmatch ()) {IMAGEURL = m.groups[1].                Value;                i++;            Imageurllist.add (IMAGEURL);        } return imageurllist; } #endregion 
         

This function eventually intercepts all of the news's image address collection according to the news content, and then simply displays the pictures, selects one, updates to the ImageUrl field in the database, and updates isshow to "yes".


Finally, the setting display and the cancellation display can be realized, in the homepage display of course also is good to run.

Query the database in the first page display (isshow field is "yes") of the news, in the first page display, in the. NET environment if the. aspx way, you can use C # syntax to traverse the display, you can use repeater, etc., if you use MVC, you can use razor syntax to traverse the display. In the JSP environment, you can use Java syntax to traverse, or you can use JSTL tags and other ways.




NewsId Newstitle Newscontent IsEnabled Isshow ImageUrl

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The background management of the Web page

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.