3, ), $atts, 'most_read_posts'); ob_start(); $popular = new WP_Query(array( 'posts_per_page' => intval($atts['posts']), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Needed for ordering by view count. 'meta_key' => 'post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'post_status' => 'publish', )); if ($popular->have_posts()) : echo '
'; while ($popular->have_posts()) : $popular->the_post(); $post_id = get_the_ID(); $title = get_the_title(); $author = get_the_author(); $date = get_the_date(); $cats = get_the_category(); $catname = $cats ? esc_html($cats[0]->name) : ''; $catlink = $cats ? esc_url(get_category_link($cats[0]->term_id)) : '#'; $img = get_the_post_thumbnail_url($post_id, 'large'); $permalink = esc_url(get_permalink($post_id)); ?>
•
'; wp_reset_postdata(); else: echo '

' . esc_html__('No popular posts found.', 'aj-category-posts') . '

'; endif; return ob_get_clean(); } add_shortcode('most_read_posts', 'ajcps_most_read_posts_shortcode'); /* |-------------------------------------------------------------------------- | Shortcode: Latest Post Overlay |-------------------------------------------------------------------------- */ function ajcps_latest_post_overlay_shortcode($atts) { ob_start(); echo '
'; $query = new WP_Query(array( 'posts_per_page' => 1, 'post_status' => 'publish' )); if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); $post_id = get_the_ID(); $title = get_the_title(); $author = get_the_author(); $date = get_the_date(); $cats = get_the_category(); $catname = $cats ? esc_html($cats[0]->name) : ''; $catlink = $cats ? esc_url(get_category_link($cats[0]->term_id)) : '#'; $img = get_the_post_thumbnail_url($post_id, 'large'); $postlink = esc_url(get_permalink($post_id)); ?>

•
'; return ob_get_clean(); } add_shortcode('latest_post_overlay', 'ajcps_latest_post_overlay_shortcode'); /* |-------------------------------------------------------------------------- | Shortcode: Latest Posts Grid (with pagination) |-------------------------------------------------------------------------- */ function ajcps_latest_posts_grid_shortcode($atts) { $atts = shortcode_atts( array( 'posts' => get_option('ajcps_posts_per_page', 12), ), $atts, 'latest_posts_grid' ); // Use native WordPress pagination (paged for archives, page for paginated pages) $paged = max(1, get_query_var('paged') ? get_query_var('paged') : (get_query_var('page') ? get_query_var('page') : 1)); // Shortcode posts attribute only applies to page 1; pages 2+ use the admin setting $posts_per_page = $paged > 1 ? get_option('ajcps_posts_per_page', 12) : intval($atts['posts']); ob_start(); $paged_mode = $paged > 1 ? ' ajcps-paged-mode' : ''; echo '
'; $query = new WP_Query(array( 'posts_per_page' => $posts_per_page, 'paged' => $paged, 'post_status' => 'publish' )); if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); $post_id = get_the_ID(); $title = get_the_title(); $author = get_the_author(); $date = get_the_date(); $cats = get_the_category(); $catname = $cats ? esc_html($cats[0]->name) : ''; $catlink = $cats ? esc_url(get_category_link($cats[0]->term_id)) : '#'; $img = get_the_post_thumbnail_url($post_id, 'large'); $postlink = esc_url(get_permalink($post_id)); ?>

•
No posts found.

'; endif; echo '
'; // Native WordPress pagination if ($query->max_num_pages > 1) { $big = 999999999; $paginate = paginate_links(array( 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), 'format' => '?paged=%#%', 'current' => $paged, 'total' => $query->max_num_pages, 'prev_text' => 'Prev', 'next_text' => 'Next', 'type' => 'list', )); if ($paginate) { echo '
' . wp_kses_post( $paginate ) . '
'; } } // Paged mode: hide non-post page elements on pages 2+ if ($paged > 1) { echo ''; } return ob_get_clean(); } add_shortcode('latest_posts_grid', 'ajcps_latest_posts_grid_shortcode'); /* |-------------------------------------------------------------------------- | Shortcode: Category Posts (ajcapos) |-------------------------------------------------------------------------- */ function ajcapos_showcase_shortcode_handler($atts) { $atts = shortcode_atts(array( 'id' => '' ), $atts); $post_id = intval($atts['id']); if (!$post_id) return ''; $category = get_post_meta($post_id, '_ajcps_category', true); $count = get_post_meta($post_id, '_ajcps_count', true); $columns = get_post_meta($post_id, '_ajcps_columns', true); $columns = !empty($columns) ? intval($columns) : 3; $excerpt_length = get_post_meta($post_id, '_ajcps_excerpt_length', true); $excerpt_length = !empty($excerpt_length) ? intval($excerpt_length) : 15; if (empty($category)) return ''; $args = array( 'posts_per_page' => $count ? intval($count) : 6, 'post_status' => 'publish', ); if (is_numeric($category)) { $args['cat'] = intval($category); } else { $args['category_name'] = sanitize_title($category); } $latest_posts = new WP_Query($args); ob_start(); ?>
have_posts()) : ?> have_posts()) : $latest_posts->the_post(); ?>
'ajcps-img-fluid']); ?>

No posts found for this category.

term_id); ?>