帖子缩略图 Metabox 未出现在 WordPress 网络上

发布于 2024-11-02 19:48:31 字数 2374 浏览 1 评论 0原文

我最近将包含两个站点的 Wordpress 网络从本地 MAMP 服务器迁移到在线服务器。除了后缩略图的功能外,一切都完美迁移。元框根本不会出现在网络上的任何网站、任何主题中。

我测试了几个启用后缩略图的不同主题,结果是相同的。没有可见的元框!我很困惑,有人有建议吗?

其中一个站点的functions.php 文件是:

if(function_exists('add_theme_support')) {
    add_theme_support('post-thumbnails', array( 'page', 'post', 'portfolio' ));

    /** Register custom size */
    add_image_size('page-image', 620, 620, false);
    add_image_size('portfolio-image', 795, 575, true);
    add_image_size('portfolio-thumbnail', 135, 94, true);
}



//------enable post thumbnail preview for custom columns 
if ( !function_exists('fb_AddThumbColumn') && function_exists('add_theme_support') ) {

    // for post and investments

    function fb_AddThumbColumn($cols) { 
        $cols['thumbnail'] = __('Thumbnail'); 
        return $cols;
    }

    function fb_AddThumbValue($column_name, $post_id) {

            $width = (int) 200;
            $height = (int) 125;


            if ( 'thumbnail' == $column_name ) {
                // thumbnail of WP 2.9
                $thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true );
                // image from gallery
                $attachments = get_children( array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image') );
                if ($thumbnail_id)
                    $thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
                elseif ($attachments) {
                    foreach ( $attachments as $attachment_id => $attachment ) {
                        $thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true );
                    }
                }
                    if ( isset($thumb) && $thumb ) {
                        echo $thumb;
                    } else {
                        echo __('None');
                    }
            }
    }

    // for posts
    add_filter( 'manage_posts_columns', 'fb_AddThumbColumn' );
    add_action( 'manage_posts_custom_column', 'fb_AddThumbValue', 10, 2 );

    // for portfolio
    add_filter( 'manage_portfolio_columns', 'fb_AddThumbColumn' );
    add_action( 'manage_portfolio_custom_column', 'fb_AddThumbValue', 10, 2 );
}
*/

function the_post_thumbnail_url($post_id) {
  echo wp_get_attachment_url( get_post_thumbnail_id($post_id) );
}

I recently migrated a Wordpress network of two sites from a local MAMP server to an online one. Everything migrated perfectly, except the functionality of the Post-Thumbnail. The meta box is simply not appearing in any site, in any theme across the network.

I've tested a few different themes with post-thumbnail enabled, and the result is the same. No metabox is visible! I'm rather stumped, does anyone have suggestions?

The functions.php file for one of the sites is:

if(function_exists('add_theme_support')) {
    add_theme_support('post-thumbnails', array( 'page', 'post', 'portfolio' ));

    /** Register custom size */
    add_image_size('page-image', 620, 620, false);
    add_image_size('portfolio-image', 795, 575, true);
    add_image_size('portfolio-thumbnail', 135, 94, true);
}



//------enable post thumbnail preview for custom columns 
if ( !function_exists('fb_AddThumbColumn') && function_exists('add_theme_support') ) {

    // for post and investments

    function fb_AddThumbColumn($cols) { 
        $cols['thumbnail'] = __('Thumbnail'); 
        return $cols;
    }

    function fb_AddThumbValue($column_name, $post_id) {

            $width = (int) 200;
            $height = (int) 125;


            if ( 'thumbnail' == $column_name ) {
                // thumbnail of WP 2.9
                $thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true );
                // image from gallery
                $attachments = get_children( array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image') );
                if ($thumbnail_id)
                    $thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
                elseif ($attachments) {
                    foreach ( $attachments as $attachment_id => $attachment ) {
                        $thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true );
                    }
                }
                    if ( isset($thumb) && $thumb ) {
                        echo $thumb;
                    } else {
                        echo __('None');
                    }
            }
    }

    // for posts
    add_filter( 'manage_posts_columns', 'fb_AddThumbColumn' );
    add_action( 'manage_posts_custom_column', 'fb_AddThumbValue', 10, 2 );

    // for portfolio
    add_filter( 'manage_portfolio_columns', 'fb_AddThumbColumn' );
    add_action( 'manage_portfolio_custom_column', 'fb_AddThumbValue', 10, 2 );
}
*/

function the_post_thumbnail_url($post_id) {
  echo wp_get_attachment_url( get_post_thumbnail_id($post_id) );
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鼻尖触碰 2024-11-09 19:48:32

您必须切换到网络管理模式

,然后转到

设置 > 网络设置

接近尾声时,您会发现

上传设置> 媒体上传按钮

我检查了图像,看到特色图像框出现在我的新帖子管理页面中。

You must switch to Network Admin mode

then go to

Settings > Network settings

near the end you'll find

Upload Settings > Media upload buttons

I checked Images to see the Featured Image box appears in my New Post admin page.

天赋异禀 2024-11-09 19:48:32

当我迁移 Wordpress 网络时,我也遇到了类似的缩略图问题。
我已经使用这段代码修复了它,也许它可以帮助你。您需要将此代码添加到functions.php

<?php
function get_timthumb_thumbnail($post_id = null) {
    global $blog_id;

    //we can access it, so why not use it?
    $is_mu = WP_ALLOW_MULTISITE;

    //if is true it means it's a wordpress MU site and we'll have to do some work
    if($is_mu == true):
        $thumbnail_id=get_the_post_thumbnail($post_id);
        preg_match ('/src="(.*)" class/',$thumbnail_id,$link);
        $imageParts = explode('files/', $link[1]);
        if (!empty($imageParts[1])):
            //check if the image is in the blog directory
            if(@getimagesize('./wp-content/blogs.dir/' . $blog_id . '/files/' . $imageParts[1])):

                $thumbnail = 'http://'.$_SERVER['HTTP_HOST'].'/wp-content/blogs.dir/' . $blog_id . '/files/' . $imageParts[1];

            endif;
            //check if the image is in the main uploads directory (you never know)
            if(@getimagesize('./wp-content/uploads/' . $imageParts[1])):

                $thumbnail = 'http://'.$_SERVER['HTTP_HOST'].'/wp-content/uploads/' . $imageParts[1];

            endif;
                    else:
                            $imageParts = explode('uploads/', $link[1]);
                            if(@getimagesize('./wp-content/uploads/' . $imageParts[1])):
                                $thumbnail = 'http://'.$_SERVER['HTTP_HOST'].'/wp-content/uploads/' . $imageParts[1];
                            endif;
        endif;

    else:
        $thumbnail_id=get_the_post_thumbnail($post_id);
            preg_match ('/src="(.*)" class/',$thumbnail_id,$link);
            $thumbnail = $link[1];
    endif;

    return $thumbnail;
}
?>

要在循环上使用此函数,我添加了如下内容:

<?php $thumb = get_timthumb_thumbnail($post->ID); ?>
<?php if(has_post_thumbnail()){ ?>
    <img src="<?php echo $thumb;?>" class="thumb" />
<?php }else{
    echo '<img src="'.get_bloginfo("template_url").'/img/boyds.png" class="thumbdflt" />';
}?>

问候。

I had a similar problem with thumbnails when I migrated a Wordpress Network.
I've fixed it using this code, maybe it can help you. You need to add this code to functions.php

<?php
function get_timthumb_thumbnail($post_id = null) {
    global $blog_id;

    //we can access it, so why not use it?
    $is_mu = WP_ALLOW_MULTISITE;

    //if is true it means it's a wordpress MU site and we'll have to do some work
    if($is_mu == true):
        $thumbnail_id=get_the_post_thumbnail($post_id);
        preg_match ('/src="(.*)" class/',$thumbnail_id,$link);
        $imageParts = explode('files/', $link[1]);
        if (!empty($imageParts[1])):
            //check if the image is in the blog directory
            if(@getimagesize('./wp-content/blogs.dir/' . $blog_id . '/files/' . $imageParts[1])):

                $thumbnail = 'http://'.$_SERVER['HTTP_HOST'].'/wp-content/blogs.dir/' . $blog_id . '/files/' . $imageParts[1];

            endif;
            //check if the image is in the main uploads directory (you never know)
            if(@getimagesize('./wp-content/uploads/' . $imageParts[1])):

                $thumbnail = 'http://'.$_SERVER['HTTP_HOST'].'/wp-content/uploads/' . $imageParts[1];

            endif;
                    else:
                            $imageParts = explode('uploads/', $link[1]);
                            if(@getimagesize('./wp-content/uploads/' . $imageParts[1])):
                                $thumbnail = 'http://'.$_SERVER['HTTP_HOST'].'/wp-content/uploads/' . $imageParts[1];
                            endif;
        endif;

    else:
        $thumbnail_id=get_the_post_thumbnail($post_id);
            preg_match ('/src="(.*)" class/',$thumbnail_id,$link);
            $thumbnail = $link[1];
    endif;

    return $thumbnail;
}
?>

To use this function on the loop, I had added something like this:

<?php $thumb = get_timthumb_thumbnail($post->ID); ?>
<?php if(has_post_thumbnail()){ ?>
    <img src="<?php echo $thumb;?>" class="thumb" />
<?php }else{
    echo '<img src="'.get_bloginfo("template_url").'/img/boyds.png" class="thumbdflt" />';
}?>

Regards.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文