• I am using the main blog part of WordPress as the main homepage for my company site. A short welcome message is delivered by using a sticky post. Here is what it looks like at the moment: http://ampsoundsystems.com/site/

    As you can see, the little calendar date shows a fixed date – the date that sticky was published. In a few months, that will start to look very off! So I want just that post to always have todays date as its published date. Any way to do this?

    On a side note, what do you think of having that page as the homepage? I used to have the blog burried in a “News” page, but recently decided to move it to the homepage. Do you think it is too distracting or is the dynamic content a good thing?

Viewing 3 replies - 1 through 3 (of 3 total)
  • <?php
    echo date('Ymd');
    ?>

    But see Formatting_Date_and_Time for formats

    Thread Starter AMPSound

    (@ampsound)

    Ok, but how do I only use that time in the sticky posts?

    My index.php looks like this:

    <?php get_header(); ?>
    <?php
    	$options = get_option('patagonia_options');
    ?>
    <div id="content">
    <div id="content-inner">
    <div id="main">
    <?php if (have_posts()) : ?>
    	<?php while (have_posts()) : the_post(); ?>
    	<div class="sticky-box">
    	                <?php if(is_sticky()) : ?>
    	    				<div class="sticky-post"><img src="<?php bloginfo('template_url'); ?>/images/sticky.png" alt="sticky" width="70" height="70"/></div>
    	    			<?php endif; ?>
    	</div>
    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
      <div class="date"><div class="month"><?php the_time('M') ?></div><div class="nr"><?php the_time('j') ?></div><div class="year"><?php the_time('Y') ?></div></div>
    	<div class="entry">
    		<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    		<div class="postmetadata3">
    		<img style="vertical-align:-5px;" alt="categories" src="<?php bloginfo('template_directory'); ?>/images/category.gif" height="16" width="16" /> <?php the_category(', ') ?>
    	    </div>
    		<?php comments_template(); ?>
    	</div>
    				<?php the_content('Continue Reading &raquo;'); ?>
    				<div class="fixed"></div>
    	<div class="postmetadata2">
    		 <?php if (get_the_tags()){?> Tags: <?php the_tags('') ?>  <?php } ?> | <img style="vertical-align:-5px;" alt="comments" src="<?php bloginfo('template_directory'); ?>/images/comment.gif" height="15" width="20" />
    		 <?php comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')); ?> <?php edit_post_link('Edit',' ',''); ?>
    	</div>
    </div>
    	<?php endwhile; ?>
    	 <div id="navigation">
    			<div class="fleft"><?php next_posts_link('&laquo; Older') ?></div>
    			<div class="fright"> <?php previous_posts_link('Newer &raquo;') ?></div>
    	 </div>
    	<?php else : ?>
    	 <div class="post">
    	   <div class="entry">
    		 <h2>Not Found</h2>
    		 <p>Sorry, you are looking for something that isn't here.</p>
           </div>
    </div>
    </div>
    </div>
    <?php endif; ?>
    </div>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    Can you show me where I would put that code you gave me in?

    Didn’t test this but it would be something like this:

    Change this line:

    <div class="date"><div class="month"><?php the_time('M') ?></div><div class="nr"><?php the_time('j') ?></div><div class="year"><?php the_time('Y') ?></div></div>

    to this:

    <?php
    if ( is_sticky() ) {
    ?>
      <div class="date"><div class="month"><?php echo date('M'); ?></div><div class="nr"><?php echo date('j'); ?></div><div class="year"><?php echo date('Y'); ?></div></div>
    <?php
    } else {
    ?>
      <div class="date"><div class="month"><?php the_time('M') ?></div><div class="nr"><?php the_time('j') ?></div><div class="year"><?php the_time('Y') ?></div></div>
    <?php
    }
    ?>

    Related:
    Formatting_Date_and_Time
    Conditional_Tags#A_Sticky_Post
    Template_Tags/the_time
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Always keep post date as “Today”’ is closed to new replies.