رفتن به مطلب

لود شدن هر تب در هنگام کلیک بر روی آن


پست های پیشنهاد شده

استاد میشه سایت رو یه نگاه بندازید.F12 که میزنی قسمت console از فایل tabcontent اررور میگیره.میتونه مشکل از اون باشه؟!

لینک به ارسال

من از کد های خودتون استفاده کردم

http://1fakhar.ir/pages/tab-ajax/

درست بود ولی وقتی به جای متن محتوا آدرس فایل هایی که توش کد بود به صورت include قرار دادم کل سایت رو در اون تب شبیه آی فریم نشون میداد و سرعت سایت شدیدا افت کرد!!!!!!

درواقع اصلا سایت بالا نمیاد بلکه تو حالت لود میمونه :|

لینک به ارسال

برای اینکه محتواتون رو درست داخل شرط اجرا نگذاشتید

باور کنید کاری که می خواهید بکنید پیچیده نیست ولی آشنایی با php و جاوا اسکریپت پیش نیازهاش هستند

دقت کنید شرط گذاریتون باید اینجوری باشه


<?php
if(isset($_REQUEST['tab'])) {
$tab = $_REQUEST['tab'];
if($tab ==1) :
include (TEMPLATEPATH . '/tab1.php');
elseif($tab ==2) :
include (TEMPLATEPATH . '/tab2.php');
else :
include (TEMPLATEPATH . '/tab3.php');
endif;
}
else {؟>
کدهای فایلی که تبها در آن نمایش داده می شوند
<?php
};?>

لینک به ارسال

من همین کاری که شما گفتید انجام دادم ولی بازم در هر تب کل سایت رو نمایش داد!!!


<?php
if(isset($_REQUEST['tab'])) :
$tab = $_REQUEST['tab'];
if($tab==4) {
include (TEMPLATEPATH . '/tab4.php');
}
elseif($tab==3) {
include (TEMPLATEPATH . '/tab3.php');
}
elseif($tab==2) {
include (TEMPLATEPATH . '/tab2.php');
}
else {
include (TEMPLATEPATH . '/tab1.php');
}
else : ?>
<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="active">
<a class="tabs" data-tab="1">تب اول </a>
</li>
<li>
<a class="tabs" data-tab="2">تب دوم </a>
</li>
<li>
<a class="tabs" data-tab="3">تب سوم </a>
</li>
<li>
<a class="tabs" data-tab="4">تب چهارم </a>
</li>
</ul>
</div>
<div class="tab-content">
<div id="tab-entry" style="display:none" data-load="1">
محتواي تب اول
</div>
<div id="loading">Load ... </div>
</div>
<script>
$(document).ready(function() {
$("#tab-entry").load('index.php',{tab:1});
$("#tab-entry").promise().done(function() {
$("#loading").hide("normal").prev("#tab-entry").delay(1000).show("normal");
});
$(".tabs").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).parent("li").addClass("active");
$("#tab-entry").each(function() {
$(this).attr("data-load", tab).hide('normal').load('index.php',{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>

اینم عکسش

0d5bjn369t2t.png

لینک به ارسال

خوب پس چرا شما این نشانی رو دارید آژاکسی لود می کنید


.load('index.php',{tab:tab})

و این کدهایی که گذاشتید مال چه فایلیه ؟

کدها را باید در یک برگه مشخص قرار بدید و از اون لود کنید نشانی کامل اون برگه رو هم باید قرار بدید

الان شما صفحه خانگی را داری با آژاکس می خونی مسلمه که کل برگه را می آره

لینک به ارسال

من 4تا تب رو با نام های tab1.php , tab2.php , tab3.php , tab4.php جدا ساختم و کدهارو توش گذاشتم که هر تب رو از اونجا فراخوانی کنه

حالا این کدی که شما الان گذاشتید رو الان باید حذف کنم؟!

اون رو ساختم

این مثلا محتوای تب دومه

http://bourstahlil.ir/ajax?tab=2

ویرایش شده توسط M.Javad
لینک به ارسال

من به جای index.php اسم فایل برگه ajax-left.php رو قرار دادم ولی بازم تغییری نکرد.ایندفعه فقط تو هر تب مینویسه محتوای تب ...

لینک به ارسال

استاد عزیز من الان کد رو گذاشتم و فقط محتوای تب اول رو نشون میده ولی وقتی رو تب های دیگه میزنی کد درست عمل میکنه ولی محتوا رو نشون نمیده

در قسمت کنسول سایت یه اررور جاوااسکریپت از فایل tabcontent.js گرفته به این صورت


Uncaught TypeError: Cannot read property 'indexOf' of null

من احتمال میدم تداخلی بین کدها به وجود اومده یا ...

لینک به ارسال

این کد برگه ای هست که شما گفتید بسازم :


<?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; ?>

و اینم کد سایدبار


<?php
/**
* Theme: IIGC Group
* Created: April 2014
* Author: Alireza Saberi
*
**/
?>
<script type='text/javascript' src='<?php bloginfo('template_url'); ?>/jarid.js'></script>
<div id="sidebar">
<div class="search-fb">
<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
<input class="search" id="s" name="s" value="" placeholder="" />
<input class="submit" type="submit" value="" />
</form>
</div>
<div class="clear"></div>
<!--popup-->
<div style="margin-bottom: 15px;padding: 5px;background: rgba(245,245,245,1);border: 1px solid #bbb;border-bottom: 4px solid #bbb;border-radius: 5px;-webkit-border-radius: 5px;-moz-border-radius: 5px;box-shadow: 0 1px 1px rgba(0,0,0,0.1);font-family: Tahoma;font-size: 13px;color: rgba(0,54,104,0.8);">
<div class="popup-gallery">
<div style="text-align:center;background:white;border:1px solid #CCC;width:100%;height:40px;"><div style="background:black;width:95%;height:35px;margin:2px auto;"><a style="color:#CCC;line-height: 25px;
font-weight: bold;"><img src="http://www.bourstalar.ir/up/uploads/14119687133.png" width="18" style="margin-top:7px;float:right;margin-right:20px;"/><a style="color:#CCC;margin-right:7px;font-weight:bold;float:right;margin-top:8px;">تيتر روزنامه هاي اقتصادي</a></div></div>
<?php
$portfolio = new WP_Query(array(
'post_status' =>'publish',
'post_type' =>'post',
'cat' =>'6377',
'posts_per_page' =>'1',
'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1
));
?>
<ul class="slideshow" style="padding:0;margin:0;list-style-type:none;overflow:hidden;height:210px;border:1px solid #CCC;">
<?php
if($portfolio->have_posts()) :
while($portfolio->have_posts()) : $portfolio->the_post(); ?>
<li class="first"><a href="<?php the_permalink() ?>" title="براي ديدن ادامه روزنامه ها کليک کنيد"><img src="<?php $dl = get_post_meta($post->ID, 'a1', true); ?><?php echo $dl; ?>" ></a></li>
<li><a href="<?php the_permalink() ?>" title="براي ديدن ادامه روزنامه ها کليک کنيد"><img src="<?php $dl = get_post_meta($post->ID, 'a2', true); ?><?php echo $dl; ?>" ></a></li>
<li><a href="<?php the_permalink() ?>" title="براي ديدن ادامه روزنامه ها کليک کنيد"><img src="<?php $dl = get_post_meta($post->ID, 'a3', true); ?><?php echo $dl; ?>" ></a></li>
<li><a href="<?php the_permalink() ?>" title="براي ديدن ادامه روزنامه ها کليک کنيد"><img src="<?php $dl = get_post_meta($post->ID, 'a4', true); ?><?php echo $dl; ?>" ></a></li>
<li class="last"><a href="<?php the_permalink() ?>" title="براي ديدن ادامه روزنامه ها کليک کنيد"><img src="<?php $dl = get_post_meta($post->ID, 'a5', true); ?><?php echo $dl; ?>" ></a></li>
<?php endwhile; ?>
<?php endif; ?>
</ul>
<?php wp_reset_query();?>
<div style="margin-bottom: 5px;text-align:center;background:white;border:1px solid #CCC;width:100%;height:40px;"><div style="background:black;width:95%;height:35px;margin:2px auto;"><a style="color:#CCC;line-height: 25px;
font-weight: bold;"><img src="http://www.home.bourstahlil.ir/wp-content/themes/Silver/images/archives.png" width="18" style="margin-top:7px;float:right;margin-right:70px;"/><a href="http://www.home.bourstahlil.ir/category/news/%D8%B1%D9%88%D8%B2%D9%86%D8%A7%D9%85%D9%87" style="color:#CCC;margin-right:7px;font-weight:bold;float:right;margin-top:8px;">آرشيو</a></a></div></div>
</div>
</div>
<!--end popup-->
<script type="text/javascript">
$(document).ready(function() {
$("#tab-entry").load('http://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('http://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>
<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>
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar') ) : ?><?php endif; ?>
<a target="_blank" href="http://www.hemmat110.com/"><img width="230" src="<?php bloginfo('template_url'); ?>/images/k1.png" alt="" /></a>
<a target="_blank" href="http://behnamcharity.org.ir/index.php/home"><img width="230" src="<?php bloginfo('template_url'); ?>/images/k2.png" alt="" /></a>
<a target="_blank" href="http://childf.com/"><img width="230" src="<?php bloginfo('template_url'); ?>/images/k3.png" alt="" /></a>
</div>
</div>

جالب اینجاست که تب اول رو نشون میده ولی بقیه تب هارو نه !!!

لینک به ارسال
  • 2 سال بعد...
در در 12/2/2014 at 08:36، imanfakhar گفته است :

و با این اسکریپت جی کوئری هم کار می کنه

 

 

$(document).ready(function() {
$("#tab-entry").load('http://domain.com/ajax-tab',{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('http://domain.com/ajax-tab',{tab:tab}).next("#loading").delay(500).show();
  });
   $("#tab-entry").promise().done(function() {
   $("#loading").delay(500).hide("normal").prev("#tab-entry").delay(1000).show("normal");
   });
  }
});
});

چطور می‌تونم به این کد افکت fade بدم؟ تا محتوای تب فعلی محو شه و محتوای تبی که انتخاب کردیم آرام ظاهر شه؟ چون تو این کد محتوا به سمت راست منتقل میشه!!

لینک به ارسال

با سلام و احترام میتوانید به جای hide و show از fadeOut و fadeIn استفاده کنید 

http://api.jquery.com/fadeout/

http://api.jquery.com/fadein/

لینک به ارسال
در 2 ساعت قبل، Fenix.ir گفته است :

با سلام و احترام میتوانید به جای hide و show از fadeOut و fadeIn استفاده کنید 

http://api.jquery.com/fadeout/

http://api.jquery.com/fadein/

خیلی ممنون! ولی اگه خودتون امتحان کنید بعد از اعمال تغییراتی که گفتین اونطور انتظار میره کار نمیکنه. یعنی وقتی روی یک تب دیگه کلیک میشه محتواش بلافاصله ظاهر میشه و محو میشه و دوباره با سرعت آرام ظاهر میشه. که چندان جالب نیست!

لینک به ارسال
در در 12/3/2014 at 10:44، M.Javad گفته است :

استاد عزیز من این کد رو گذاشتم فقط تب اول رو نشون میده!!!

 

 

<script type="text/javascript">
$(document).ready(function() {
$("#tab-entry").load('http://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('http://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>
<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>

 

اینم آدرس سایت

http://bourstahlil.ir/

ستون سمت چپ

https://jqueryui.com/tabs/

http://jsfiddle.net/vRqcb/11/

 

لینک به ارسال

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع ...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...