Sorry, I am pretty new to WordPress coding and learning it from scratch. Please pardon me for my lack of experience.
I have a custom post type called ‘Products’ and want to display only them as a date based archive in homepage. But, I Don’t want to display the post titles or any other content from the posts except the featured from first three or four posts in that date. Something like this:
I am trying the following code, but it returns the posts as the normal loop.
<?php $query = new WP_Query( array('post_type' => 'products', 'orderby' => 'date') ); ?>
<?php if ( $query->have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
$archive_year = get_the_time('Y');
$archive_month = get_the_time('m');
$archive_day = get_the_time('d');
?>
<div class="idpostdate">
<a href="<?php echo get_day_link( $archive_year, $archive_month, $archive_day); ?>"><?php the_date( 'F j, Y', '', '<span class="datetext">: Click Here To View Products</span>', true );?></a>
</div>
<div class="thumbnail">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail('homet'); } ?>
</article>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'no-results', 'index' ); ?>
<?php endif; ?>
Any guidance?
Functions like
the_ID()
andthe_post_thumbnail()
run on the main query. If you want to use their equivalents in your code, you’ll need to prepend$query->
to them.Untested, but I think it’ll do what you want it to: