HomeHow To

How to display today’s post on a page or in a static front page

How to display today’s post on a page or in a static front page
Like Tweet Pin it Share Share Email

To displays Today’s post on a page , all you have to do is change the default loop in your theme or page with the following codes. The other way is to create a page template and assign it to your page.

1. Create a template page postoftheday.php

<?php
/**
 * Template Name: post of the day
 * The template for displaying the page with a slug of `post of the day`.
 */
?>

<?php


// replace the loop with the code below 

?>

2. Login to your wordpress dashboard and create a page – Todays post or a name of your choice.

3. Use/Assign the page template created in step one.

CODE

you can play with the following ..

'author' => '2', 

– to display from a particular author change the author id or remove the whole line if its not required.

'category_name' => 'category-name-here',

– to display from a particular category change the category name or remove the whole line if its not required.

  
<?php $today = getdate();
$args = array(
'author' => '2',
'category_name' => 'category-name-here',
'posts_per_page' => -1,
'year' => $today["year"],
'orderby' => 'date',
'order'   => 'DESC',
'monthnum' => $today["mon"],
'day' => $today["day"]
);
query_posts( $args );

//existing loop starts here: ?>
  
  <?php

if (have_posts()) :
   while (have_posts()) : the_post();
?>
 <div class="dpost"><h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
 
</div>
 
<?php endwhile; else: ?>
    <?php _e( 'Sorry, articles not yet uploaded .', 'textdomain' ); ?>
<?php endif; ?>
  
 
  

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

six − 3 =