WordPress posts numeric pagination:
-------------------------------------------------------------------------------------------------------------------
function ashique_all_trending_topics_blog_posts($atts, $content = null) {
global $post;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$blogs_arg2 = array(
'posts_per_page' => -1,
'post_status' => 'publish',
'suppress_filters' => true
);
$blogs_array2 = get_posts($blogs_arg2);
$args = array(
'posts_per_page' => 12,
'orderby' => 'date',
'order' => 'DESC',
'post_status' => 'publish',
'suppress_filters' => true,
'paged' => $paged
);
$blogs_array = get_posts($args);
for ($i = 0; $i < count($blogs_array); $i++) {
//echo "<pre>";
//print_r($blogs_array[$i]);
}
$output = '';
$output .= '<div id="rp_trending_topics">';
// $posts = get_posts($args);
foreach( $blogs_array as $post ) {
setup_postdata($post);
if ( has_post_thumbnail() ) {
$image_file_url = get_the_post_thumbnail_url();
$upload_dir = wp_upload_dir();
$file_name = explode('/', $image_file_url);
$file_name = end($file_name);
$data = file_get_contents($image_file_url);
$new_image = $upload_dir['basedir'] .'/'. 'most-viewd-' . $file_name;
file_put_contents($new_image, $data);
$image_size = '300x200';
$img_temp = explode("x", $image_size);
$img_width = $img_temp[0];
$img_height = $img_temp[1];
$image = wp_get_image_editor( $new_image );
if ( ! is_wp_error( $image ) ) {
$image->resize( $img_width, $img_height, true );
$image->save( $new_image );
}
$output .= '<div class="flex_column av_one_fourth"><div class="trending-post-container">';
$image_tag_html = '<img class="wprp-post-image" src="' . $upload_dir['baseurl'] . '/' . 'most-viewd-' . $file_name . '" alt="" />';
}
else {
$image_tag_html = '<img class="wprp-post-image" src="' . get_stylesheet_directory_uri() . '/images/default-image.jpg" />';
}
$num_words='12';
$more='...';
$excerpt = get_the_excerpt();
$excerpt = wp_trim_words( $excerpt, $num_words , $more );
$output .= '<article class="trending-image-with-content">
<a class="single-image" href="'.get_the_permalink().'" title="">'.$image_tag_html.'</a>
<div class="slide-content"><header class="entry-content-header">
<h3 class="slide-entry-title entry-title" itemprop="headline">
<a href='.get_the_permalink().' role="link" title="">'.get_the_title().'</a></h3></header>
</div></article>';
$output .= '<div class="rp_excerpt">'.$excerpt.'</div>';
$output .= '<div class="rp_date_and_read_more"><span class="rp_date">'.get_the_date().'</span><a class="rp_read_more" href="'.get_the_permalink().'">Read More</a></div>';
$output .= '</div></div>';
}
$output .= '</div>';
$big = 999999999; // need an unlikely integer
$count = count($blogs_array2);
$offset = 12;
$max = $count / $offset;
if ( is_float($max) ) {
$max = (int) $max + 1;
}
$mypagei = paginate_links(
array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $max,
'prev_text' => '«',
'next_text' => '»'
)
);
if ( $mypagei != '' ) {
$output .= '<div class="pager">'.$mypagei.'</div>';
}
wp_reset_postdata();
return $output;
}
add_shortcode('ashique_all_trending_topics_blog_post', 'ashique_all_trending_topics_blog_posts');
/************************************* END ***********************************/
-------------------------------------------------------------------------------------------------------------------
function ashique_all_trending_topics_blog_posts($atts, $content = null) {
global $post;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$blogs_arg2 = array(
'posts_per_page' => -1,
'post_status' => 'publish',
'suppress_filters' => true
);
$blogs_array2 = get_posts($blogs_arg2);
$args = array(
'posts_per_page' => 12,
'orderby' => 'date',
'order' => 'DESC',
'post_status' => 'publish',
'suppress_filters' => true,
'paged' => $paged
);
$blogs_array = get_posts($args);
for ($i = 0; $i < count($blogs_array); $i++) {
//echo "<pre>";
//print_r($blogs_array[$i]);
}
$output = '';
$output .= '<div id="rp_trending_topics">';
// $posts = get_posts($args);
foreach( $blogs_array as $post ) {
setup_postdata($post);
if ( has_post_thumbnail() ) {
$image_file_url = get_the_post_thumbnail_url();
$upload_dir = wp_upload_dir();
$file_name = explode('/', $image_file_url);
$file_name = end($file_name);
$data = file_get_contents($image_file_url);
$new_image = $upload_dir['basedir'] .'/'. 'most-viewd-' . $file_name;
file_put_contents($new_image, $data);
$image_size = '300x200';
$img_temp = explode("x", $image_size);
$img_width = $img_temp[0];
$img_height = $img_temp[1];
$image = wp_get_image_editor( $new_image );
if ( ! is_wp_error( $image ) ) {
$image->resize( $img_width, $img_height, true );
$image->save( $new_image );
}
$output .= '<div class="flex_column av_one_fourth"><div class="trending-post-container">';
$image_tag_html = '<img class="wprp-post-image" src="' . $upload_dir['baseurl'] . '/' . 'most-viewd-' . $file_name . '" alt="" />';
}
else {
$image_tag_html = '<img class="wprp-post-image" src="' . get_stylesheet_directory_uri() . '/images/default-image.jpg" />';
}
$num_words='12';
$more='...';
$excerpt = get_the_excerpt();
$excerpt = wp_trim_words( $excerpt, $num_words , $more );
$output .= '<article class="trending-image-with-content">
<a class="single-image" href="'.get_the_permalink().'" title="">'.$image_tag_html.'</a>
<div class="slide-content"><header class="entry-content-header">
<h3 class="slide-entry-title entry-title" itemprop="headline">
<a href='.get_the_permalink().' role="link" title="">'.get_the_title().'</a></h3></header>
</div></article>';
$output .= '<div class="rp_excerpt">'.$excerpt.'</div>';
$output .= '<div class="rp_date_and_read_more"><span class="rp_date">'.get_the_date().'</span><a class="rp_read_more" href="'.get_the_permalink().'">Read More</a></div>';
$output .= '</div></div>';
}
$output .= '</div>';
$big = 999999999; // need an unlikely integer
$count = count($blogs_array2);
$offset = 12;
$max = $count / $offset;
if ( is_float($max) ) {
$max = (int) $max + 1;
}
$mypagei = paginate_links(
array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $max,
'prev_text' => '«',
'next_text' => '»'
)
);
if ( $mypagei != '' ) {
$output .= '<div class="pager">'.$mypagei.'</div>';
}
wp_reset_postdata();
return $output;
}
add_shortcode('ashique_all_trending_topics_blog_post', 'ashique_all_trending_topics_blog_posts');
/************************************* END ***********************************/