正在尝试从t31os脚本显示附件窗口中的链接“用作特色图像”

时间:2012-01-12 作者:neomale

我从t31os 这让我有机会在wordpress中添加图片时隐藏字段和按钮。

function myAttachmentFields($form_fields, $post) {
// Can now see $post becaue the filter accepts two args, as defined in the add_fitler
if ( substr( $post->post_mime_type, 0, 5 ) == \'image\' ) {
    $form_fields[\'image_alt\'][\'value\'] = \'\';
    $form_fields[\'image_alt\'][\'input\'] = \'hidden\';

    $form_fields[\'post_excerpt\'][\'value\'] = \'\';
    $form_fields[\'post_excerpt\'][\'input\'] = \'hidden\';

    $form_fields[\'post_content\'][\'value\'] = \'\';
    $form_fields[\'post_content\'][\'input\'] = \'hidden\';

    $form_fields[\'url\'][\'value\'] = \'\';
    $form_fields[\'url\'][\'input\'] = \'hidden\';

    $form_fields[\'align\'][\'value\'] = \'aligncenter\';
    $form_fields[\'align\'][\'input\'] = \'hidden\';

    $form_fields[\'image-size\'][\'value\'] = \'thumbnail\';
    $form_fields[\'image-size\'][\'input\'] = \'hidden\';

    $form_fields[\'image-caption\'][\'value\'] = \'caption\';
    $form_fields[\'image-caption\'][\'input\'] = \'hidden\';

    $form_fields[\'buttons\'] = array(
        \'label\' => \'\',
        \'value\' => \'\',
        \'input\' => \'html\'
    );
    $filename = basename( $post->guid );
    $attachment_id = $post->ID;
    if ( current_user_can( \'delete_post\', $attachment_id ) ) {
        if ( !EMPTY_TRASH_DAYS ) {
            $form_fields[\'buttons\'][\'html\'] = "<a href=\'" . wp_nonce_url( "post.php?action=delete&amp;post=$attachment_id", \'delete-attachment_\' . $attachment_id ) . "\' id=\'del[$attachment_id]\' class=\'delete\'>" . __( \'Delete Permanently\' ) . \'</a>\';
        } elseif ( !MEDIA_TRASH ) {
            $form_fields[\'buttons\'][\'html\'] = "<a href=\'#\' class=\'del-link\' onclick=\\"document.getElementById(\'del_attachment_$attachment_id\').style.display=\'block\';return false;\\">" . __( \'Delete\' ) . "</a>
                     <div id=\'del_attachment_$attachment_id\' class=\'del-attachment\' style=\'display:none;\'>" . sprintf( __( \'You are about to delete <strong>%s</strong>.\' ), $filename ) . "
                     <a href=\'" . wp_nonce_url( "post.php?action=delete&amp;post=$attachment_id", \'delete-attachment_\' . $attachment_id ) . "\' id=\'del[$attachment_id]\' class=\'button\'>" . __( \'Continue\' ) . "</a>
                     <a href=\'#\' class=\'button\' onclick=\\"this.parentNode.style.display=\'none\';return false;\\">" . __( \'Cancel\' ) . "</a>
                     </div>";
        } else {
            $form_fields[\'buttons\'][\'html\'] = "<a href=\'" . wp_nonce_url( "post.php?action=trash&amp;post=$attachment_id", \'trash-attachment_\' . $attachment_id ) . "\' id=\'del[$attachment_id]\' class=\'delete\'>" . __( \'Move to Trash\' ) . "</a><a href=\'" . wp_nonce_url( "post.php?action=untrash&amp;post=$attachment_id", \'untrash-attachment_\' . $attachment_id ) . "\' id=\'undo[$attachment_id]\' class=\'undo hidden\'>" . __( \'Undo\' ) . "</a>";
        }
    }
    else {
        $form_fields[\'buttons\'][\'html\'] = \'\';
    }
}
return $form_fields;
}
// Hook on after priority 10, because WordPress adds a couple of filters to the same     hook - added accepted args(2)
add_filter(\'attachment_fields_to_edit\', \'myAttachmentFields\', 11, 2 );
但有一件事是Use as featured image 链接未出现。有人对我如何显示链接有想法吗Use as featured image 删除链接旁边?这是这个伟大的脚本中唯一缺少的东西,但我不是一个php专家,我试图找出它,但没有找到soluiton。谢谢你的帮助。

当做

1 个回复
SO网友:Evan

“按功能使用”不是字段的一部分,而是表单本身的一部分。您必须确保主题支持post缩略图,以便WP执行其逻辑并有条件地显示项目。

没有一种简单的方法可以覆盖此功能。

下面是为主题启用post缩略图的代码(可能在functions.php文件中)

add_theme_support(\'post-thumbnails\');

结束

相关推荐

images are broken

我有一段代码,用于显示来自RSS提要的每篇帖子上的图像,这些图像将从yahoo images search获取,我将把这段代码粘贴到我的单曲中。php文件,这样它就会出现在我的帖子之后,我在其中一个网站上找到了这段代码,这段代码用于获取图像,但不是从yahoo获取图像,而是从不同的feed获取图像我使用的代码如下:- <?php include_once(ABSPATH.WPINC.\'/rss.php\'); // path to include script $f