问题描述
我使用 wordpress 3.2,我做了一个这样的查询帖子:
<?php query_posts("posts_per_page=1post=type&page=post_parent=10");?>
然后我试着回答这个帖子的日期,我这样问。
<?php echo the_date(); ?>
它给了我的职位的标题和摘录和永久链接,但没有日期。你认为问题是什么?我相信这是一个很尴尬的事情。
以下是视频页面的模板文件中的代码:
<?php query_posts("posts_per_page=1post=type&page=post_parent=10");?>
<h2>Recent Video</h2>
<h3 class="date"><?php echo the_date(); ?></h3>
<p><strong><?php echo the_title(); ?></strong><?php echo the_excerpt(); ?></p>
<p><a href="<?php%20echo%20the_permalink();%20?>" class="more2">Watch Now</a></p>
这里我尝试把查询放在一个循环中:
<?php query_posts("posts_per_page=1post=type&page=post_parent=10");?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2>Recent Video</h2>
<h3 class="date"><?php echo the_date(); ?></h3>
<p><strong><?php echo the_title(); ?></strong><?php echo the_excerpt(); ?></p>
<p><a href="<?php%20echo%20the_permalink();%20?>" class="more2">Watch Now</a></p>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
the_date() 没有工作,但是 the_title() 等功能起作用。顺便说一下,我的查询更改为 the_post(),这不是我想要的。我想查询最新的视频,就像我在循环之上。
顺便说一下,我在页面中使用了 the_date 功能,它的工作。这可能是问题吗?这是在代码之前,我有一个问题。
<div id="col75" class="firstcol">
<iframe id="video" src="http://www.youtube.com/embed/videoseries?list=<?php%20print%20get_post_meta($post->ID,"playlist_id", true); ?>" width='560' height='350' frameborder="0"></iframe>
<div id="col25">
<h2><?php echo get_post_meta($post->ID,"speaker", true); ?></h2>
<h3 class="date"><?php echo the_date(); ?></h3>
最佳解决方案
看这个 special note about using the `the_date’
SPECIAL NOTE: When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template Tag the_time() or get_the_date() (since 3.0) with a date-specific format string. Use to add the date set in the admin interface.
-
您使用
query_posts拧紧全局变量 -
您回应已经打印到浏览器的功能
-
你实际上是为所有的模板标签。
-
将
echo the_date();更改为:echo get_the_date('F j, Y'); -
从已经打印到浏览器的模板标签中删除回声,或者使用返回值的备用函数。
-
-
使用新的
WP_Query或get_posts代替query_posts -
阅读法典。它告诉你如何使用所有这些功能,是非常有益的:)
次佳解决方案
the_date()仅在以前未打印同一日期的情况下打印日期。不,这与其他类似的功能不一致。但是这是它在 WordPress 的祖先 b2 /cafelog 中的工作原理,向后兼容性总是胜过逻辑… 🙂
要打印日期总是使用 get_the_date()
<?php echo get_the_date(); ?>
要么
<?php echo mysql2date( get_option( 'date_format' ), $post->post_date); ?>
参考文献
注:本文内容整合自 Google/Baidu/Bing 辅助翻译的英文资料结果。如果您对结果不满意,可以加入我们改善翻译效果:薇晓朵技术论坛。