2015-09-26 88 views
0

所以,这里是一个没有任何参数(WordPress的)原始功能添加PHP参数

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

这是在下面的变量中:

$my_site_images = MY_images::getCurrent(); 

因此,它得到了$post->IDgetCurrent()

现在,我想定制它,以便我可以在其中添加任何id或将其保留为空,以用于默认功能,例如followin g:

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

我需要对原始函数做些什么修改才能添加任何ID?

谢谢一堆!

回答

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; 
} 
+0

谢谢。欣赏它!得到它的工作。 –