Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为Wordpress循环编写自己的函数_Wordpress_Wordpress Theming - Fatal编程技术网

为Wordpress循环编写自己的函数

为Wordpress循环编写自己的函数,wordpress,wordpress-theming,Wordpress,Wordpress Theming,我想在我的wordpress插件中提供我自己的属性()。假设我的插件保存了自定义元标记“myAttribute”。如果我现在宣布 function the_attribute () { echo get_post_meta($post->ID, 'myAttribute', true); } 它将不起作用,因为$post仅在模板循环中可见,而在我的插件中不可见。那么,我如何才能挂接到循环中以获得一个可访问的post对象呢?我认为它只是调用全局$post而已 function th

我想在我的wordpress插件中提供我自己的
属性()。假设我的插件保存了自定义元标记“myAttribute”。如果我现在宣布

function the_attribute () {
    echo get_post_meta($post->ID, 'myAttribute', true);
}

它将不起作用,因为
$post
仅在模板循环中可见,而在我的插件中不可见。那么,我如何才能挂接到循环中以获得一个可访问的post对象呢?

我认为它只是调用全局$post而已

function the_attribute () {
    global $post;
    echo get_post_meta($post->ID, 'myAttribute', true);
}