首页 wordpress教程

导语:在开发企业主题的时候需要写各种样式的幻灯片,就避免不了一些文字如标题,图片说明这些,看着wordrpess的图片中都有这些选项,就想着能不能在原生功能上进行扩展,以满足各类开需求,后来看wordpress开发文档的代码,发现了它使用get_post_meta()来获取的。

get_post_meta 函数是用来取出自定义字段的值的函数,那么在附件图片中代替文本信息就是一个自定义的值。然后叶子以为图像描述也是自定义的值,结果在`wp_postmeta`没有发现。

SELECT * FROM `wp_postmeta` WHERE `post_id` =109

发现这张图片有以下输出:

338 109 _wp_attached_file 2016/05/wordpress-life_the_post_thumbnail_url_20160608.jpg

339 109 _wp_attachment_metadata a:5:{s:5:”width”;i:1000;s:6:”height”;i:750;s:4:”file”;s:58:”2016/05/wordpress-life_the_post_thumbnail_url_20160608.jpg”;s:5:”sizes”;a:7:{s:9:”thumbnail”;a:4:{s:4:”file”;s:58:”wordpress-life_the_post_thumbnail_url_20160608-150×150.jpg”;s:5:”width”;i:150;s:6:”height”;i:150;s:9:”mime-type”;s:10:”image/jpeg”;}s:6:”medium”;a:4:{s:4:”file”;s:58:”wordpress-life_the_post_thumbnail_url_20160608-300×225.jpg”;s:5:”width”;i:300;s:6:”height”;i:225;s:9:”mime-type”;s:10:”image/jpeg”;}s:12:”medium_large”;a:4:{s:4:”file”;s:58:”wordpress-life_the_post_thumbnail_url_20160608-768×576.jpg”;s:5:”width”;i:768;s:6:”height”;i:576;s:9:”mime-type”;s:10:”image/jpeg”;}s:26:”codilight_lite_block_small”;a:4:{s:4:”file”;s:56:”wordpress-life_the_post_thumbnail_url_20160608-90×60.jpg”;s:5:”width”;i:90;s:6:”height”;i:60;s:9:”mime-type”;s:10:”image/jpeg”;}s:29:”codilight_lite_block_1_medium”;a:4:{s:4:”file”;s:58:”wordpress-life_the_post_thumbnail_url_20160608-250×170.jpg”;s:5:”width”;i:250;s:6:”height”;i:170;s:9:”mime-type”;s:10:”image/jpeg”;}s:29:”codilight_lite_block_2_medium”;a:4:{s:4:”file”;s:58:”wordpress-life_the_post_thumbnail_url_20160608-325×170.jpg”;s:5:”width”;i:325;s:6:”height”;i:170;s:9:”mime-type”;s:10:”image/jpeg”;}s:28:”codilight_lite_single_medium”;a:4:{s:4:”file”;s:58:”wordpress-life_the_post_thumbnail_url_20160608-700×350.jpg”;s:5:”width”;i:700;s:6:”height”;i:350;s:9:”mime-type”;s:10:”image/jpeg”;}}s:10:”image_meta”;a:12:{s:8:”aperture”;s:1:”0″;s:6:”credit”;s:0:””;s:6:”camera”;s:0:””;s:7:”caption”;s:0:””;s:17:”created_timestamp”;s:1:”0″;s:9:”copyright”;s:0:””;s:12:”focal_length”;s:1:”0″;s:3:”iso”;s:1:”0″;s:13:”shutter_speed”;s:1:”0″;s:5:”title”;s:0:””;s:11:”orientation”;s:1:”0″;s:8:”keywords”;a:0:{}}}

340 109 _wp_attachment_image_alt 使用wordpress函数the_post_thumbnail_url()获取缩略图URL

后来明白了,附件图片其实也就是一篇特殊的文章,那么它的标题就是文章标题,图像描述就是文章内容,说明就是文章摘要。

获取图片标题

get_the_title( $post_id)

获取图片的代替文本

get_post_meta( $post_id, ‘_wp_attachment_image_alt’, true )

获取图片描述

get_the_content( $post_id)

获取图片说明

get_the_excerpt($post_id)

会员评论:(0)

声明:本站所有主题/文章除标明原创外,均来自网络转载,版权归原作者所有,如果有侵犯到您的权益,请联系本站删除,谢谢!
©www.sbmzenith.com 2013-2022 All Rights Reserved.
豫ICP备15009393号