在帖子预览中显示POST日期

时间:2014-05-08 09:16:21

标签: php wordpress date post preview

我使用' get_post_date()在我的主页的每个帖子预览中显示日期。我唯一的问题是这个命令返回页面的pubblication日期而不是帖子的pubblication日期。我在帖子页面尝试了相同的命令,结果是正确的。 如何显示正确的日期?

<?php
$block = $block_data[0];
$settings = $block_data[1];
?>
<?php if($block === 'title'): ?>

<div class="blocchetto"></div>
<div style="font-family: 'Prata',serif;font-size: 12px; margin-bottom:2px">
<?php echo get_the_date("d.m.Y",$post->ID); ?> </div>
<h2 class="post-title">
    <?php echo !empty($settings[0]) && $settings[0]!='no_link' ? $this->getLinked($post, $post->title, $settings[0], 'link_title') : $post->title ?>
</h2>

<?php elseif($block === 'image' && !empty($post->thumbnail)): ?>

<div class="post-thumb">
    <?php echo !empty($settings[0]) && $settings[0]!='no_link' ? $this->getLinked($post, $post->thumbnail, $settings[0], 'link_image') : $post->thumbnail ?>
</div>

<?php elseif($block === 'text'): ?>

<div class="entry-content">
    <?php echo !empty($settings[0]) && $settings[0]==='text' ?  $post->content : $post->excerpt; ?>
</div>
<?php elseif($block === 'link'): ?>

<div>
<a href="<?php echo $post->link ?>" id="vc_read_more" class="vc_read_more" title="<?php echo esc_attr(sprintf(__( 'Permalink to %s', "js_composer" ), $post->title_attribute)); ?>"<?php echo $this->link_target ?>><?php _e('Read more...', "js_composer") ?></a>



</div>



<?php endif; ?>

1 个答案:

答案 0 :(得分:0)

使用此

获取日期
<?php echo $post->post_date; ?>

    WP_Post Object
    (
        [ID] => 1
        [post_author] => 1
        [post_date] => 2014-05-31 10:11:20
        [post_date_gmt] => 2014-05-31 10:11:20
        [post_content] => Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!dsadadsdasdasdsdadasdsadasdasdarvi
        [post_title] => Hello world! 
        [post_excerpt] => this is a excerpt.ravi
        [post_status] => future
        [comment_status] => open
        [ping_status] => open
        [post_password] => 
        [post_name] => hello-world
        [to_ping] => 
        [pinged] => 
        [post_modified] => 2014-05-08 11:56:31
        [post_modified_gmt] => 2014-05-08 11:56:31
        [post_content_filtered] => 
        [post_parent] => 0
        [guid] => http://192.168.1.11/soci39/?p=1
        [menu_order] => 0
        [post_type] => post
        [post_mime_type] => 
        [comment_count] => 1
        [filter] => raw
    )