wordpress建站中如何自带函数获取文章缩略图ID,下面web建站小编给大家简单介绍一下get_post_thumbnail_id函数的基本用法!
函数原型:
get_post_thumbnail_id( int|WP_Post $post = null ): int|false
参数说明:
$post,文章 ID 或 文章对象。
开启文章缩略图功能:
add_theme_support( 'post-thumbnails' );
函数源码:
function get_post_thumbnail_id( $post = null ) {
$post = get_post( $post );
if ( ! $post ) {
return false;
}
$thumbnail_id = (int) get_post_meta( $post->ID, '_thumbnail_id', true );
return (int) apply_filters( 'post_thumbnail_id', $thumbnail_id, $post );
}
调用方法:
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => 'any',
'post_parent' => $post->ID,
'exclude' => get_post_thumbnail_id(),
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo apply_filters( 'the_title', $attachment->post_title );
the_attachment_link( $attachment->ID, false );
}
}
php语法对index.php首页进行判断(根据需要显示不同页面)
wordpress新建页面中页面属性里没有“模板”选项解决方法
上面是“wordpress教程如何获取文章缩略图ID”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_4485.html
workflows工作流
一只在森林里漫步的麋鹿ComfyUI工作流
一只蚂蚁在花丛中找食物ComfyUI工作流
汉堡里的一只毛茸茸的小猫ComfyUI工作流
一只沮丧的卡通小丑鱼ComfyUI工作流
文生图工作流:一幅海底睡莲,碧海蓝天comfyui工
一张超现实主义美女照片ComfyUI工作流
一张皮卡丘向观众眨眼的逼真照片ComfyUI工作流
一张科幻照片,火星车在沙漠里ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

css3搭积木叠加图形
HTML5 Canvas 刻度尺
利用css3做一个动态loading效果
利用css绘画棋盘布局(象棋)
黑客入侵效果代码
css3实现星球旋转
如何利用css3+js做一个下雨效果
css3做一个风雨雷电天气动态图标










