那么,这里是没有任何参数的原始函数(wordpress)
public static function getCurrent() {
$post = get_post();
$profiles = new MY_images($post->ID);
return $profiles;
}
用于以下变量:
$my_site_images = MY_images::getCurrent();
它从getCurrent()
中得到$post->ID
现在,我想自定义它,以便我可以在其中添加任何id
或将其保留为空的默认功能,如以下:
$my_site_images = MY_images::getCurrent(343); (where the "post id" is 343)
我需要对原始函数做什么修改才能在其中添加任何ID ??
谢谢很多!
你可以选择传递一个post id或者留空来获取当前的post id。
public static function getCurrent($post_id=false) {
if($post_id !== false) {
$profiles = new MY_images($post_id);
} else {
$post = get_post();
$profiles = new MY_images($post->ID);
}
return $profiles;
}