cool hit counter Backend management of the website home page rotation image_Intefrankly

Backend management of the website home page rotation image


Copyright: This is an original post by the blogger and may not be reproduced without the blogger's permission. https://blog.csdn.net/huyuyang6688/article/details/46687793

Many CMS homepages will have a need for rotating charts that update in real time, as follows.

I recently came across such a requirement in the course of working on a CMS.

I had done a project for a campus website before (for fun on my own), but the frontend rotogram was written dead on the page, ie.

<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="#">
                    <img src="images/Index/show/01.jpg" alt="Main entrance of the school" /></a></li>
                <li><a href="#">
                    <img src="images/Index/show/02.jpg" alt=" School playground" /></a></li>
                <li><a href="#">
                    <img src="images/Index/show/03.jpg" alt=" Exhibition of Ancient Building Models in College of Construction and Engineering" /></a></li>
                <li><a href="#">
                    <img src="images/Index/show/04.jpg" alt=" Graduate of the School of Dance" /></a></li>           
<span style="white-space:pre">	</span></ul>
</div></span>

But in the actual project is certainly to do live, that is, to be able to manage in the background, dynamically modify the home page display images and link addresses.

Just sharing thoughts with you here.

For example, the requirement is this: the pictures displayed on the home page in turn are pictures in the news, click on the picture to jump to the corresponding news content page, so the background can set whether each news in the home page display pictures, if displayed, then select the picture displayed on the home page of this news (there may be more than one picture in each news), after the selection, update the database; of course, you can also cancel the display on the home page.

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

NewsId

NewsTitle

NewsContent

IsShow

ImageUrl

IsEnabled

NewsContent is the news content, which is edited by a rich text editor and stored in html form (which will contain the path to the image in the news), IsShow indicates whether to display it on the front page ("yes" or "no"), and ImageUrl indicates the path to the image displayed if it is displayed on the front page.

First, to remove news from displaying on the front page.

Canceling the display on the front page is simple, just update the database field IsShow to "No", because when the front page loads, it will only query for news with the IsShow field "Yes".

Plus set a news item to display on the front page at.

If you want to set a news picture on the front page, you need to find out which pictures are included in this news content (just get their paths), and use the core code to get the paths of these pictures in the news content as follows (C# implementation method).

<span style="white-space:pre">	</span>#region InterceptImagesUrl- through (a gap)HTML Get the image path in the news content of the format- Hu Yuyang
        /// <summary>
         /// Get the image path from the news content in HTML format
        /// </summary>
        /// <param name="content"> News</param>
        /// <returns>List<String> types</returns>
        List<String> InterceptImagesUrl(string 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(content); m.Success; m = m.NextMatch())
            {
                imageUrl = m.Groups[1].Value;
                i++;
                imageUrlList.Add(imageUrl);
            }
            return imageUrlList;
        }
 <span style="white-space:pre">	</span>#endregion

This function will eventually truncate the set of image addresses in all news based on the news content, then just display these images, select one, update it to the ImageUrl field in the database and update IsShow to "Yes" and that's it.

Finally, setting display and undisplay can be is achieved, displaying on the home page is of course a good idea.

The query database shows in the first page(IsShow The fields are “ be”) news, When displayed on the front page, (located) at.net If the environment with the.aspx way, You can useC# Syntax traversal shows, You can also userepeater etc.; If the usedMVC, You can userazor Syntax for traversal display。 (located) atjsp in an environment, You can usejava grammatical traversal, You can also usejstl Tags etc.。


Recommended>>
1、Shodan Newbies Guide to Getting Started
2、When Machine Learning Meets Computer Vision The Next Part
3、Linux User Management
4、Google chairman predicts that the Internet of Things may cause the Internet to disappear
5、C Course Design Class Assignment 4

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号