Home > CMS Tutorial > DEDECMS > body text

How dedecms implements random calling of thumbnails on list pages

藏色散人
Release: 2019-12-14 10:07:25
Original
1777 people have browsed it

How dedecms implements random calling of thumbnails on list pages

dedecmsHow to implement random calling of thumbnails on list pages?

Friends who have used DEDECMS should know that some template list pages require thumbnails. To call the thumbnails in the content, you can use the system's own script to call the first picture. However, not all of our content has images, and sometimes the first image is not necessarily the standard thumbnail size that fits the size. In short, the user experience is not good, especially if the editor forgets or does not know how to upload the thumbnail. It will definitely affect the website.

Recommended learning: Dream Weaver cms

The steps for randomly calling thumbnail images are as follows:

1. Our original template The script that calls the thumbnail is like this:

The code is as follows:

[field:array runphp=&#39;yes&#39;]@me = (empty(@me[&#39;litpic&#39;]) ? "" : "<a href=&#39;{@me[&#39;arcurl&#39;]}&#39; class=&#39;preview&#39;><img src=&#39;{@me[&#39;litpic&#39;]}&#39;/></a>"); [/field:array]
Copy after login

2. It needs to be replaced with what I prepared:

The code is as follows:

<a href="[field:arcurl/]" title="[field:title/]" target="_blank"><script language="JavaScript" src="/images/road.js"></script></a>
Copy after login

3. Upload the following JS file and prepared images to the host.

The code is as follows:

var m=20; 
var n=Math.floor(Math.random()*m+1) 
document.write ("<img src=&#39;/images/nt"+n+".jpg&#39; border=0 width=148 height=118 />");
Copy after login

One thing to note is that we’d better prepare 20-30 pictures with a fixed thumbnail size, because the fixed size layout looks better and will not be compressed or deformed. If you list 10 contents, if there are only 10 pictures, a few pictures will be repeated randomly, and the experience is not very good. If there are more pictures, the chance of duplication will be smaller. That's it, just refer to it if necessary.

The above is the detailed content of How dedecms implements random calling of thumbnails on list pages. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!