当前位置:网站首页>为WordPress相关日志插件增加自动缩略图功能
为WordPress相关日志插件增加自动缩略图功能
2022-06-11 11:07:00 【星哥玩云】
WordPress 相关日志插件:WordPress Related Posts,这个也是由水煮鱼制作的插件,其中有一项功能可以通过自定义字段显示缩略图,对于一个新博客而言,可以慢慢添加,但是对于一个已经有几百上千的日志,如果确实需要相关日志只显示图片而不需要使用标题的类型,这个时候你去自定字段一个个修改,耗时不说,累都累死了。我想到了修改,经过在源码的基础上修改后,适用一切正常,至于漂亮与否,还需要各位自己修改了,毕竟修改PHP并且要设计的好看。
修改的主要作用是在大量文章需要设置自定义字段来达到相关日志显示缩略图时,可以使用我修改过的代码,为设置您的每篇文章的第一张图片规律性的替换,比如规律性的替换.jpg 为 _s.jpg 不仅适用于flickr,一些大型网站也是比较适合的,wordpress的自带图片库也可以适用,但是具体怎么替换后缀名需要你自己手动修改下代码。 注意: 只是一些小的改动,插件源码来自于水煮鱼 插件设置不需要勾选 Related Posts with Thumbnail(给相关日志显示缩略图)
下载相关日志只显示缩略图插件:
哪些地方你可能需要改动:
$content = $related_post-> post_content;
preg_match_all('|<img.*?src=[\'"](.*?)[\'"].*?>|i', $related_post->post_content, $matches);
$img_src = $matches[1][0]; //first photo if (eregi("flickr.com",$img_src)){ $img_url = str_replace(".jpg", "_s.jpg", $img_src); }else{ $img_url=$img_src; }
以上你可以设置怎么替换图片后缀,以上只抓取每篇文章的第一张图片。
和
$output .= '<a href="'.get_permalink($related_post->ID).'" title="'.wptexturize($related_post->post_title).'"><img style="border: 2px solid black; width: 75px;" src="' . $img_url . '" /></a>';
以上你可以设置图片显示格式,有漂亮的格式教我。
效果参考地址:http://www.babyshoot.cn/2010/01/22/dreaming-of-forever.html
这样一来,就不需要每篇文章都去修改添加自定义字段的缩略图图片地址了。
源码来源于:http://fairyfish.net/2007/09/12/wordpress-23-related-posts-plugin/
边栏推荐
- Bad navigation category bar code version
- The complete manual of the strongest Flink operator is a good choice for the interview~
- JS prototype. The find () method has no effect on the object array. It is urgent...
- 想做钢铁侠?听说很多大佬都是用它入门的
- WordPress用户名修改插件:Username Changer
- Introduction to database system - Chapter 2 - relational database (2.1~2.3) (important knowledge points)
- 迭代器模式--沙场秋点兵
- 沒有財富就不能自由嗎?
- Processing of uci-har datasets
- Appearance mode -- it has been used in various packages for a long time!
猜你喜欢

JS prototype. The find () method has no effect on the object array. It is urgent...

設置默認收貨地址【項目 商城】

Typeerror: argument of type "Int 'is not Iterable

Introduction to database system -- Chapter 2 -- relational database (2.4 relational algebra)

SpingBoot+Quartrz生产环境的应用支持分布式、自定义corn、反射执行多任务

命令模式--进攻,秘密武器

985 University doctors became popular because of their thanks in classical Chinese! The tutor commented that he not only wrote well in sci

(key points of software engineering review) Chapter IV overall design exercises

Inventory of the 9 most famous work task management software at home and abroad

杰理之获取 BLE 区分复位跟唤醒【篇】
随机推荐
Where is it safer to open an account for soda ash futures? How much capital is needed to buy soda ash futures?
How to form a good habit? By perseverance? By determination? None of them!
AI security and Privacy Forum issue 11 - stable learning: finding common ground between causal reasoning and machine learning
Using domestic MCU (national technology n32g031f8s7) to realize pwm+dma control ws2812
距离度量 —— 欧式距离(Euclidean Distance)
Jerry's acquisition of ble voltage detection and ADC detection inaccuracy [chapter]
数字藏品系统app源码
Summary of English thesis reading knowledge
文件excel导出
使用Yolov5训练好模型调用电脑自带摄像头时出现问题:TypeError: argument of type “int‘ is not iterable的解决方法
SAP Spartacus Reference App Structure
The first day of the new year | at 8:00 p.m. tomorrow, pulsar Chinese developer and user group meeting registration
Set the default receiving address [project mall]
Introduction to database system -- Chapter 2 -- relational database (2.4 relational algebra)
Use pydub to modify the bit rate of the wav file, and an error is reported: c:\programdata\anaconda3\lib\site packages\pydub\utils py:170: RuntimeWarning:
Adapter mode -- can you talk well?
msf cs openssl流量加密
MySQL optimized learning diary 10 - locking mechanism
JS set IP mask
Exness: the progress of Russia Ukraine negotiations is limited, and the RBA's decision remains unchanged