返回顶部
首页 > 资讯 > CMS >Wordpress 显示主题图片的实现代码
  • 574
分享到

Wordpress 显示主题图片的实现代码

Wordpress主题图片 2022-06-12 02:06:20 574人浏览 八月长安
摘要

复制代码代码如下: <?PHP //Put this in functions.php function get_primary_image($id, $size){ $featured =


复制代码代码如下:

<?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');

?>

--结束END--

本文标题: Wordpress 显示主题图片的实现代码

本文链接: https://lsjlt.com/news/32006.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作