如何将图像附加到分类法..?

时间:2016-11-13 作者:user2584538

我正在使用分类法,我需要将图像附加到分类法。我已重命名我的wp内容文件夹。之后,我无法检索图像路径。我用过

<?php bloginfo(\'url\'); ?>/renamed-folder/uploads/<?php echo get_post_meta(get_my_taxonomy_fields($set->term_id, \'upload_image\'), \'_wp_attached_file\', true); ?>
所以,我的图像代码是

 <img src="<?php bloginfo(\'url\'); ?>/renamed-folder/uploads/<?php echo get_post_meta((get_my_taxonomy_fields($set->term_id, \'upload_image\'), \'_wp_attached_file\', true); ?>" alt="<?php echo $set->name;  ?>" />
如何获取附加于分类法的图像路径。。?

1 个回复
SO网友:jgraup

如果要引用上载目录,请使用https://developer.wordpress.org/reference/functions/wp_upload_dir/

<?php
$upload_dir = wp_upload_dir(); // Array of key => value pairs
/*
    $upload_dir now contains something like the following (if successful)
    Array (
        [path] => C:\\path\\to\\wordpress\\wp-content\\uploads\\2010\\05
        [url] => http://example.com/wp-content/uploads/2010/05
        [subdir] => /2010/05
        [basedir] => C:\\path\\to\\wordpress\\wp-content\\uploads
        [baseurl] => http://example.com/wp-content/uploads
        [error] =>
    )
    // Descriptions
    [path] - base directory and sub directory or full path to upload directory.
    [url] - base url and sub directory or absolute URL to upload directory.
    [subdir] - sub directory if uploads use year/month folders option is on.
    [basedir] - path without subdir.
    [baseurl] - URL path without subdir.
    [error] - set to false.
*/

echo $upload_dir[\'path\'] . \'<br />\';
echo $upload_dir[\'url\'] . \'<br />\';
echo $upload_dir[\'subdir\'] . \'<br />\';
echo $upload_dir[\'basedir\'] . \'<br />\';
echo $upload_dir[\'baseurl\'] . \'<br />\';
echo $upload_dir[\'error\'] . \'<br />\';

$upload_url = ( $upload_dir[\'url\'] );
$upload_url_alt = ( $upload_dir[\'baseurl\'] . $upload_dir[\'subdir\'] );

// Now echo the final result
echo $upload_url . \'<br />\'; // Output - http://example.com/wp-content/uploads/2010/05

// Using year and month based folders, the below will be the same as the line above.
echo $upload_url_alt . \'<br />\'; // Output - http://example.com/wp-content/uploads/2010/05
?>

相关推荐

Custom Taxonomy Page

我正在尝试创建一个显示特定类别的所有子类别的页面。所以在上下文中,我有一个标题为“目的地”的父类别。我希望能够点击目的地,并被引导到一个页面,显示子类别或国家的列表。下面是我试图实现的一个示例,减去顶部的地图-https://www.vagabrothers.com/destinations. 在理想情况下,类别页面的布局将与此页面相同。你可以从上面的例子中看出我的意思。它会使网站上的导航像这样:目的地>国家>个人帖子。我正在使用CPT UI,设置了一个名为“目的地”的自定义帖子类型和类别,然