Plugin Directory

Changeset 2793299


Ignore:
Timestamp:
10/03/2022 08:22:33 AM (4 years ago)
Author:
rounakkumar
Message:

New Version Added.
New Features added.
Show posts by Multiple category.
Pagination for category attribute.
Show all posts by exclude category.

Location:
posts-by-shortcode
Files:
26 added
4 edited

Legend:

Unmodified
Added
Removed
  • posts-by-shortcode/trunk/posts-by-shortcode-rk.php

    r2754553 r2793299  
    6565    <p><code>[show_posts_pbs_rk layout="1" hide_category="yes"]</code> <br><i style="background: #f4f4d4;">Hide category label from posts.</i></p>
    6666    <p><code>[show_posts_pbs_rk layout="1" desc_length="200"]</code> <br><i style="background: #f4f4d4;">Set number of characters to show in post description.</i></p>
    67     <p><code>[show_posts_pbs_rk layout="1" category_id="1"]</code> <br><i style="background: #f4f4d4;">Show posts by category id(Use single id with single shortcode).</i></p>
    68     <p><code>[show_posts_pbs_rk layout="1" pagination="yes"]</code> <br><i style="background: #f4f4d4;">Show posts pagination(Pagination will not work if shortcode has category_id attribute).</i></p>
     67    <p><code>[show_posts_pbs_rk layout="1" category_id="1"]</code> or multiple category ids <code>[show_posts_pbs_rk layout="1" category_id="1,2,3"]</code><br><i style="background: #f4f4d4;">Show posts by category id.</i></p>
     68    <p><code>[show_posts_pbs_rk layout="1" exclude_cat="1"]</code> or multiple category ids <code>[show_posts_pbs_rk layout="1" exclude_cat="1,2,3"]</code><br><i style="background: #f4f4d4;">Show All posts excluded by category id.</i></p>
     69    <p><code>[show_posts_pbs_rk layout="1" pagination="yes"]</code> <br><i style="background: #f4f4d4;">Show posts pagination.</i></p>
    6970    <p><code>[show_posts_pbs_rk layout="1" read_more_lebel="Continue Reading >"]</code> <br><i style="background: #f4f4d4;">Set Custom Label for Read More Button.</i></p>
    7071    <p><code>[show_posts_pbs_rk layout="1" show_author="yes"]</code> <br><i style="background: #f4f4d4;">Show author name in posts.</i></p>
     
    107108    /* Show Single Post by ID */
    108109    if($atts['post_id']){$show_post_by_id = $atts['post_id'];}else{$show_post_by_id = '0';}
     110   
     111    /* Exclude category IDs from posts */
     112    if($atts['exclude_cat']){$exclude_cat = $atts['exclude_cat'];}else{$exclude_cat = '0';}
    109113   
    110114    /* Get Posts Arguments */
     
    122126            'post_status'    => 'publish',
    123127            'order'          => 'DESC',
     128            'category__not_in'   => array($exclude_cat),
    124129            'posts_per_page' => $post_per_page,
    125130            'offset'         => $offset
     
    130135    $result = new WP_Query( $args );
    131136   
    132     /* Calculate Pagination */
    133     if($pagination_attr == 'yes'){
    134         $total_posts = wp_count_posts()->publish;
    135         $total_page = ceil($total_posts/$post_per_page);
    136     }
    137    
    138137    $content = '';
    139138   
     
    161160    /* Show Pagination */
    162161    if($pagination_attr == 'yes'){
    163         if($total_posts > $post_per_page && $category_id == 0){
     162       
     163        /* Calculate Pagination */
     164        if($category_id != 0 || $exclude_cat != 0){
     165            $args = array(
     166              'cat' => $category_id,
     167              'post_type' => 'post',
     168              'category__not_in'     => array($exclude_cat),
     169              'post_status'  => 'publish'
     170            );
     171           
     172            $the_query = new WP_Query( $args );
     173            $total_posts = $the_query->found_posts;
     174        }else{     
     175            $total_posts = wp_count_posts()->publish;
     176        }
     177       
     178        $total_page = ceil($total_posts/$post_per_page);
     179           
     180        if($total_posts > $post_per_page){
    164181            $content .= '<div class="pbs_rk_pagination">';
    165182            $content .= '<ul>';
  • posts-by-shortcode/trunk/readme.txt

    r2754559 r2793299  
    33Tags: Posts, Posts Shortcode, Show Posts, Show posts by shortcode, posts by shortcode
    44Donate link: https://learn-wordpress-by-rk.blogspot.com/2022/04/donate-me.html
    5 Requires at least: 3.0
     5Requires at least: 5.0
    66Tested up to: 6.0
    77Requires PHP: 7.0
    8 Stable tag: 1.1
     8Stable tag: 1.2
    99License: GPL2 or Later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    4545`[show_posts_pbs_rk layout="1" category_id="1"]`
    4646
     47Show Posts by Multiple Category
     48
     49`[show_posts_pbs_rk layout="1" category_id="1,2,3"]`
     50
     51Show all posts excluded by category
     52
     53`[show_posts_pbs_rk layout="1" exclude_cat="1"]`
     54
     55Show all posts excluded by multiple category
     56
     57`[show_posts_pbs_rk layout="1" exclude_cat="1,2,3"]`
     58
    4759Show pagination
    4860
     
    6880
    6981`[show_posts_pbs_rk layout="1" post_id="52"]`
     82
     83[youtube https://www.youtube.com/watch?v=l4kg9BCq4PQ&t=369s]
    7084
    7185
     
    114128== Changelog ==
    115129
    116 1.0
    117 Initial version
     1301.2
     131New version added
    118132
    119133== Upgrade Notice ==
Note: See TracChangeset for help on using the changeset viewer.