The first thing you need to do is to write some HTML for category and publish date select box. This can be added to a custom template or your home page index.php file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<div class="filter-wrap"> <div class="category"> <div class="field-title">Category</div> <?php $get_categories = get_categories(array('hide_empty' => 0)); ?> <select class="js-category"> <option value="all">All</option> <?php if ( $get_categories ) : foreach ( $get_categories as $cat ) : ?> <option value="<?php echo $cat->term_id; ?>"> <?php echo $cat->name; ?> </option> <?php endforeach; endif; ?> </select> </div> <div class="date"> <div class="field-title">Sort by</div> <select class="js-date"> <option value="new">Newest</option> <option value="old">Oldest</option> </select> </div> </div> |
Now, when we have HTML ready, we also need to show some latest blog posts.
1 2 3 4 5 6 7 8 9 10 11 |
<div class="filtered-posts"> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); get_template_part( 'template-parts/content-post' ); endwhile; endif; ?> </div> |
Create a file called content-post.php […]