WordPress.org

Plugin Directory

Changeset 446403


Ignore:
Timestamp:
10/02/11 13:59:29 (3 years ago)
Author:
Kawauso
Message:

committing 0.1.1 to trunk

Location:
set-front-page-post-count/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • set-front-page-post-count/trunk/readme.txt

    r351945 r446403  
    11=== Set Front Page Post Count === 
    2 Contributors: Kawauso 
     2Contributors: kawauso 
     3Donate link: http://adamharley.co.uk/buy-me-a-coffee/ 
    34Tags: front page, posts, pre_get_posts 
    45Requires at least: 3.0 
    5 Tested up to: 3.1 
    6 Stable tag: 0.1 
     6Tested up to: 3.3 
     7Stable tag: 0.1.1 
    78 
    89Allows the front page to have a different number of posts than other pages. 
     
    1213Adds a setting under Settings -> Reading to allow the front page post count to be controlled independently of the main post count and adjusts paging to accomodate for this. 
    1314 
    14 Uses the `pre_get_posts` hook and checks for the `$wp_query` query being passed, so may have issues with additional loops and `query_posts()`. 
     15Uses the `pre_get_posts` hook and checks for the `$wp_the_query` query being passed, so won't work with `query_posts()`. 
    1516 
    1617== Installation == 
     
    18191. Upload `set-front-page-post-count.php` to the `/wp-content/plugins/` directory 
    19201. Activate the plugin through the 'Plugins' menu in WordPress 
     211. Set the front page post count in the 'Reading' section of the 'Settings' menu 
    2022 
    2123== Frequently Asked Questions == 
     
    2931== Changelog == 
    3032 
     33= 0.1.1 = 
     34* Adds missing default for when no front page count is set 
     35* Avoids applying query filter in admin 
     36 
    3137= 0.1 = 
    3238* First public release 
     39 
     40== Upgrade Notice == 
     41 
     42= 0.1.1 = 
     43Missing default value added. Query filter no longer applied in admin. 
  • set-front-page-post-count/trunk/set-front-page-post-count.php

    r351945 r446403  
    33Plugin Name: Set Front Page Post Count 
    44Description: Allows the front page to have a different number of posts than other pages. 
    5 Author: Kawauso 
    6 Version: 0.1 
     5Author: Adam Harley 
     6Version: 0.1.1 
     7Author URI: http://adamharley.co.uk 
     8Plugin URI: http://adamharley.co.uk/wordpress-plugins/set-front-page-post-count/ 
    79*/ 
    810 
     
    1618?> 
    1719 
    18 <input name="front_page_post_count" type="text" id="front_page_post_count" value="<?php echo esc_attr( get_option( 'front_page_post_count', get_option('posts_per_page') ) ) ?>" class="small-text" /> <?php _e( 'posts', 'sfppc' ) ?> 
     20<input name="front_page_post_count" type="text" id="front_page_post_count" value="<?php echo esc_attr( get_option( 'front_page_post_count', get_option( 'posts_per_page' ) ) ) ?>" class="small-text" /> <?php _e( 'posts', 'sfppc' ) ?> 
    1921 
    2022<?php 
     
    2325 
    2426function sfppc_posts_settings_sanitize( $value ) { 
    25     return is_numeric( $value ) ? $value : get_option( 'front_page_post_count', get_option('posts_per_page') ); 
     27    return is_numeric( $value ) ? $value : get_option( 'front_page_post_count', get_option( 'posts_per_page' ) ); 
    2628} 
    2729 
     
    3133        return; 
    3234 
    33     if ( $query->is_paged ) { 
    34         $posts_per_page = $query->get('posts_per_page') ? $query->get('posts_per_page') : get_option('posts_per_page'); 
    35         $offset = ($query->get('paged') - 2) * $posts_per_page + get_option( 'front_page_post_count', $posts_per_page ); 
    36         $query->set( 'offset', $offset ); 
    37     } 
     35    $posts_per_page = $query->get('posts_per_page') ? $query->get('posts_per_page') : get_option('posts_per_page'); 
     36 
     37    if ( $query->is_paged )  
     38        $query->set( 'offset', ($query->get('paged') - 2) * $posts_per_page + get_option( 'front_page_post_count', $posts_per_page ) ); 
    3839    else 
    3940        $query->set( 'posts_per_page', get_option( 'front_page_post_count', $posts_per_page ) ); 
    4041} 
    4142 
    42  
    43 add_action( 'admin_init', 'sfppc_posts_settings_add' ); 
    44 add_action( 'pre_get_posts', 'sfppc_posts_filter' ); 
     43if ( is_admin() ) 
     44    add_action( 'admin_init', 'sfppc_posts_settings_add' ); 
     45else 
     46    add_action( 'pre_get_posts', 'sfppc_posts_filter' ); 
Note: See TracChangeset for help on using the changeset viewer.