最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Displaying the Month and Year that a page was Created?

programmeradmin1浏览0评论

Question

How can I display only the Month and Year that a page was created?

Background

I have a page that will get changes has a field that shows the month and year. It needs to be in Month and year format like "December 2013"

Code

I previously had this in my template, to display (for example) December 2013:

<time><?php the_time('F Y') ?>:</time>

But since it will only show up on a specific page I wrote this

<?php 
    if ( is_page('about/mission-statement/')) {
        $post_month_year = get_post_time(get_option('date_format'), false, $post, true);
        echo '<time>' . $post_month_year . ':' . '</time>';
    }
?>

But that gives me the date with the day in addition, December 12, 2013.

So the problem is that variable. I thought I could just do something like

$post_month_year = 'the_time('F Y’)';

I just need the month and year. What did I do wrong and how can I best address this?

Question

How can I display only the Month and Year that a page was created?

Background

I have a page that will get changes has a field that shows the month and year. It needs to be in Month and year format like "December 2013"

Code

I previously had this in my template, to display (for example) December 2013:

<time><?php the_time('F Y') ?>:</time>

But since it will only show up on a specific page I wrote this

<?php 
    if ( is_page('about/mission-statement/')) {
        $post_month_year = get_post_time(get_option('date_format'), false, $post, true);
        echo '<time>' . $post_month_year . ':' . '</time>';
    }
?>

But that gives me the date with the day in addition, December 12, 2013.

So the problem is that variable. I thought I could just do something like

$post_month_year = 'the_time('F Y’)';

I just need the month and year. What did I do wrong and how can I best address this?

Share Improve this question edited Jun 15, 2020 at 8:21 CommunityBot 1 asked Sep 12, 2017 at 19:49 JGallardoJGallardo 1941 silver badge11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

This worked for me. I created variables for both the month of the post and the year of the post.

<?php
    $post_month  = get_the_time('F');
    $post_year = get_the_time('Y'); 
    if ( is_page('about/mission-statement/')) {
        echo '<time>' . $post_month . ' ' . $post_year . ':' . '</time>';
    }
?>
发布评论

评论列表(0)

  1. 暂无评论