Php Wordpress post->;身份问题
这是一个wordpress问题。我正在尝试使用一些代码,这些代码在我的主页内页模板上运行良好:Php Wordpress post->;身份问题,php,wordpress,Php,Wordpress,这是一个wordpress问题。我正在尝试使用一些代码,这些代码在我的主页内页模板上运行良好: query_posts('cat=4'); // The Loop echo '<div id="cal_details"><ul>'; while ( have_posts() ) : the_post(); $cal_date_j = date('j', intval(get_post_meta($post->ID, 'date
query_posts('cat=4');
// The Loop
echo '<div id="cal_details"><ul>';
while ( have_posts() ) : the_post();
$cal_date_j = date('j', intval(get_post_meta($post->ID, 'date_value', true)));
$cal_date_n = date('n', intval(get_post_meta($post->ID, 'date_value', true)));
$my_array[] = date('j, n', intval(get_post_meta($post->ID, 'date_value', true)));
$issetdate = get_post_meta($post->ID, 'date_value', true);
if (isset($issetdate)) {
echo '<li class="cal_event_li list_item_' . $cal_date_j . '_' . $cal_date_n . '">';
echo '<a href="' . get_permalink() . '">';
the_title();
echo '</a></li>';
}
endwhile;
echo '</ul></div>';
query_posts('cat=4');
//环路
回声“”;
while(have_posts()):the_post();
$cal_date_j=date('j',intval(get_post_meta($post->ID,'date_value',true));
$cal_date_n=date('n',intval(get_post_meta($post->ID,'date_value',true));
$my_array[]=date('j,n',intval(get_post_meta($post->ID,'date_value',true));
$issetdate=get\u post\u meta($post->ID,'date\u value',true);
if(isset($issetdate)){
echo'- ';
回音“
”;
}
结束时;
回声“
”;
但是,这在内部页面上似乎不起作用。所有标题链接都被正确输出,但它不会正确打印get_post_元部分
列表项都显示类似于
我想我尝试使用$post->ID的方式可能存在一些问题,但我不确定这里发生了什么。有什么想法吗?尝试用内部页面中的_ID()替换$post->ID。像这样的
query_posts('cat=4');
// The Loop
echo '<div id="cal_details"><ul>';
while ( have_posts() ) : the_post();
$cal_date_j = date('j', intval(get_post_meta(the_ID(), 'date_value', true)));
$cal_date_n = date('n', intval(get_post_meta(the_ID(), 'date_value', true)));
$my_array[] = date('j, n', intval(get_post_meta(the_ID(), 'date_value', true)));
$issetdate = get_post_meta(the_id(), 'date_value', true);
if (isset($issetdate)) {
echo '<li class="cal_event_li list_item_' . $cal_date_j . '_' . $cal_date_n . '">';
echo '<a href="' . get_permalink() . '">';
the_title();
echo '</a></li>';
}
endwhile;
echo '</ul></div>';
query_posts('cat=4');
//环路
回声“”;
while(have_posts()):the_post();
$cal_date_j=date('j',intval(get_post_meta(ID(),'date_value',true));
$cal_date_n=date('n',intval(get_post_meta)(ID(),'date_value',true));
$my_array[]=date('j,n',intval(get_post_meta(ID(),'date_value',true));
$issetdate=get_post_meta(_id(),'date_value',true);
if(isset($issetdate)){
echo'- ';
回音“
”;
}
结束时;
回声“
”;
当您使用查询帖子时
您必须调用全局$post
以获取帖子元。如果您只调用一个类别,为什么不使用归档模板呢
另外,如果您要使用query\u posts
请确保在单词后重置查询,以便插件、边栏等仍然可以与循环进行条件交互等
global %post;
query_posts('cat=4');
// The Loop
//more stuff
endwhile;
wp_reset_query();
这段代码是为一个插件编写的,它将日期输入到侧边栏上的日历中,这就是为什么我不能使用归档页面。