【问题标题】:WP Featured Image URI instead of Custom FieldWP 特色图像 URI 而不是自定义字段
【发布时间】:2023-03-11 21:11:01
【问题描述】:

我的主题是无法依赖 wordpress 中的自定义字段,而需要使用“特色图片”功能。

这是调用自定义字段的代码

<?php $thumbnail_image = get_post_meta($post->ID, 'post-image', true); ?>

我在 Wordpress 法典中找不到任何关于“特色图片”的文档,但是在这个示例中是否可以调用页面的特色图片的 url?

【问题讨论】:

    标签: php plugins wordpress wordpress-theming


    【解决方案1】:

    这应该会让你继续前进 http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail

    编辑:

    $image_attributes = wp_get_attachment_image_src( get_post_thumbnail_id() );
    $image_src = $image_attributes[0];
    

    【讨论】:

    • 玩这个,我只能得到一个没有 src 属性的图像元素,想知道这是如何工作的。
    • 我将 size 参数添加到 wp_get_attachment_image_src 中,它就像一个魅力。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-03
    • 2016-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多