添加php参数

时间:2015-09-26 23:42:47

标签: php wordpress

所以,这里是原始函数,没有任何参数(wordpress)

public static function getCurrent() {
    $post = get_post();
    $profiles = new MY_images($post->ID);
    return $profiles;
}

用于以下变量:

$my_site_images = MY_images::getCurrent();

因此,它从$post->ID

获得getCurrent()

现在,我想自定义它,以便我可以在其中添加任何id或将其留空以用于默认功能,如下所示:

$my_site_images = MY_images::getCurrent(343);  (where the "post id" is 343)

我需要对原始函数进行哪些修改才能在其中添加任何ID?

非常感谢!

1 个答案:

答案 0 :(得分:3)

您可以选择将其传递给帖子ID或将其留空以获取当前的帖子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;
}
相关问题