【发布时间】:2015-07-28 01:12:37
【问题描述】:
使用 wordpress 4.2.2,当我在子主题 function.php 中使用此代码根据每个帖子类型更改附件上传目录时:
function wpse_16722_type_upload_dir( $args ) {
// Get the current post_id
$id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : '' );
if( $id ) {
// Set the new path depends on current post_type
$newdir = '/' . get_post_type( $id );
$args['path'] = str_replace( $args['subdir'], '', $args['path'] ); //remove default subdir
$args['url'] = str_replace( $args['subdir'], '', $args['url'] );
$args['subdir'] = $newdir;
$args['path'] .= $newdir;
$args['url'] .= $newdir;
return $args;
}
}
add_filter( 'upload_dir', 'wpse_16722_type_upload_dir' );
我得到一个空白页! function.php 中没有空行,并且仅在添加此代码后才会出现问题。我真的需要它来组织我的上传文件夹,但没有空白页。 有什么解决办法吗?
【问题讨论】:
-
空白页表示语法错误。在您打开 PHP 标记(例如
<?php error_reporting(E_ALL); ini_set('display_errors', 1);)之后将错误报告添加到文件顶部,然后是其余代码,以查看它是否产生任何结果。 -
什么都没发生,什么都不显示,空白页
标签: php wordpress path directory attachment