Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function my_login_wpcategories(){
- global $wpdb;
- $slide = 1;
- $popup = 1;
- $ajax_content = '';
- $taxonomy = 'wpcategories';
- $parent_term = $_GET['term'];
- $parent_term_id = $wpdb->get_var("SELECT term_id FROM $wpdb->terms WHERE slug='$parent_term'");
- $child_term = get_term_children( $parent_term_id , $taxonomy );
- foreach($child_term as $term){
- if($slide==1 || $slide%3==1)
- $ajax_content .= '<div class="slide">';
- $term_data = get_term_by('id', $term, $taxonomy);
- $args = array(
- 'post_type' => 'whitepaper',
- 'tax_query' => array(
- array(
- 'taxonomy' => $taxonomy,
- 'field' => 'id',
- 'terms' => $term
- )
- ),
- 'posts_per_page' => -1
- );
- $tabpopup = $slidebase = '';
- $pop_i = 1;
- $my_post = new WP_Query($args);
- // .processitem
- $ajax_content .= '<div class="processitem">';
- if($my_post->have_posts()) :
- while ( $my_post->have_posts() ) : $my_post->the_post();
- if($pop_i<=5)
- $tabpopup_content .= '<p><a href="'.get_permalink().'">'.get_the_title().'</a></p>';
- $pop_i++;
- $slidebase_content .= '<p><a href="'.get_permalink().'">'.get_the_title().'</a></p>';
- endwhile;
- $tabpopup .= '<div id="pop'.str_pad( $popup, 2, 0, STR_PAD_LEFT ).'" class="tabpopup" style="display: none;"><h3>'.$term_data->name.'</h3><div>';
- $tabpopup .= $tabpopup_content;
- $tabpopup .= '</div></div>';
- $slidebase .= '<div class="slidebase noborder tabber"><h3>'.$term_data->name.'</h3><div>';
- $slidebase .= $slidebase_content;
- $slidebase .= '</div><p><a href="#" id="p'.str_pad( $popup, 2, 0, STR_PAD_LEFT ).'" class="mediumgraybutton">More</a></p></div>';
- $ajax_content .= $tabpopup;
- $ajax_content .= $slidebase;
- endif;
- // .processitem
- $ajax_content .= '</div>';
- if($slide%3==0)
- $ajax_content .= '</div><!--slide-->';
- $slide++; $popup++;
- }
- if(($slide-1)%3!=0)
- $ajax_content .= '</div><!--slide-->';
- echo $ajax_content;
- die;
- }
- function my_nonlogin_wpcategories(){
- global $wpdb;
- $slide = 1;
- $popup = 1;
- $ajax_content = '';
- $register_url = 'http://yoursite.com/register';
- $taxonomy = 'wpcategories';
- $parent_term = $_GET['term'];
- $parent_term_id = $wpdb->get_var("SELECT term_id FROM $wpdb->terms WHERE slug='$parent_term'");
- $child_term = get_term_children( $parent_term_id , $taxonomy );
- foreach($child_term as $term){
- if($slide==1 || $slide%3==1)
- $ajax_content .= '<div class="slide">';
- $term_data = get_term_by('id', $term, $taxonomy);
- $args = array(
- 'post_type' => 'whitepaper',
- 'tax_query' => array(
- array(
- 'taxonomy' => $taxonomy,
- 'field' => 'id',
- 'terms' => $term
- )
- ),
- 'posts_per_page' => -1
- );
- $tabpopup = $slidebase = '';
- $pop_i = 1;
- $my_post = new WP_Query($args);
- // .processitem
- $ajax_content .= '<div class="processitem">';
- if($my_post->have_posts()) :
- while ( $my_post->have_posts() ) : $my_post->the_post();
- if($pop_i<=5)
- $tabpopup_content .= '<p><a href="'.$register_url.'">'.get_the_title().'</a></p>';
- $pop_i++;
- $slidebase_content .= '<p><a href="'.$register_url.'">'.get_the_title().'</a></p>';
- endwhile;
- $tabpopup .= '<div id="pop'.str_pad( $popup, 2, 0, STR_PAD_LEFT ).'" class="tabpopup" style="display: none;"><h3>'.$term_data->name.'</h3><div>';
- $tabpopup .= $tabpopup_content;
- $tabpopup .= '</div></div>';
- $slidebase .= '<div class="slidebase noborder tabber"><h3>'.$term_data->name.'</h3><div>';
- $slidebase .= $slidebase_content;
- $slidebase .= '</div><p><a href="#" id="p'.str_pad( $popup, 2, 0, STR_PAD_LEFT ).'" class="mediumgraybutton">More</a></p></div>';
- $ajax_content .= $tabpopup;
- $ajax_content .= $slidebase;
- endif;
- // .processitem
- $ajax_content .= '</div>';
- if($slide%3==0)
- $ajax_content .= '</div>';
- $slide++; $popup++;
- }
- if(($slide-1)%3!=0)
- $ajax_content .= '</div><!--slide-->';
- echo $ajax_content;
- die;
- }
- add_action('wp_ajax_wpcategories_action', 'my_login_wpcategories');
- add_action('wp_ajax_nopriv_wpcategories_action', 'my_nonlogin_wpcategories');
- // enqueue our ajax script file and passing ajaxurl value
- function my_ajax_load_scripts() {
- // get our custom-script.js
- wp_enqueue_script('my-custom-script', get_template_directory_uri() . '/js/custom-script.js');
- // globalize admin-ajax.php url for ajax processing page
- wp_localize_script('my-custom-script', 'my_wp', array(
- 'ajaxurl' => admin_url('admin-ajax.php'),
- 'action' => 'wpcategories_action'
- )
- );
- }
- add_action('wp_enqueue_scripts', 'my_ajax_load_scripts');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement