Changeset 1754497
- Timestamp:
- 10/28/2017 06:37:24 PM (8 years ago)
- Location:
- infinite-scroll-generatepress
- Files:
-
- 3 added
- 1 deleted
- 4 edited
-
assets/screenshot-1.png (added)
-
trunk/admin (added)
-
trunk/admin/settings.php (added)
-
trunk/css/style.css (modified) (1 diff)
-
trunk/gp_infinite_scroll.php (modified) (8 diffs)
-
trunk/images (deleted)
-
trunk/js/ajax-loader.js (modified) (7 diffs)
-
trunk/readme.txt (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
infinite-scroll-generatepress/trunk/css/style.css
r1752187 r1754497 1 1 #matts_inf_scroll_loading { 2 background-image: url(' ../images/loading.gif');3 background-size: 40px 40px;2 background-image: url('/wp-includes/images/spinner-2x.gif'); 3 background-size: 30px 30px; 4 4 background-position: center; 5 5 background-repeat: no-repeat; -
infinite-scroll-generatepress/trunk/gp_infinite_scroll.php
r1752187 r1754497 4 4 * Plugin URI: https://northwoodsdigital.com/ 5 5 * Description: A very lightweight infinite scroll plugin for your blog running the GeneratePress Theme by Tom Usborne. Just install and activate this plugin to enable infinite scroll on your blog. 6 * Version: 1.0. 16 * Version: 1.0.2 7 7 * Author: Mathew Moore 8 8 * Author URI: https://profiles.wordpress.org/mathewemoore … … 28 28 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly 29 29 30 if ( !class_exists( ' Matts_Infinite_Scroll_Plugin' ) ) {31 class Matts_Infinite_Scroll_Plugin30 if ( !class_exists( 'Infinite_Scroll_GeneratePress' ) ) { 31 class Infinite_Scroll_GeneratePress 32 32 { 33 33 // Setup some global variables to use throughout this plugin 34 private $post_type = 'post'; 35 private $posts_per_page = '2'; 34 private $post_types; 35 private $posts_per_page; 36 private $ifsg_options; 36 37 37 38 public function __construct() 38 39 { 40 $this->ifsg_options = get_option( 'ifsg_settings' ); 41 $this->post_types = (!empty($this->ifsg_options['ifsg_text_field_0']) ? $this->ifsg_options['ifsg_text_field_0'] : ''); 42 $this->posts_per_page = $this->ifsg_options['ifsg_text_field_1']; 39 43 // Include( INF_SCROLL_PLUGIN_DIR . 'js/ajax-loader.js'); 40 add_action('wp_enqueue_scripts', array($this,' matt_infinite_scroll'));44 add_action('wp_enqueue_scripts', array($this,'ifsg_wp_enqueue_scripts')); 41 45 // Ajax for Larger Screens 42 46 add_action( 'wp_ajax_nopriv_post_template_load', array($this, 'post_template_load' )); … … 45 49 add_action( 'wp_ajax_nopriv_post_template_load_small', array($this, 'post_template_load_small' )); 46 50 add_action( 'wp_ajax_post_template_load_small', array($this, 'post_template_load_small' )); 51 // Add WordPress Buitin Admin Notices 52 add_action( 'admin_notices', array($this, 'isgp_default_admin_notices' )); 53 add_action('wp_head', array($this, 'isgp_remove_paging_navigation')); 54 47 55 // Setup the Plugin Directory Location 48 define( 'PLUGIN_DIR', plugin_dir_url( __FILE__ ) ); 49 define( 'TEMPLATE_DIR', get_template_directory_uri() ); 50 } 51 public function matt_infinite_scroll() 56 if ( ! defined( 'INF_SCROLL_GP' )) { 57 define( 'INF_SCROLL_GP', plugin_dir_url( __FILE__ ) ); 58 } 59 require_once( dirname(__FILE__) . '/admin/settings.php'); 60 } 61 62 public function isgp_default_admin_notices() 63 { 64 settings_errors(); 65 } 66 67 public function isgp_remove_paging_navigation(){ 68 if (!empty($this->ifsg_options['ifsg_text_field_0']) & !empty($this->ifsg_options['ifsg_text_field_1'])){ 69 echo '<style type="text/css">.paging-navigation {display: none;}</style>'; 70 } 71 } 72 73 public function infinite_scroll_total_posts() 74 { 75 // function to get total number of published posts for the specified post types 76 if (!empty($this->ifsg_options['ifsg_text_field_1'])){ 77 $totalcount = array(); 78 foreach ($this->post_types as $post_type) 79 { 80 $post_count = wp_count_posts($post_type); 81 $totalcount[] = $post_count->publish; 82 } 83 return array_sum($totalcount); 84 } else {return '0';} 85 } 86 87 public function ifsg_wp_enqueue_scripts() 52 88 { 53 89 if ( is_home() ) { // Run this script on the blog page only 54 90 // Load CSS & Javascript Assets 55 wp_register_style('matt_infinite_scroll_css', PLUGIN_DIR . 'css/style.css', '1.0.0', true); 56 wp_enqueue_style('matt_infinite_scroll_css'); 57 58 wp_register_script('matt_infinite_scroll', PLUGIN_DIR . 'js/ajax-loader.js', array('jquery'), '1.0.0', true); 59 wp_enqueue_script('matt_infinite_scroll'); 60 61 $count_posts = wp_count_posts($this->post_type); 62 $published_posts = $count_posts->publish; 63 64 wp_localize_script( 'matt_infinite_scroll', 'matt_inf_scroll', array( 91 wp_register_style('ifsg_plugin_css', INF_SCROLL_GP . 'css/style.css', '1.0.0', true); 92 wp_enqueue_style('ifsg_plugin_css'); 93 94 wp_register_script('ifsg_plugin_scripts', INF_SCROLL_GP . 'js/ajax-loader.js', array('jquery'), '1.0.0', true); 95 wp_enqueue_script('ifsg_plugin_scripts'); 96 97 echo '<input type="hidden" name="inf_scroll_gp_ajax_nonce" id="inf_scroll_gp_ajax_nonce" value="' . wp_create_nonce( 'inf_scroll_gp_ajax_nonce' ) . '" />'; 98 99 wp_localize_script( 'ifsg_plugin_scripts', 'ifsg_ajax_scripts', array( 65 100 'ajax_url' => admin_url( 'admin-ajax.php' ), 66 101 'plugins_url' => plugins_url( '/', __FILE__ ), 67 'total_posts' => $ published_posts,102 'total_posts' => $this->infinite_scroll_total_posts(), 68 103 )); 69 104 } 70 105 } 106 71 107 public function post_template_load(){ // Larger Screens 108 // Verify AJAX nonce or die 109 check_ajax_referer( 'inf_scroll_gp_ajax_nonce', 'security' ); 110 72 111 $offset = esc_html($_POST['offset']); 73 $count_posts = wp_count_posts($this->post_type);112 // $count_posts = wp_count_posts($this->post_type); 74 113 75 114 // WP_Query arguments … … 77 116 78 117 $args = array( 79 'post_type' => array( $this->post_type ),118 'post_type' => $this->post_types, 80 119 'post_status' => array( 'publish' ), 81 120 'order' => 'DESC', … … 99 138 // Restore original Post Data 100 139 wp_reset_postdata(); 101 /* ?>102 <?php103 140 // Custom Content Block 1 104 <div class="inside-article inf_ad_block"> 105 </div> 106 ?> 107 <?php */ 141 142 if ( !empty($this->ifsg_options['ifsg_text_field_2'] ) ) { ?> 143 144 <div class="inside-article inf_ad_block"> 145 <?php echo $this->ifsg_options['ifsg_text_field_2']; ?> 146 </div> 147 148 <?php 149 } 108 150 } 109 151 die(); 110 152 } 111 153 public function post_template_load_small(){ // Small screens 154 // Verify AJAX nonce or die 155 check_ajax_referer( 'inf_scroll_gp_ajax_nonce', 'security' ); 156 112 157 $offset = esc_html($_POST['offset']); 113 $count_posts = wp_count_posts($this->post_type);158 // $count_posts = wp_count_posts($this->post_type); 114 159 115 160 // WP_Query arguments … … 117 162 118 163 $args = array( 119 'post_type' => array( $this->post_type ),164 'post_type' => $this->post_types, 120 165 'post_status' => array( 'publish' ), 121 166 'order' => 'DESC', … … 137 182 } 138 183 } else { 184 return false; 139 185 // no posts found 140 186 } 141 187 // Restore original Post Data 142 188 wp_reset_postdata(); 143 /* ?>144 <?php145 189 // Custom Content Block 1 146 <div class="inside-article inf_ad_block"> 147 </div> 148 ?> 149 <?php */ 190 191 if ( !empty($this->ifsg_options['ifsg_text_field_2'] ) ) { ?> 192 193 <div class="inside-article inf_ad_block"> 194 <?php echo $this->ifsg_options['ifsg_text_field_2']; ?> 195 </div> 196 197 <?php 198 } 150 199 } 151 200 die(); … … 153 202 } 154 203 155 $ Matts_Infinite_Scroll_Plugin = new Matts_Infinite_Scroll_Plugin();204 $Infinite_Scroll_GeneratePress = new Infinite_Scroll_GeneratePress(); 156 205 } -
infinite-scroll-generatepress/trunk/js/ajax-loader.js
r1752187 r1754497 1 var matt_inf_scroll_processing;1 var ifsg_ajax_scripts_processing; 2 2 3 3 jQuery(document).ready(function($) { … … 5 5 $(window).scroll(function() { 6 6 7 if ( matt_inf_scroll_processing)7 if (ifsg_ajax_scripts_processing) 8 8 return false; 9 9 10 if( ($(window).scrollTop() >= ($(document).height() - $(window).height())*0.85) && matt_inf_scroll.total_posts > $('.type-post').size() ) { 11 matt_inf_scroll_processing = true; 12 var last_id = $(".type-post:last").attr("id"); 13 var last_id_small = $(".type-post:last").attr("id"); 10 if( ($(window).scrollTop() >= ($(document).height() - $(window).height())*0.85) && ifsg_ajax_scripts.total_posts > $('article').size() ) { 11 ifsg_ajax_scripts_processing = true; 12 13 var last_id = $('article').attr("id"); 14 var last_id_small = $('article').attr("id"); 14 15 // loadMoreData(last_id); 15 16 if ( $(window).width() > 768) { 16 17 // processing = true; 17 // Add yourjavascript for large screens here18 // javascript for large screens here 18 19 loadMoreData(last_id); 19 20 // loadMoreDataSmall(last_id_small); … … 21 22 else { 22 23 // processing = true; 23 // Add yourjavascript for small screens here24 // javascript for small screens here 24 25 loadMoreDataSmall(last_id_small); 25 26 } … … 30 31 $.ajax( 31 32 { 32 url: matt_inf_scroll.ajax_url,33 url: ifsg_ajax_scripts.ajax_url, 33 34 type : 'post', 34 35 data : { 35 36 action : 'post_template_load', 37 security: $( '#inf_scroll_gp_ajax_nonce' ).val(), 36 38 post_id : last_id, 37 offset : $(' .type-post').size(),39 offset : $('article').size(), 38 40 }, 39 41 beforeSend: function(response) … … 43 45 success: function( response ) { 44 46 $('#matts_inf_scroll_loading').remove(); 45 $('.site-main').append(response); 46 matt_inf_scroll_processing = false; 47 console.log($('.type-post').size()); 48 } 47 if(response) { // check for non-empty response 48 $('#main').append(response); 49 ifsg_ajax_scripts_processing = false; 50 } 51 else { 52 ifsg_ajax_scripts_processing = true; 53 } 54 }, 49 55 }); 50 56 return false; … … 54 60 $.ajax( 55 61 { 56 url: matt_inf_scroll.ajax_url,62 url: ifsg_ajax_scripts.ajax_url, 57 63 type : 'post', 58 64 data : { 59 65 action : 'post_template_load_small', 66 security: $( '#inf_scroll_gp_ajax_nonce' ).val(), 60 67 post_id : last_id_small, 61 offset : $(' .type-post').size(),68 offset : $('article').size(), 62 69 }, 63 70 beforeSend: function(response) … … 67 74 success: function( response ) { 68 75 $('#matts_inf_scroll_loading').remove(); 69 $('.inside-right-sidebar').append(response); 70 matt_inf_scroll_processing = false; 71 console.log($('.type-post').size()); 76 if(response) { // check for non-empty response 77 $('#content').children('div:last').append(response); 78 ifsg_ajax_scripts_processing = false; 79 } 80 else { 81 ifsg_ajax_scripts_processing = true; 82 } 72 83 } 73 84 }); -
infinite-scroll-generatepress/trunk/readme.txt
r1752187 r1754497 1 === Infinite Scroll for GeneratePress ===1 === Infinite Scroll for GeneratePress === 2 2 Contributors: mathewemoore 3 3 Tags: generatepress, infinite scroll … … 6 6 Tested up to: 4.8.2 7 7 Requires PHP: 5.6 8 Stable tag: 1.0. 18 Stable tag: 1.0.2 9 9 License: GPLv2 or later 10 10 … … 14 14 15 15 Infinite Scroll for GeneratePress is a super lightweight plugin to enable infinite scroll functionality on your WordPress blog running the GeneratePress theme. 16 17 [youtube https://youtu.be/NueysU2XLlc ] 16 18 17 19 [→ Get More Information](https://northwoodsdigital.com/plugins/generatepress-infinite-scroll) … … 39 41 * Click 'Install Now' 40 42 * Activate the plugin 43 * Visit the plugin settings page from the WordPress Dashboard and enable your options 41 44 42 45 = Uploading in WordPress Dashboard = … … 44 47 * Navigate to 'Add New' in the plugins dashboard 45 48 * Navigate to the 'Upload' section 46 3. Select ` generatepress-infinite-scroll.zip` from your computer49 3. Select `infinite-scroll-generatepress.zip` from your computer 47 50 4. Click 'Install Now' 48 51 5. Activate the plugin in the Plugin dashboard 52 6. Visit the plugin settings page from the WordPress Dashboard and enable your options 49 53 50 54 = Using FTP = 51 55 52 56 1. Download `generatepress-infinite-scroll.zip` 53 2. Extract the ` generatepress-infinite-scroll.zip` directory to your computer54 3. Upload the ` generatepress-infinite-scroll.zip` directory to the `/wp-content/plugins/` directory57 2. Extract the `infinite-scroll-generatepress.zip` directory to your computer 58 3. Upload the `infinite-scroll-generatepress.zip` directory to the `/wp-content/plugins/` directory 55 59 4. Activate the plugin in the Plugin dashboard 60 6. Visit the plugin settings page from the WordPress Dashboard and enable your options 56 61 57 62 == Frequently Asked Questions == … … 59 64 [→ Contact Me](https://northwoodsdigital.com/contact) 60 65 66 == Screenshots == 67 68 1. Admin Settings for Infinite Scroll GenereatePress 69 61 70 == Changelog == 71 72 = 1.0.2 = 73 74 * Feature: added backend settings menu 75 * Feature: added option to choose post types to use 76 * Feature: added option to change number of 'posts_per_page' in AJAX calls 77 * Feature: added WYSIWYG option to append custom content to AJAX calls 78 * Feature: added WordPress default admin notices 79 80 * Change: now using native WordPress spinner gif for AJAX calls 81 * Change: adjusted AJAX output for mobile devices in case no sidebars active 82 * Change: remove default GeneratePress blog pagination when plugin is enabled 83 84 * Fix: prefixed plugin class variables 62 85 63 86 = 1.0.1 = … … 68 91 == Upgrade Notice == 69 92 93 = 1.0.2 = 94 Visit the plugin settings page from the WordPress Dashboard and enable your options after updating. 95 70 96 * None
Note: See TracChangeset
for help on using the changeset viewer.