Last active
May 27, 2018 17:49
-
-
Save dividezigns/a147f1f99befb41e15d32946f7f34bcf to your computer and use it in GitHub Desktop.
This code will make a shortcode that you can place any where on a page to render a custom post type archive. Place this code in your functions.php in your child theme's directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_featured_project(){ | |
ob_start(); | |
$paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged'); | |
$featured_project = new WP_Query(array( | |
'post_type' => 'custom_post_type', | |
'post_status' => 'publish', | |
'posts_per_page' => 2, | |
'order' => 'DESC', | |
'paged' => $paged, | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'taxonomy_slug_name', | |
'field' => 'slug', | |
'terms' => array('term_name'), | |
), | |
), | |
)); | |
if($featured_project -> have_posts()): | |
while($featured_project -> have_posts()): $featured_project -> the_post();?> | |
<div class="et_pb_column et_pb_column_1_3"> | |
<div class="et_pb_module et_pb_text et_pb_text_align_center"> | |
<div class="et_pb_text_inner"> | |
<a href="<?php the_permalink(); ?>"> | |
<?php echo the_post_thumbnail('medium');?> | |
<h2><?php echo the_title();?></h2> | |
<a href="<?php the_permalink(); ?>">View Project</a> | |
</a> | |
</div> | |
</div> | |
</div> | |
<?php endwhile; | |
endif; | |
return ob_get_clean(); | |
} | |
add_shortcode('featured-project', 'get_featured_project'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment