使用其他文件夹图像作为wp帖子缩略图

时间:2019-11-30 14:40:39

标签: php wordpress wordpress-theming custom-wordpress-pages

add_filter( 'upload_dir', 'my_custom_upload_dir' );

function my_custom_upload_dir( $default_dir ) {

if ( ! isset( $_POST['post_id'] ) || $_POST['post_id'] < 0 )
return $default_dir;

if ( get_post_type( $_POST['post_id'] ) != 'photos' )
return $default_dir;

$dir = WP_CONTENT_DIR . '/uploads/photos';
$url = WP_CONTENT_URL . '/uploads/photos';

$bdir = $dir;
$burl = $url;

$subdir = '';
if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
$time = current_time( 'mysql' );
$y = substr( $time, 0, 4 );
$m = substr( $time, 5, 2 );
$subdir = "/$y/$m";
}

$dir .= $subdir;
$url .= $subdir;

$custom_dir = array(
'path' => $dir,
'url' => $url,
'subdir' => $subdir,
'basedir' => $bdir,
'baseurl' => $burl,
'error' => false,
);


return $custom_dir;
}

通过此代码,我在wp-content / uploads文件夹内创建了一个自定义帖子类型的文件夹。现在如何使用这些图像/将这些图像显示为自定义帖子缩略图?

0 个答案:

没有答案