乖乖乖乖 發表於 2023-9-28 00:00:00

wordpress上传图片不自动生成缩略图的解决方法

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
因为站点不需要显示这么多图片,只需要原图就OK了,所以就要修改下媒体设置。打开设置-&gt;媒体,将不需要的缩略图宽度高度都设置为0就可以了。如下图:<br><br><img title="wordpress上传图片不自动生成缩略图的解决方法" alt="wordpress上传图片不自动生成缩略图的解决方法" id="theimg" src="https://zhuji.jb51.net/uploads/img/202305/ec4f70691309248f8f02da1981731b2e.jpg" style="max-width:100%!important;height:auto!important;border: 1px solid rgb(204, 204, 204); vertical-align: middle; padding: 1px; overflow: hidden; max-width: 696px; width: 526px; height: 204px;"><br><br>
但是这样设置之后,还是会生成其它分辨率的缩略图,笔者猜测应该是主题的问题,于是就去主题内查找,笔者用的主题是themolio。后来在主题文件的functions.php中找到了这样的代码:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
 </p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span>
</div>
代码如下:</div>
<div id="phpcode1" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
function themolio_setup() {&lt;/p&gt; &lt;p&gt; /* Make Themolio available for translation.<br>
* Translations can be added to the /languages/ directory.<br>
* If you're building a theme based on Themolio, use a find and replace<br>
* to change 'themolio' to the name of your theme in all the template files.<br>
*/<br>
load_theme_textdomain('themolio', get_template_directory().'/languages' );<br>
add_editor_style();<br>
add_theme_support('automatic-feed-links');<br>
add_theme_support('post-thumbnails');&lt;/p&gt; &lt;p&gt; /**<br>
* This sets up the image size for the grid based top-down layouts (with no sidebar).<br>
* If you change the width/height of your content,<br>
* you will have to modify the width and height mentioned below as well<br>
*/<br>
add_image_size('themolio-two-col-grid-image-nosidebar',460,300,true);<br>
add_image_size('themolio-three-col-grid-image-nosidebar',290,200,true);<br>
add_image_size('themolio-four-col-grid-image-nosidebar',210,150,true);&lt;/p&gt; &lt;p&gt; /**<br>
* This sets up the image size for the grid based top-down layouts (with sidebar).<br>
* If you change the width/height of your content,<br>
* you will have to modify the width and height mentioned below as well<br>
*/<br>
add_image_size('themolio-two-col-grid-image-sidebar',356,250,true);<br>
add_image_size('themolio-three-col-grid-image-sidebar',230,150,true);<br>
add_image_size('themolio-four-col-grid-image-sidebar',171,110,true);&lt;/p&gt; &lt;p&gt; /**<br>
* This sets up the image size for the featured image.<br>
* If you change the width/height of your content,<br>
* you will have to modify the width and height mentioned below as well<br>
*/<br>
add_image_size('themolio-featured-image',800,300,true);&lt;/p&gt; &lt;p&gt; register_nav_menu('primary', __('Primary Menu', 'themolio'));&lt;/p&gt; &lt;p&gt; add_theme_support('post-formats', array('link', 'gallery', 'status', 'quote', 'image', 'video'));&lt;/p&gt; &lt;p&gt; if(themolio_is_wp_version('3.4')) {<br>
add_theme_support('custom-background');<br>
} else {<br>
add_custom_background();<br>
}<br>
}</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
 </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
其中add_image_size就是增加缩略图设置的方法,根据需要注释掉即可。其它主题也可以依此类推,只要搜索关键词add_image_size,应当就能找到缩略图的设置。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
最后生成多张缩略图的问题就搞定了。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
友情提示</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
如果日后有需要缩略图,可以在媒体-&gt;媒体库-&gt;选择需要的图片点编辑-&gt;编辑图片,然后就可以裁剪图片了。最后报下wordpress和使用主题的版本:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
wordpress是3.4.1版本<br>
主题是Themolio,版本是1.2</p>
頁: [1]
查看完整版本: wordpress上传图片不自动生成缩略图的解决方法