making tab content with ajax
-
hey everyone
I want to make a tab content by ajax
i make a new page named left-ajax.php
this is all code in page :<?php /* template name: left ajax */ if(isset($_REQUEST['tab'])) : $tab = $_REQUEST['tab']; if($tab==4) { ?> <div id="tab4" class="tabs-wrap"> <?php $custom_query = new WP_Query(array( 'post_status' =>'published', 'post_type' =>'post', 'order' =>'descending', 'orderby' =>'ID', 'cat' =>'854', 'posts_per_page' =>'7', 'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1 )); ?> <ul> <?php if($custom_query->have_posts()) : while($custom_query->have_posts()) : $custom_query->the_post();?> <li> <div class="post-thumbnail"> <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="bookmark"><?php echo get_the_post_thumbnail(); ?><span class="overlay-icon"></span></a> </div> <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> <span class="date"><span class="tie-date"><?php $days = round((date('U') - get_the_time('U')) / (60*60*24)); if ($days==0) echo timeago(); else echo " " . $days . " ??? ???"; ?> </span></span><br/> </li> <?php endwhile;endif; ?> </ul> <?php wp_reset_query(); ?> </div> <?php } elseif($tab==3) { ?> <div id="tab3" class="tabs-wrap"> <?php $number=7; // number of recent comments desired $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $number"); ?> <ul id="recentcomments"> <?php if ( $comments ) : foreach ( (array) $comments as $comment) : echo '<li class="recentcomments" style="font-size:11px;">' . sprintf(__('%1$s ?? %2$s'), get_comment_author_link(), '<a href="'. get_comment_link($comment->comment_ID) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>'; endforeach; endif;?></ul> </div> <?php } elseif($tab==2) { ?> <div id="tab2" class="tabs-wrap"> <ul> <?php query_posts('meta_key=post_views_count&orderby=meta_value_num&order=DESC&showposts=7'); if (have_posts()) : while (have_posts()) : the_post(); ?> <li> <div class="post-thumbnail"> <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="bookmark"><?php echo get_the_post_thumbnail(); ?><span class="overlay-icon"></span></a> </div> <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> <span class="date"><span class="tie-date"><?php $days = round((date('U') - get_the_time('U')) / (60*60*24)); if ($days==0) echo timeago(); else echo " " . $days . " ??? ???"; ?></span><br/> </span> </li> <?php endwhile; endif; wp_reset_query(); ?> </ul> </div> <?php } else { ?> <div id="tab1" class="tabs-wrap"> <?php $custom_query1 = new WP_Query(array( 'post_status' =>'published', 'post_type' =>'post', 'order' =>'descending', 'orderby' =>'ID', 'cat' =>'894,893,10,851,853,14,855,13,856,857,859,15', 'posts_per_page' =>'8', 'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1 )); ?> <ul> <?php if($custom_query1->have_posts()) : while($custom_query1->have_posts()) : $custom_query1->the_post();?> <li> <div class="post-thumbnail"> <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="bookmark"> <?php echo get_the_post_thumbnail(); ?> <span class="overlay-icon"></span></a> </div> <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> <span class="date"><span class="tie-date"><?php $days = round((date('U') - get_the_time('U')) / (60*60*24)); if ($days==0) echo timeago(); else echo " " . $days . " ??? ???"; ?></span><br/></span> </li> <?php endwhile;endif; ?> </ul> <?php wp_reset_query(); ?> </div> <?php } endif; ?>
and this is content in sidebar for showing tab content
<aside class="sidebar" style="margin-bottom:-12px"> <div class="widget" id="tabbed-widget"> <div style="margin-top:-20px" class="widget-container"> <div class="widget-top"> <!-- ???? ??????? ?? --> <ul class="tabs posts-taps"> <li class="tabs"> <a class="tab-button active" data-tab="1">?? ??? </a> </li> <li class="tabs"> <a class="tab-button" data-tab="2">?? ??? </a> </li> <li class="tabs"> <a class="tab-button" data-tab="3">?? ??? </a> </li> <li class="tabs"> <a class="tab-button" data-tab="4">?? ????? </a> </li> </ul> <!-- / ???? ??????? ?? --> <div class="tab-content"> <div id="tab-entry" style="display:none" data-load="1"> <?php query_posts( array( 'page_id' => 36848 ) ); // ID of the page including the form if ( have_posts() ) : while ( have_posts() ) : the_post(); the_content(); endwhile; endif; wp_reset_query(); ?> </div> <div id="loading">Load ... </div> </div> </div> </div> </aside> <script type="text/javascript"> $(document).ready(function() { $("#tab-entry").load('https://bourstahlil.ir/ajax',{tab:1}); $("#tab-entry").promise().done(function() { $("#loading").hide("normal").prev("#tab-entry").delay(1000).show("normal"); }); $(".tab-button").click(function() { var tab = $(this).attr("data-tab"); var dl = $("#tab-entry").attr("data-load"); if(tab !== dl) { $(this).parent("li").parent("ul").find(".active").removeClass("active"); $(this).addClass("active"); $("#tab-entry").each(function() { $(this).attr("data-load", tab).hide('normal').load('https://bourstahlil.ir/ajax',{tab:tab}).next("#loading").delay(500).show(); }); $("#tab-entry").promise().done(function() { $("#loading").delay(500).hide("normal").prev("#tab-entry").delay(1000).show("normal"); }); } }); }); </script>
the problem is just tab1 is working and other tabs are done…!!!
i mean they work currectly in inspect element by dont show anything…
in console there is an error :Uncaught TypeError: Cannot read property ‘indexOf’ of null
in tabcontent.js…
can anybody help please
sorry for my bad english ??
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘making tab content with ajax’ is closed to new replies.