WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to add timestamp to the_content() (4 posts)

  1. joneslee85
    Member
    Posted 4 years ago #

    Hello there,
    I am going to design a short-news style for the post content.

    for example:

    <November 10th 2009> - <paragraph1>
    <paragaph2>

    My question is how to take advantage of filter or action to add the timestamp into the first paragraph of the_content(). Please help. Many thanks

  2. joneslee85
    Member
    Posted 4 years ago #

    Example:

    November 29th, 2009 - Inspire Generations (IG) launches website and is now accepting volunteers starting 1st Jan 2010. IG is offering a very special deal for its grand opening. We are offering 50% off applications fees if you apply before 1st Feb 2010.”

    Blah blah blah blah

    Blhahah

    -------------

    November 27th, 2009 - Inspire Generations (IG) launches website and is now accepting volunteers starting 1st Jan 2010. IG is offering a very special deal for its grand opening. We are offering 50% off applications fees if you apply before 1st Feb 2010.”

    Blah blah blah blah

    Blhahah

  3. MichaelH
    Member
    Posted 4 years ago #

    This in your theme's functions.php should work:

    function prepend_date_to_content($content) {
    global $post;
    $content = mysql2date("F j, Y", $post->post_date) . ' - ' . $content;
    return $content;
    }
    add_filter( 'the_content', 'prepend_date_to_content',9 ); //using priority 9 to force filter to act before wpautop
  4. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    try something like (in the loop):

    <div class="entry">
    <span><?php the_time(' F j Y'); ?> - </span>
    <?php the_content(__('(more...)')); ?>
    </div>

    and the style:

    .entry {
    font-size: 115%;
    line-height:1.5;
      }
    .entry span {
    float:left;
    margin:0;
    padding:0px 5px 0 0;
      }
    .entry p {
    margin:3px 0 12px 0;
      }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.