I have found this code snippet but I think it disaplays all posts for the 24th, e.g. Jan 24th, Feb 24th, etc.
<?php
$day = date('j');
query_posts('day='.$day);
if (have_posts()) :
while (have_posts()) : the_post();
?>
<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="view: <?php the_title(); ?>"><?php the_title(); ?></a></h3>
<div class="storycontent"><?php the_content(); ?></div>
<?php endwhile; ?> <?php endif; ?>
Is it possible to amend this slightly please?
Does anyone know of a plugin please? Or is this done at theme stage?
Thanks
Rich
]]>$args = array(
'date_query' => array(
array(
'day' => date( 'j' ),
'month' => date( 'n' ),
),
),
);
query_posts( $args );
You probably don’t care, but for anyone else reading who might, the “date_query” argument is preferred over the older individual date arguments. It allows extremely complex date logic to be applied to the query. Multiple argument arrays can be added to the one overall date_query array. Inner arrays can be nested for even more complex logic.
The use of query_posts() is now frowned upon, it can be very inefficient. But without knowing how you want this query applied in your site, I can’t suggest a better solution. The preferred approach is to alter the default query through the “pre_get_posts” action, but to do so we need to know when to apply the change and when not to.
]]>Thanks for the very helpful reply. I will have to research some of the information you have given me.
The above is the site I am applying it to. Does this help to answer your query in terms of when to apply the change please?
Thanks
Rich
]]>If we’re going to do things the “right” way, first of all, you shouldn’t be directly altering theme templates (unless you made your own theme). Your changes will be lost when the theme is updated. To customize a theme, create a child theme. Because we are going to alter the posts query via the pre_get_posts action, no template alterations are required, so this could also be accomplished via a custom plugin instead of child theme.
To alter the home page query, add the following to functions.php of your child theme, or the main code page of a custom plugin:
add_action('pre_get_posts', 'cgy_same_day');
function cgy_same_day( $query ) {
if ( $query->is_home() && $query->is_main_query()) {
$query->set('date_query', array(
array(
'day' => date( 'j' ),
'month' => date( 'n' ),
),
));
}
return;
}
No need to alter any theme templates this way ??
]]>Thanks for all the help.
]]>If anyone wants to look…. I am running it here:
https://gucu.org.uk/everydaywithjesus/
Rich
]]>