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='yes']@me = (empty(@me['litpic']) ? "" : "<a href='{@me['arcurl']}' class='preview'><img src='{@me['litpic']}'/></a>"); [/field:array]
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>
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='/images/nt"+n+".jpg' border=0 width=148 height=118 />");
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!