Skip to content

Commit

Permalink
issue #1
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusgimenez committed May 18, 2015
1 parent fed2db5 commit cb7371b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 13 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error_log

.vagrant
Vagrantfile

*.swp
*.swo
*.zip
*~
sftp-config.json
23 changes: 23 additions & 0 deletions assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,28 @@ jQuery(document).ready(function($) {

console.log('altura doc'+$(document).height())
});

//ajax midia
$('.btn-loadmore').on('click',function(e){
var data = {
'action': 'midia_load_posts',
'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');
}
});

})
});

2 changes: 1 addition & 1 deletion front-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<?php wp_reset_postdata(); ?>

<?php else : ?>
<p><?php _e( 'Crie uma´seção', 'odin' ); ?></p>
<p><?php _e( 'Crie umaseção', 'odin' ); ?></p>

<?php endif;
?>
Expand Down
1 change: 1 addition & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ function odin_enqueue_scripts() {

// Main jQuery.
wp_enqueue_script( 'odin-main', $template_url . '/assets/js/main.js', array(), null, true );
wp_localize_script( 'odin-main', 'odin_main', array('ajaxurl' => admin_url( 'admin-ajax.php' )) );


// Grunt watch livereload in the browser.
Expand Down
29 changes: 17 additions & 12 deletions inc/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function short_query_func( $atts ) {

$a = shortcode_atts( array(
'post_type' => 'flauta',
'paged' => get_query_var( 'paged', 1 )
), $atts );
switch ($a['post_type']) {
case 'flauta':
Expand All @@ -29,12 +30,11 @@ function short_query_func( $atts ) {

break;
case 'midia':
$per_page= '9';
$per_page= '3';
$thumb='thumb-midia';
$class_item = 'col-sm-4';
$class_container = "row";



break;
case 'equipe':
$per_page= '999999';
Expand All @@ -61,7 +61,7 @@ function short_query_func( $atts ) {

break;
}
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$paged = $a['paged'];

$args = array(
'post_type' => $a['post_type'],
Expand All @@ -87,10 +87,14 @@ function short_query_func( $atts ) {

}
else{
$html .="<div class='".$class_item." cada-".$a['post_type']."'>".get_the_post_thumbnail($query->post->ID, $thumb)."</div>";
if($a['post_type'] == 'midia' && !defined('DOING_AJAX')){
$depois_interno = '<a class="btn btn-loadmore" data-paged="2" data-loading="'.__('Carregando...', 'odin').'" data-selector="#interno-nav-midia" data-max-paged="'.$query->max_num_pages.'">';
$depois_interno .= __('Carregar +','odin');
$depois_interno .= '</a>';
}
$html .="<div class='".$class_item." cada-".$a['post_type']."'>".get_the_post_thumbnail($query->post->ID, $thumb)."</div>";
}
endwhile;

wp_reset_postdata();
else:
$html = 'Adicionar um '.$a['post_type'];
Expand Down Expand Up @@ -121,9 +125,10 @@ function lista_videos( ) {
}
add_shortcode( 'videos', 'lista_videos' );







//ajax midia
function ajax_midia_load_posts(){
echo do_shortcode('[query post_type="midia" paged="'.$_POST['paged'].'"]');
wp_die();
}
add_action( 'wp_ajax_midia_load_posts', 'ajax_midia_load_posts' );
add_action( 'wp_ajax_nopriv_midia_load_posts', 'ajax_midia_load_posts' );

0 comments on commit cb7371b

Please sign in to comment.