Skip to content

Commit

Permalink
issue #7
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusgimenez committed May 26, 2015
1 parent b29d7dc commit 93177c2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
23 changes: 23 additions & 0 deletions assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
20 changes: 16 additions & 4 deletions inc/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,12 @@ function short_query_func( $atts ) {


if ($a['post_type'] == 'disco'){
$html .="<a href='".get_permalink( $query2->post->ID)."'><div class='".$class_item."cada-".$a['post_type']."'>
$html .="<a href='".get_permalink( $query2->post->ID)."'><div class='".$class_item."cada-".$a['post_type']." animated bounceIn'>
<div class='".$class_thumb."'>".get_the_post_thumbnail($query2->post->ID, $thumb)."</div>";
$html .= '<div class="texto_disco col-xs-8"><h1 class="titulo-disco">'.get_the_title( $query2->post->ID).'</h1>';
$content = get_the_content();
$trimmed_content = wp_trim_words( $content, 100, '...');
$html .= $trimmed_content."</div><div class='mais-disco'></div></div><div class='clearfix'></div>";

}
else if ($a['post_type'] == 'post'){
$html .="<a href='".get_permalink( $query2->post->ID)."'><div class='".$class_item."cada-".$a['post_type']."'>
Expand All @@ -147,10 +146,16 @@ function short_query_func( $atts ) {
$html .="<div class='".$class_item." cada-".$a['post_type']." animated bounceIn'>".get_the_post_thumbnail($query2->post->ID, $thumb)."</div>";
}
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 = '<a class="btn btn-primary btn-loadmore-discos" data-paged="2" data-loading="'.__('Carregando...', 'odin').'" data-selector="#interno-nav-disco" data-max-paged="'.$query2->max_num_pages.'">';
$depois_interno .= __('Carregar +','odin');
$depois_interno .= '</a>';
}

wp_reset_postdata();
else:
$html = 'Adicionar um '.$a['post_type'];
Expand Down Expand Up @@ -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' );
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' );

0 comments on commit 93177c2

Please sign in to comment.