更改wordpress中帖子的发布日期格式

时间:2014-02-12 03:03:48

标签: wordpress date format printf

我想要一些帮助。我想将日期格式更改为我的wordpress主题中的数字。目前它设定于2014年2月5日,但我希望它像02-05-14。我不是一个php编码器,但我认为它与我从functions.php复制的sprintf函数有关。下面的代码来自我的子主题中的functions.php文件。

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
    <div class="featured-post">
        <?php _e( 'Featured post', 'twentytwelve' ); ?>
    </div>
    <?php endif; ?>



    <header class="entry-header">

    <?php if ( is_search() || is_archive () || is_category () || is_tag () || is_home() ) : // Only display Excerpts for Search ?>


        <?php //if ( !(is_search() || is_archive() || is_category() || is_tag() || is_home()) ) : // Only display Excerpts for Search ?>
        <?php //the_post_thumbnail(); ?>
        <?php //endif; ?>

        <?php if ( is_single() ) : ?>

        <h1 class="entry-title  post-title"><?php the_title(); ?></h1>
        <?php else : ?>


        <?php endif; // is_single() ?>
        <?php if ( comments_open() ) : ?>
            <!--<div class="comments-link">
                <?php // comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'twentytwelve' ) . '</span>', __( '1 Reply', 'twentytwelve' ), __( '% Replies', 'twentytwelve' ) ); ?>
            </div>--><!-- .comments-link -->
        <?php endif; // comments_open() ?>
        <footer class="entry-meta post-content">



        <?php if ( has_post_thumbnail() ) :
        echo '<figure class="cat-thumb">';
        the_post_thumbnail('category-thumb');
        echo '</figure>';
        endif;
        ?>

                <?php if ( has_post_thumbnail() ) {
                    echo '<div id="blogPostContent">'; }?>



                <p class="post-title"><a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'twentytwelve' ), the_title_attribute( 'echo=0' ) ) ); ?>"    rel="bookmark"><?php the_title(); ?></a></p>

                <div class="entry-summary">


                <div class="postByLine">
                        <?php 
                    $date = sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>',
                    esc_url( get_permalink() ),
                    esc_attr( get_the_time() ),
                    esc_attr( get_the_date( 'c' ) ),
                    esc_html( get_the_date() )
                    );

                    $author = sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
                            esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
                            esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
                            get_the_author()
                        );

                        echo ' Published on ' . $date . ' | By ' . $author . ' | ';


                    if ( comments_open() ) : ?>

                    <?php comments_popup_link( '<span class="leave-reply">' . __( 'No Comments', 'twentytwelve' ) . '</span>', __( '1 Comment', 'twentytwelve' ), __( '% Comments', 'twentytwelve' ) ); ?>

                        <?php endif; // comments_open()
                    ?>
                </div>


                    <?php the_excerpt(); ?><span class="read_more"><a href="<?php the_permalink(); ?>">Read More</a></span>

                </div><!-- .entry-summary -->

                <?php else : ?>
                <div class="entry-content">
                    <?php the_content( __( 'Continue reading  <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?>
                    <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
                </div><!-- .entry-content -->
                <?php endif; ?>


<?php if ( has_post_thumbnail() ) {
echo '</div>'; } ?> <!-- end post content div -->



    </footer>
    </header><!-- .entry-header -->



    <footer class="entry-meta">
        <? // php twentytwelve_entry_meta(); ?>
        <?php edit_post_link( __( 'Edit', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?>
        <?php if ( is_singular() && get_the_author_meta( 'description' ) && is_multi_author() ) : // If a user has filled out their description and this is a multi-author blog, show a bio on their entries. ?>
            <div class="author-info">
                <div class="author-avatar">
                    <?php echo get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'twentytwelve_author_bio_avatar_size', 68 ) ); ?>
                </div><!-- .author-avatar -->
                <div class="author-description">
                    <h2><?php printf( __( 'About %s', 'twentytwelve' ), get_the_author() ); ?></h2>
                    <p><?php the_author_meta( 'description' ); ?></p>
                    <div class="author-link">
                        <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author">
                            <?php printf( __( 'View all posts by %s <span class="meta-nav">&rarr;</span>', 'twentytwelve' ), get_the_author() ); ?>
                        </a>
                    </div><!-- .author-link -->
                </div><!-- .author-description -->
            </div><!-- .author-info -->
        <?php endif; ?>
    </footer><!-- .entry-meta -->
</article><!-- #post -->

3 个答案:

答案 0 :(得分:4)

  • 信息中心&gt;设置&gt;一般

  • 然后,您可以选择您喜欢的格式:

enter image description here

  • 选择自定义并将文本框的内容替换为m-d-y

答案 1 :(得分:2)

试试这个..

<?php the_time('d-m-y') ?>

答案 2 :(得分:2)

您可以从wp-admin设置&gt;设置日期格式。一般日期格式..根据日期格式更改检查wp-admin general settings下面的图像

在自定义字段上添加m-d-Y来执行此操作。