Last active
May 5, 2018 02:47
-
-
Save uandidezign/136eee83cbfb1af781b9da03a0f99e8c to your computer and use it in GitHub Desktop.
This code snippet will create an CTP loop that can be inserted in any page via a short code.
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 custom_short_code(){ | |
ob_start(); | |
$paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged'); | |
$call_cpt = new WP_Query(array( | |
'post_type' => 'custom_post_type', | |
'post_status' => 'publish', | |
'posts_per_page' => 8, | |
'order' => 'DESC', | |
'paged' => $paged | |
)); | |
?> | |
<div class="et_pb_row"> | |
<?php | |
if($call_cpt ->have_posts()) { | |
$i = 0; | |
while($call_cpt ->have_posts()): $call_cpt ->the_post(); | |
?> | |
<div class="et_pb_column"> | |
<div class="et_pb_text et_pb_module"> | |
<div class="et_pb_text_inner"> | |
<p>Custom Post Type Data</p> | |
</div> | |
</div> | |
</div> | |
<?php | |
$i++; | |
if($i % 2 == 0) echo '</div><div class="et_pb_row" >'; | |
endwhile; | |
} | |
return ob_get_clean(); | |
} | |
add_shortcode('name_of_shortcode', 'custom_short_code'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment