特色图像代码在可湿性粉剂中存储在哪里?

时间:2011-08-25 作者:Wordpressor

嗯,我正在寻找这两个小容器的源代码(PHP后端、HTML前端和用于附加图像的JS):

Featured Image

我想根据特色图片代码构建一个主题选项,但我找不到它。我很确定它在wp admin目录的某个地方,但我在那里花了很长时间,什么也没找到。

有什么线索吗?

3 个回复
最合适的回答,由SO网友:Rarst 整理而成

该元框的标记是由生成的_wp_post_thumbnail_html() 函数,包含在wp-admin/includes/post.php.

SO网友:François J.

下面是一个完整的示例Featured image meta box 在外部显示和工作wp-admin/post.php 页面上下文(自WordPress 4.6以来,请参见wp-admin/includes/post.php), 这可能是您想知道代码存储在哪里的原因之一:

/**
 * Featured image metabox
 *
 * @uses _wp_post_thumbnail_html
 *
 * @param int    $post_id   Post ID.
 * @param string $post_type Post type.
 */
function featured_image_metabox( $post_id, $post_type ) {

    // @see edit-form-advanced.php
    $thumbnail_support = current_theme_supports( \'post-thumbnails\', $post_type ) && post_type_supports( $post_type, \'thumbnail\' );

    if ( ! $thumbnail_support ||
        ! current_user_can( \'upload_files\' ) ) {

        return;
    }

    // All meta boxes should be defined and added before the first do_meta_boxes() call (or potentially during the do_meta_boxes action).
    require_once ABSPATH . \'wp-admin/includes/meta-boxes.php\';

    if ( ! $post_id ) {
        // New post.
        $post = get_default_post_to_edit( $post_type, true );

        // Fix PHP error. Add filter so get_post( $post ) returns our post!
        $post->filter = \'raw\';
    } else {
        $post = get_post( $post_id );
    }

    $thumbnail_id = get_post_meta( $post->ID, \'_thumbnail_id\', true );

    if ( ! $thumbnail_id ) {

        $thumbnail_id = -1;
    }

    $post_type_object = get_post_type_object( $post_type );

    $title = $post_type_object->labels->featured_image;
    ?>
    <script>
        jQuery( document ).ready(function( e ) {
            wp.media.view.settings.post.id = <?php echo json_encode( $post->ID ); ?>;
            wp.media.view.settings.post.featuredImageId = <?php echo json_encode( $thumbnail_id ); ?>;
            wp.media.view.settings.post.nonce = <?php echo json_encode( wp_create_nonce( \'update-post_\' . $post->ID ) ); ?>;
        });
    </script>
    <div id="poststuff" style="min-width: 320px;">
        <div id="postimagediv" class="postbox">
            <h2 class=\'hndle\'><span><?php echo esc_html( $title ); ?></span></h2>
            <div class="inside">
            <?php
                echo _wp_post_thumbnail_html( $thumbnail_id, $post );
            ?>
            </div>
        </div>
    </div>
    <?php
}

Working example (Sensei LMS course wizard), in the wp-admin, but outside the post context

结束

相关推荐

404从wp-Content/Uploads/获取图像时

我在获取图像时获得404状态,http仍然包含该图像。图像显示在浏览器中,但404代码中断了一些应用程序。对wp内容/上载/的调用被重定向到。htaccess:<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\\.php$ - [L] RewriteRule (.*) /index.php?getfile=$1 [L] </IfModule>&