为Wordpress循环编写自己的函数
我想在我的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
属性()。假设我的插件保存了自定义元标记“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);
}