Created
June 8, 2018 04:25
-
-
Save IamSohaggazi/75a0366735d0c6f601995ec427a26548 to your computer and use it in GitHub Desktop.
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 portfolios_shortcode($atts){ | |
extract( shortcode_atts( array( | |
'expand' => '', | |
), $atts) ); | |
global $paged; | |
$posts_per_page = 6; | |
$settings = array( | |
'showposts' => $posts_per_page, | |
'post_type' => 'portfolio', | |
'orderby' => 'menu_order', | |
'order' => 'ASC', | |
'paged' => $paged | |
); | |
$post_query = new WP_Query( $settings ); | |
$total_found_posts = $post_query->found_posts; | |
$total_page = ceil($total_found_posts / $posts_per_page); | |
$list = '<div class="portfolio-item-list">'; | |
while($post_query->have_posts()) : $post_query->the_post(); | |
$list .= ' | |
<div class="single-portfolio-item"> | |
</div> | |
'; | |
endwhile; | |
$list.= '</div>'; | |
if(function_exists('wp_pagenavi')) { | |
$list .='<div class="page-navigation">'.wp_pagenavi(array('query' => $post_query, 'echo' => false)).'</div>'; | |
} else { | |
$list.=' | |
<span class="next-posts-links">'.get_next_posts_link('Next page', $total_page).'</span> | |
<span class="prev-posts-links">'.get_previous_posts_link('Previous page').'</span> | |
'; | |
} | |
return $list; | |
} | |
add_shortcode('portfolios', 'portfolios_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment