时间:2021-05-02
代码如下:
<?php
//Put this in functions.php
function get_primary_image($id, $size){
$featured = wp_get_attachment_image_src( get_post_thumbnail_id($id), $size, false);
if($featured){
$childURL = $featured['0'];
}else{
$children = get_children(array('post_parent' => $id, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => 1));
reset($children);
$childID = key($children);
//$childURL = wp_get_attachment_url($childID);
$childArray = wp_get_attachment_image_src($childID, $size, false);
$childURL = $childArray['0'];
if(empty($childURL)){
$childURL = get_bloginfo('template_url')."/images/default.png";
}
}
return($childURL);
}
//Run this in the loop (or any place you'd like - as long as you have an ID to feed it..)
//First argument is the ID..
//Second argument is the size.. It'll handle 'large', 'medium', 'thumbnail' or even
'array(100, 100)'..
get_primary_image(get_the_ID(), 'large');
?>
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
1.自定义主题图片大小图片是WordPress主题的重要组成部分,但开发者们有时会忘了对主题图片进行优化。主题图片包括CSS背景图,模板logo,默认储存图片、
灵动标签(e:loop)格式:复制代码代码如下:[e:loop={栏目ID/专题ID,显示条数,操作类型,只显示有标题图片,附加SQL条件,显示排序}]模板代码
[e:loop={栏目ID,显示条数,操作类型,只显示有标题图片}]
有标题图片就输出标题图片,如果没有就输出固定图片,代码如下![e:loop={0,10,3,0,'','newstimeASC'}][/e:loop]或"/>去
[e:loop={栏目ID,显示条数,操作类型,只显示有标题图片,附加SQL条件,显示排序}]
Copyright © 1999-2023 中企动力科技股份有限公司(300.cn)All Rights Reserved
京公网安备11030102010293号 京ICP证010249-2