2017-04-18 34 views
0

也許我沒有問正確的問題,但我必須錯過簡單的東西。如果我在一個頁面上放置一個運動分組,可以說'NFL',那麼我的短代碼顯示效果很好,但只要添加第二個運動組,可以說'棒球',生成的表格顯示3種類型的數據($ data_type ==「current」,$ data_type ==「past」,$ data_type ==「detailed」)在我下面提供的php文件memberresults函數中,對於該運動組不顯示。此外,爲第一組短碼(在本例中爲「NFL」)產生的數據是從任何一組/體育中隨機選擇的。短代碼衝突。我如何讓每個組獨立加載?

如何獲得所有這些短代碼以顯示每個運動的3種數據類型並將其加載到一個頁面中,而不會相互衝突?要查看頁面上發生了什麼,您可以在登錄後進入此處:https://wsplays-members.com/short-code-test/使用此臨時用戶名登錄用戶名「test」密碼「password」。作爲參考,我將在下面顯示我的代碼。先謝謝你。

短代碼在WordPress頁面中輸入

[get_biddata type='current' sport='NFL Football'] 
[get_biddata type='past' sport='NFL Football'] 
[get_biddata type='detailed' sport='NFL Football'] 

[get_biddata type='current' sport='NCAA Football'] 
[get_biddata type='past' sport='NCAA Football'] 
[get_biddata type='detailed' sport='NCAA Football'] 

[get_biddata type='current' sport='CFL Football'] 
[get_biddata type='past' sport='CFL Football'] 
[get_biddata type='detailed' sport='CFL Football'] 

[get_biddata type='current' sport='NBA Basketball'] 
[get_biddata type='past' sport='NBA Basketball'] 
[get_biddata type='detailed' sport='NBA Basketball'] 

[get_biddata type='current' sport='NCAA Basketball'] 
[get_biddata type='past' sport='NCAA Basketball'] 
[get_biddata type='detailed' sport='NCAA Basketball'] 

[get_biddata type='current' sport='MLB Baseball'] 
[get_biddata type='past' sport='MLB Baseball'] 
[get_biddata type='detailed' sport='MLB Baseball'] 

php文件memberresults功能

<?php 
function memberresults($sport_val,$data_type){ 
global $wpdb; 
    $bidsys_options = get_option('bidsys_options'); 
    for($i=1;$i<11;$i++){ 
     if($bidsys_options->sportsstatus[$i]!="Disabled"){ 
      if($sport_val==$bidsys_options->sportsname[$i]) 
      $sport = $i; 
    }} 
    $user = get_current_user_id(); 
    $currentsportaccess = get_user_meta($user,"sport_".$sport ,true); 
    if($currentsportaccess=="No"){ 
     ?> 
     <div class="pmpro_content_message">Your access plan is valid but does not give you access to view this section.<br /> You may <a href="<?=home_url();?>/purchase/">purchase another access plan here</a>.</div> 
     <?php 

    } else { 


    if($data_type=="current"){ 
     if (pmpro_hasMembershipLevel()) { 
    ?> 
    <script type='text/javascript'> 
jQuery(document).ready(function(){ 
    memberresults("current","<?php echo $sport;?>",""); 
}); 
</script> 
<h1 class="post-title"><?php echo $sport_val; ?> Picks</h1> 
<h2 class="post-title">Current Season</h2> 
<table class='inner_result'> 
<td colspan='5' > 
<table id='member_<?=$data_type;?>season_vals_inner' class='hdr_3 inner_result'> 
</table> 
</td> 
</table> 
    <?php 
     } else { 

      ?> 
     <h1 class="post-title"><?php echo $sport_val; ?> Picks</h1> 
     <h2 class="post-title">Current Season Record</h2> 
     <div class="pmpro_content_message">You must be logged in to view this section. Please <a href="<?=home_url();?>/login/">log in</a> or <a href="<?=home_url();?>/register/">register here</a>.</div> 
     <?php 

     } 
    } else if($data_type=="past"){ 
    if (pmpro_hasMembershipLevel()) { 

    $result = "SELECT * FROM ".$wpdb->prefix."bidsys_sport_seasons WHERE sport= '".$sport."' AND current_season = 'NO' ORDER BY start_date DESC"; 
    $newmeta = $wpdb->get_results($result); 
    ?> 
<script type='text/javascript'> 
jQuery(document).ready(function(){ 
    memberresults("past","<?php echo $sport;?>","season_<?php echo $newmeta[0]->id;?>"); 
}); 
</script> 
<h1 class="post-title"><?php echo $sport_val; ?> Picks</h1> 
<h2 class="post-title">Previous Seasons</h2> 
    <form action='' method='post' class="f_p_filter_frm outside_table"> 
    <select name='f_p_filter' class="f_p_filter" onchange='memberresults("past","<?php echo $sport; ?>",this.value)' > 
    <?php $i = 0; foreach($newmeta as $seasons){ 
     if($i == 0){ $sel = 'selected=""'; } else { $sel = ""; } 
     ?> 
    <option value='season_<?php echo $seasons->id;?>' <?php echo $sel;?>><?php echo $seasons->season_name;?></option> 
    <?php $i++; } ?> 
    </select> 
    </form> 

<table class='inner_result'> 
<td colspan='5' > 
<table id='member_<?=$data_type;?>season_vals_inner' class='hdr_3'> 
</table> 
</td> 
</table> 
    <?php 
     } else { 

      ?> 
     <h1 class="post-title"><?php echo $sport_val; ?> Picks</h1> 
     <h2 class="post-title">Previous Seasons Records</h2> 
     <div class="pmpro_content_message">You must be logged in to view this section. Please <a href="<?=home_url();?>/login/">log in</a> or <a href="<?=home_url();?>/register/">register here</a>.</div> 
     <?php 

     } 

    } else if($data_type=="detailed"){ 
    if (pmpro_hasMembershipLevel()) { 
    ?> 
    <script type='text/javascript'> 
jQuery(document).ready(function(){ 
    memberresults("detailed","<?php echo $sport;?>","yesterday"); 
}); 
</script> 
<style> 
.imgwin { 
    background: url('/wp-content/plugins/bid-sys/customgif/winningPick.gif'); 
    height: 16px; width: 16px; margin:8px; 
} 
.imgloss { 
    background: url('/wp-content/plugins/bid-sys/customgif/losingPick.gif'); 
    height: 16px; width: 16px; margin:8px; 
} 
.imgpush { 
    background: url('/wp-content/plugins/bid-sys/customgif/pushedPick.gif'); 
    height: 16px; width: 16px; margin:8px; 
} 

</style> 
<h1 class="post-title"><?php echo $sport_val; ?> Picks</h1> 
<h2 class="post-title">Detailed History</h2> 
<form action='' method='post' class="f_p_filter_frm outside_table"> 
    <select name='f_p_filter' class="f_p_filter" onchange='memberresults("detailed","<?php echo $sport; ?>",this.value)' > 
    <?php 
    $result = "SELECT * FROM ".$wpdb->prefix."bidsys_sport_seasons WHERE sport= '".$sport."' AND current_season = 'NO' ORDER BY start_date DESC"; 
    $newmeta = $wpdb->get_results($result); 

    foreach($newmeta as $seasons){ 
     ?> 
    <option value='season_<?php echo $seasons->id;?>' ><?php echo $seasons->season_name;?></option> 
    <?php } 
    ?> 
    <option value='playoftheday30' >Play of the Day (L30 Days)</option> 
    <option value='playoftheday365' >Play of the Day (L365 Days)</option> 
    <option value='latebreakingplay30' >VIP Late Info Play (L30 Days)</option> 
    <option value='latebreakingplay365' >VIP Late Info Play (L365 Days)</option> 
    <option value='vipplays30' >VIP Plays (L30 Days)</option> 
    <option value='vipplays365' >VIP Plays (L365 Days)</option> 
    <option value='yesterday' selected="">Yesterday</option> 
    <!--<option value='thisweek' >This Week</option>--> 
    <option value='past7days' >Past 7 Days</option> 
    <!--<option value='thismonth' >This Month</option>--> 
    <option value='past30days' >Past 30 Days</option> 
    <!-- <option value='thisyear' >This Year</option> --> 
    <option value='current' >Current Season</option> 
    <option value='past365days' >Past 365 Days</option> 
    </select> 
    </form> 
<div style="width: 56px; float: right; background: #F8F8F8;"><img src="/wp-content/plugins/bid-sys/customgif/pushedPick.gif" /> Push</div><div style=" margin: -2px 3% 0; padding-bottom: 2px; float: right;">|</div> 
<div style="width: 56px; float: right; background: #F8F8F8;"><img src="/wp-content/plugins/bid-sys/customgif/losingPick.gif" /> Loss</div><div style=" margin: -2px 3% 0; padding-bottom: 2px; float: right;">|</div> 
<div style="width: 48px; float: right; background: #F8F8F8;"><img src="/wp-content/plugins/bid-sys/customgif/winningPick.gif" /> Win</div> 
<table class='inner_result detailed_history'> 
<tr class="hdr_2"> 
<td>Game Date</td> 
<td colspan="2">Game/Pick Details</td> 
<td>Result</td> 
<td>Unit Change</td> 
</tr> 
<table id='member_<?=$data_type;?>season_vals_inner' class='hdr_3'> 
</table> 
</table> 
    <?php 
     } else { 

      ?> 
     <h1 class="post-title"><?php echo $sport_val; ?> Picks</h1> 
     <h2 class="post-title">Detailed History</h2> 
     <div class="pmpro_content_message">You must be logged in to view this section. Please <a href="<?=home_url();?>/login/">log in</a> or <a href="<?=home_url();?>/register/">register here</a>.</div> 
     <?php 

     } 

    } else if($data_type=="pending"){ 
     if (pmpro_hasMembershipLevel()) { 
    ?> 
<script type='text/javascript'> 
jQuery(document).ready(function(){ 
    memberresults("pending","<?php echo $sport;?>",""); 
}); 
</script> 
<h1 class="post-title">Today's <?php echo $sport_val; ?> Picks</h1> 
<table id='member_<?=$data_type;?>season_vals_inner' class='hdr_3'> 
</table> 
    <?php 
     } 
     } else if($data_type=="unauthorized"){ 
      if (pmpro_hasMembershipLevel()) { 
     ?> 
<h1 class="post-title">Today's <?php echo $sport_val; ?> Picks</h1> 
<div class="members-only"> 
Picks posted here are for <strong>PAID MEMBERS ONLY</strong>.<br> Your current membership level is not authorized to view this section.</strong><br> <a href="<?=home_url();?>/subscription-options/">Click Here</a> to upgrade your membership and view today's <?php echo $sport_val; ?> picks.</p></div> 
     <?php 
     } 
     } 

     else if($data_type=="defaultMessage"){ 
      if (pmpro_hasMembershipLevel()) { 
     ?> 
     <!--INTENTIONALLY LEFT BLANK SO WHEN A MEMBER LOGS IN THE MESSAGE BELOW DISAPPEARS--> 
     <?php 

     } else { 

     ?> 
<div class="loggedout-members-only"> 
<p>Picks posted here are for <strong>PAID MEMBERS ONLY</strong>.<br> 
<a href="http://wsplays-members.com/login/">Log In</a> &nbsp;-<strong>or</strong>-&nbsp; <a href="http://wsplays-members.com/subscription-options/">View/Purchase Subscriptions Here</a>.</p> 
<p><a href="http://wsplays-members.com/membership-account/membership-checkout/?level=23">Click Here</a> to register for <strong>FREE PICKS</strong> and gain <strong>FREE ACCESS</strong><br> to our Pick History &amp; Detailed Records </p> 
</div> 
     <?php 
     } 
     } 
    } 
} 
?> 

php文件簡碼

include('ajax_member_support.php'); 
function ajax_member_support($atts) { 
    extract(shortcode_atts(array(
     'sport' => '', 
     'type' => '', 
    ), $atts)); 

    $sport_val = $sport; 
    $data_type = $type; 

ob_start(); 
memberresults($sport_val,$data_type); 
$output_string=ob_get_contents();; 
ob_end_clean(); 

return $output_string; 

} 
add_shortcode('get_biddata', 'ajax_member_support'); 

JavaScript文件

var memberresults = 
     function memberresults(seasontype, sport, seasonrange) { 
      "use strict"; 
      var ajaxl = '<img src="/wp-content/plugins/bid-sys/customgif/ajax-loader.gif" alt="" />', 
       dataURL = "seasontype=" + seasontype + "&sport=" + sport + "&seasonrange=" + seasonrange; 
      jQuery("#member_" + seasontype + "season_vals_inner").html(ajaxl); 
      jQuery.ajax({ 
       type: "POST", 
       url: "/wp-content/plugins/bid-sys/ajax_member.php", 
       data: dataURL, 
       success: function (msg) { // alert(msg); 
        jQuery("#member_" + seasontype + "season_vals_inner").html(msg); 
       } 
      }); 
     }; 

回答

1

問題是,插件創建表ID的member_currentseason_vals_inner,member_pastseason_vals_inner等。渲染6每個意味着6重複的ID,而ID的應該是唯一的! ajax把它的結果放在它找到的第一張表中,所有的結果都會放到'NFL足球'表中。

您看到的隨機性是因爲對於每個體育運動,會員結果都是通過ajax單獨提取的,這是異步的,即內容在它到達瀏覽器時呈現。任何結果都可能最後到達,這就是你將在NFL表格中看到的結果。

這可以通過一個封裝來解決,該封裝作爲js/jquery的上下文來查找正確的表,但最好修復唯一的ID。因爲我不認爲你想讓每項運動都不止一次顯示,所以我建議將php $sport編號附加到表格id並調整js以使用它。 js memberresults()已經收到這個數字作爲第二個參數。

在PHP memberresults功能,改變下面的行,4次:

<table id='member_<?=$data_type;?>season_vals_inner' class='hdr_3 inner_result'> 

到:

<table id='member_<?=$data_type;?>season_vals_inner<?=$sport;?>' class='hdr_3 inner_result'> 

在JavaScript memberresults改變以下,2次:

jQuery("#member_" + seasontype + "season_vals_inner").html ... 

至:

jQuery("#member_" + seasontype + "season_vals_inner" + sport).html ... 
+0

是的!感謝您花時間!這個伎倆。從中學到很多東西。再次,非常感謝:) – kma1289