WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Make all pages show current date (7 posts)

  1. sagdude2002
    Member
    Posted 4 years ago #

    Hi,
    I have a small website with only 3 pages. How can I make all pages show the current date all the time without having to go in and update the pages every day? Thank you.
    Mike

    http://www.MikeBradbury.net

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    <?php echo date('F j, Y'); ?>`

    http://uk2.php.net/manual/en/function.date.php

  3. sagdude2002
    Member
    Posted 4 years ago #

    Hi - thanks for your quick response. Where in the code should I paste this? Here is the date code on the Stylesheet (style.css). Thank you very much.

    .post .date {
    float: right;
    margin:5px 0 0 5px;
    padding:0 10px;
    text-align:center;
    font-size: 0.8em;
    border:#000000 1px solid;
    font-weight:bold;
    background:url(img/vino.gif) no-repeat;
    color:#556677;
    font-family: "Lucida Sans", "Trebuchet MS", Verdana, Arial, Serif;
    }
    .post .date span
    {
    display:block;
    }
    .post .date .day
    {
    font-size:1.6em;
    }

  4. esmi
    Forum Moderator
    Posted 4 years ago #

    The date isn't added to the stylesheet. it's added to the theme templates.

  5. sagdude2002
    Member
    Posted 4 years ago #

    OK, below is the code for the page template (page.php). I want to make sure the month, day and year stack on top of eachother as they are now. I inserted <?php echo date('F j, Y'); ?> but that doesn't stack like it is now. Do you know how I can put the code in to keep the current format? Thanks.

    <?php get_header();?>
    <div id="main">
    <div id="content">
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <p class="date">
    <span class="month">
    <?php the_time('M') ?>
    </span>
    <span class="day">
    <?php the_time('d') ?>
    </span>
    <span class="year">
    <?php the_time('Y') ?>
    </span>
    </p>

  6. sagdude2002
    Member
    Posted 4 years ago #

    I tried a variety of different combos of the code from http://uk2.php.net/manual/en/function.date.php but can't get it to read the current date and keep the same format. Any other suggestions?

  7. sagdude2002
    Member
    Posted 4 years ago #

    I figured it out. For each section (i.e. the month, day and year) you replace 'the_time' with the 'date' and put the word 'echo' in front of the word 'date'. Here is how the final code looks:

    <?php get_header();?>
    <div id="main">
    <div id="content">
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <p class="date">
    <span class="month">
    <?php echo date('M') ?>
    </span>
    <span class="day">
    <?php echo date('d') ?>
    </span>
    <span class="year">
    <?php echo date('Y') ?>
    </span>
    </p>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.