0

我很难从主题中的上传文件夹中引用图像。我怎样才能调用那个文件夹?

这是我到目前为止所尝试的:

   add_action( 'init', 'create_post_type' );
   function create_post_type() {
   register_post_type( 'acme_product',
    array(
        'labels' => array(
            'name' => __( 'Products' ),
            'singular_name' => __( 'Product' ),
            'add_new' => __( 'Add Product' ),
            'add_new_item' => __( 'Add New Product' ),
            'edit' => __( 'Edit' ),
            'edit_item' => __( 'Edit Product' ),
            'new_item' => __( 'New Product' ),
            'view' => __( 'View Product' ),
            'view_item' => __( 'View Product' ),
            'search_items' => __( 'Search Products' ),
            'not_found' => __( 'No Products found' )
        ),
        'public' => true,
        'has_archive' => true,
        'menu_icon' =>  get_template_directory_uri() . '/uploads/2013/11/product.png',
        'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' )
    )
);
   }

但问题是,它没有显示在我的仪表板中。有任何想法吗?提前致谢。

4

2 回答 2

1

尝试使用

<?php $upload_dir = wp_upload_dir(); ?>
<?php echo $upload_dir['baseurl']; ?>

在您的 wordpress 安装中获取上传目录路径,因为get_template_directory_uri()检索当前主题的模板目录 URI,而不是 wp-content 文件夹路径

于 2013-11-02T05:47:30.830 回答
1

试试这个:

'menu_icon' => get_bloginfo('template_directory') . '/images/icon.png',
于 2015-05-08T16:31:56.927 回答