我试图通过课程检查localhost:8080/service-1
是否已经检查过{&1;}是空的,如果它们是隐藏整列。我试图通过jquery这样做。该表是从wordpress页面循环创建的,所以我找不到用PHP做的方法。
表HTML是这样的:
<td>
显示表格的PHP代码位于:https://paste.ee/p/yrQpg
我想用班级&#39; temizleme&#39;来检查细胞。在这段代码中。相关部分是:
<table>
<tr>
<th>header</th>
<th id="checking-tds-header">header</th>
<th>header</th>
</tr>
<tr>
<td>info</td>
<td class="checkthisone"></td>
<td>info</td>
</tr>
<tr>
<td>info</td>
<td class="checkthisone"></td>
<td>info</td>
</tr>
</table>
答案 0 :(得分:2)
排除PHP中的<tr>
要排除整行:
例如,要检查post_meta中的temizleme
中的值:
<?php
while ( $query->have_posts() ) : $query->the_post();
/* 1. Get the post_meta value of temizleme */
$temizleme = get_post_meta( get_the_ID(), 'temizleme', true );
/* 2. check if temizleme has a value */
if (!empty($temizleme)) {
/* 3. if temizleme isn't empty, display the row */
?>
<tr>
<td>
<a class="mangaep-episode" href="<?php the_permalink(); ?>"><?php echo get_post_meta( get_the_ID(), 'kacinci_bolum', true ); ?>
<?php $bolum_aciklamasi = get_post_meta(get_the_ID(), 'bolum_aciklamasi', true);
if ( ! empty ( $bolum_aciklamasi ) ) { ?>
<span><?php echo $bolum_aciklamasi; ?></span>
<?php } ?>
</a>
</td>
<td><?php if(function_exists('the_views')) { the_views(); } ?></td>
<td class="down"><?php echo get_post_meta( get_the_ID(), 'cevirmen', true ); ?></td>
<td class="down"><?php echo get_post_meta( get_the_ID(), 'editor', true ); ?></td>
<td class="down temizleme"><?php echo get_post_meta( get_the_ID(), 'temizleme', true ); ?></td>
<td class="down">
<?php $indirme_linki = get_post_meta(get_the_ID(), 'indirme_linki', true);
if ( ! empty ( $indirme_linki ) ) { ?>
<a target="_blank" href="<?php echo $indirme_linki; ?>" class="mangaep-down">İNDİR</a>
<?php } ?>
</td>
</tr>
<?php } /* 3. end if (!empty(temizleme)) */ ?>
<?php endwhile; ?>
检查多个值
您链接的代码与您在问题中包含的代码不同,因此我不确定您需要检查的内容。
因此,如果要检查多个值,只需获取while循环开头的所有值,并检查它们是否有值。
如果他们必须在您的&&
语句中使用if
,那么,如果任何人可以使用值||
。 e.g。
<?php
while ( $query->have_posts() ) : $query->the_post();
/* 1. Get the post_meta values to check */
$temizleme = get_post_meta( get_the_ID(), 'temizleme', true );
$kacinci_bolum= get_post_meta( get_the_ID(), 'kacinci_bolum', true );
/* 2. check that BOTH have a value */
if (!empty($temizleme) && !empty($kacinci_bolum)) {
?>
<tr>
[... display your tds the same way as above...]
</tr>
<?php } /* end if (!empty...) */ ?>
<?php endwhile; ?>
隐藏PHP中的列
要检查列的值,您需要:
$bTemizlemeColumnIsEmpty
设置为false) / LI>
$bTemizlemeColumnIsEmpty
为真),则不要为“temizleme”显示<td>
例如:
<?php
$postdata = array(); /* array to save data for ALL posts */
while ( $query->have_posts() ) : $query->the_post();
/* 1. Save all the post data in an array */
$row = array(); /* array to save data for THIS post */
$row["temizleme"] = get_post_meta( get_the_ID(), 'temizleme', true );
$row["kacinci_bolum"] = get_post_meta( get_the_ID(), 'kacinci_bolum', true );
$row["bolum_aciklamasi"] = get_post_meta( get_the_ID(), 'bolum_aciklamasi', true );
[etc...]
$postdata[] = $row; /* add this data to the $postdata array */
<?php endwhile; ?>
/* 2. check the values of temizleme */
$bTemizlemeColumnIsEmpty = true;
foreach ($postdata as $row)
if (!empty($row["temizleme"])) $bTemizlemeColumnIsEmpty = false;
/* if any of the cells have a value, $bTemizlemeColumnIsEmpty will be false after we finish this loop */
/* 3. now loop through all the row to display the table */
foreach ($postdata as $row){
?>
<tr>
<td>
<a class="mangaep-episode" href="<?php the_permalink(); ?>"><?php echo $row["kacinci_bolum"]; ?>
<?php if ( ! empty ( $row["bolum_aciklamasi"] ) ) { ?>
<span><?php echo $row["bolum_aciklamasi"]; ?></span>
<?php } ?>
</a>
</td>
<td><?php if(function_exists('the_views')) { the_views(); } ?></td>
<td class="down"><?php echo $row["cevirmen"]; ?></td>
<td class="down"><?php echo $row["editor"]; ?></td>
<?php
/* 4. only display this td if $bTemizlemeColumnIsEmpty is false */
if ( !$bTemizlemeColumnIsEmpty ){
?>
<td class="down temizleme"><?php echo $row["temizleme"]; ?></td>
<?php } ?>
<td class="down">
<?php if ( ! empty ( $row["indirme_linki"] ) ) { ?>
<a target="_blank" href="<?php echo $row["indirme_linki"]; ?>" class="mangaep-down">İNDİR</a>
<?php } ?>
</td>
</tr>
<?php } /* end foreach */ ?>
答案 1 :(得分:0)
尝试这种方法:
$(document).ready(function(){
$(".checkthisone").each(function(){ // check each class
if($(this).text() == ""){ // if the <td> has nothing in it, enter this condition
$(this).parent("tr").hide(); // hide the entire <tr>
}
});
});
$(document).ready(function(){
$(".checkthisone").each(function(){
if($(this).text() == ""){
$(this).parent("tr").hide();
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<th>header</th>
<th id="checking-tds-header">header</th>
<th>header</th>
</tr>
<tr>
<td>info</td>
<td class="checkthisone"></td>
<td>info</td>
</tr>
<tr>
<td>info</td>
<td class="checkthisone">stuff</td>
<td>info</td>
</tr>
</table>
答案 2 :(得分:0)
最简单的解决方案是使用:empty
选择器
$( "#checking-tds-header" ).hide();
$( "td.checkthisone:empty" ).hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<th>header</th>
<th id="checking-tds-header">header</th>
<th>header</th>
</tr>
<tr>
<td>info</td>
<td class="checkthisone"></td>
<td>info</td>
</tr>
<tr>
<td>info</td>
<td class="checkthisone"></td>
<td>info</td>
</tr>
</table>