From 93177c2e0c1f1afa2991375cf5e49ec1ee65e27a Mon Sep 17 00:00:00 2001 From: matheus Date: Tue, 26 May 2015 13:44:05 -0300 Subject: [PATCH] issue #7 --- assets/js/main.js | 23 +++++++++++++++++++++++ inc/shortcodes.php | 20 ++++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/assets/js/main.js b/assets/js/main.js index 2078a53..28861b2 100755 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -242,6 +242,29 @@ jQuery(document).ready(function($) { }); }); + //ajax discos + $('.btn-loadmore-discos').on('click',function(e){ + var data = { + 'action': 'discos_load', + 'paged': $(this).attr('data-paged'), + }; + var default_html = $(this).html(); + $(this).html($(this).attr('data-loading')); + var elem = this; + var selector = $(elem).attr('data-selector'); + $.post(odin_main.ajaxurl, data, function(response) { + $(selector).append(response); + $(elem).html(default_html); + var paged = parseInt($(elem).attr('data-paged')) + 1; + var max_paged = parseInt($(elem).attr('data-max-paged')); + $(elem).attr('data-paged',paged); + if(paged > max_paged){ + $(elem).fadeOut('slow'); + } + }); + + }); + //ajax facebook var data = { 'action': 'facebook_brasa_social_feed' diff --git a/inc/shortcodes.php b/inc/shortcodes.php index ad19341..f3bbc83 100644 --- a/inc/shortcodes.php +++ b/inc/shortcodes.php @@ -121,13 +121,12 @@ function short_query_func( $atts ) { if ($a['post_type'] == 'disco'){ - $html .="
+ $html .="
".get_the_post_thumbnail($query2->post->ID, $thumb)."
"; $html .= '

'.get_the_title( $query2->post->ID).'

'; $content = get_the_content(); $trimmed_content = wp_trim_words( $content, 100, '...'); $html .= $trimmed_content."
"; - } else if ($a['post_type'] == 'post'){ $html .="
@@ -147,10 +146,16 @@ function short_query_func( $atts ) { $html .="
".get_the_post_thumbnail($query2->post->ID, $thumb)."
"; } endwhile; - if($a['post_type'] == 'midia' && defined('DOING_AJAX') && DOING_AJAX){ + if(defined('DOING_AJAX') && DOING_AJAX){ global $ajax_max_paged; $ajax_max_paged = $query2->max_num_pages; } + if($a['post_type'] == 'disco' && !defined('DOING_AJAX')){ + $depois_interno = '
'; + $depois_interno .= __('Carregar +','odin'); + $depois_interno .= ''; + } + wp_reset_postdata(); else: $html = 'Adicionar um '.$a['post_type']; @@ -205,4 +210,11 @@ function ajax_midia_load_category(){ wp_die(); } add_action( 'wp_ajax_midia_load_category', 'ajax_midia_load_category' ); -add_action( 'wp_ajax_nopriv_midia_load_category', 'ajax_midia_load_category' ); \ No newline at end of file +add_action( 'wp_ajax_nopriv_midia_load_category', 'ajax_midia_load_category' ); + +function ajax_discos_load(){ + echo do_shortcode('[query post_type="disco" paged="'.$_POST['paged'].'"]'); + wp_die(); +} +add_action( 'wp_ajax_discos_load', 'ajax_discos_load' ); +add_action( 'wp_ajax_nopriv_discos_load', 'ajax_discos_load' ); \ No newline at end of file