Php wordpress短代码内容显示了两次
我正在为wordpress开发一个短代码 将word文件中的短代码用作:Php wordpress短代码内容显示了两次,php,wordpress,Php,Wordpress,我正在为wordpress开发一个短代码 将word文件中的短代码用作: add_shortcode('LATEST_NOT_ROHIT','latest_notification_rohit'); function latest_notification_rohit() { include("shortcode.php"); } 在shortcode.php文件中,代码如下: <div class='alert alert-info'>Latest Notificatio
add_shortcode('LATEST_NOT_ROHIT','latest_notification_rohit');
function latest_notification_rohit()
{
include("shortcode.php");
}
在shortcode.php
文件中,代码如下:
<div class='alert alert-info'>Latest Notifications</div>
<?php
global $wpdb;
$select_qury = "select * from `ln_category`";
$select_cat = $wpdb->get_results($select_qury);
foreach($select_cat as $select_cat)
{
echo "<h4>Latest Notifications For <span style='color:#800000'>".$select_cat->category."</span></h4>";
$cat_id = $select_cat->id;
$select_qury2 = "select * from `ln_notification` where `cat_id`='$cat_id'";
$select_notification = $wpdb->get_results($select_qury2);
?>
<table class="responsive display table table-bordered">
<tr><th>Sr No</th><th>Organisation</th><th>Post Name</th><th>No of Post</th><th>Qualification</th><th>Fees</th><th>Adervst Date</th><th>Application Start Date</th>
<th>Application Last Date</th><th>Status</th></tr>
<?php
$i=1;
foreach($select_notification as $select_notification)
{
$current_date = date('Y-m-d');
$start_date = $select_notification->start_date;
$last_date = $select_notification->last_date;
if($current_date < $start_date)
{
$remark = "<span style='color:green'>Form is about to start</span>";
}
elseif($current_date > $last_date)
{
$remark ="<span style='color:red'>Last Date is over</span>";
}
else
{
$remark = "Application is going on";
}
echo "<tr><td>$i</td><td>".$select_notification->organisation."</td><td>".$select_notification->post_name."</td><td>".$select_notification->no_of_post.
"</td><td>".$select_notification->qualification."</td><td>".$select_notification->fees."</td><td>".date('d-M-Y',strtotime($select_notification->adv_date))."</td><td>".date('d-M-Y',strtotime($start_date))."</td><td>".date('d-M-Y',strtotime($last_date))."</td><td>$remark</td></tr>";
$i++;
}
?>
</table>
<?php
}
?>
最新通知
您可能正在对以下文件之一调用最新通知\u rohit()函数:
- 页面的Header.php
- 页面模板文件
您也可能会为该页面调用两次内容函数。搜索所有内容()或最新通知\u rohit()可能会显示代码被多次调用的位置。您可能正在以下文件之一上调用最新通知\u rohit()函数:
add_shortcode('LATEST_NOT_ROHIT','latest_notification_rohit');
function latest_notification_rohit()
{
ob_start();
require_once("shortcode.php");
$data = ob_get_contents();
ob_end_clean();
return $data;
}
- 页面的Header.php
- 页面模板文件
您也可能会为该页面调用两次内容函数。搜索所有内容()或最新的\u通知\u rohit()可能会显示代码被多次调用的位置
add_shortcode('LATEST_NOT_ROHIT','latest_notification_rohit');
function latest_notification_rohit()
{
ob_start();
require_once("shortcode.php");
$data = ob_get_contents();
ob_end_clean();
return $data;
}
请你试试上面的代码好吗
请您试试上面的代码好吗?我想问题出在您的代码中,您使用了两个foreach循环
$select_qury = "select * from `ln_category`";
$select_cat = $wpdb->get_results($select_qury);
它可能返回两个类别,第一次让foreach执行两次。由于您的表正好位于第二个foreach循环之前,即使它没有记录,也会打印第二个表。如果有记录,请输入打印表格的条件
希望这能帮助你解决这个问题 我认为问题出在您的代码中,您使用了两个foreach循环
$select_qury = "select * from `ln_category`";
$select_cat = $wpdb->get_results($select_qury);
它可能返回两个类别,第一次让foreach执行两次。由于您的表正好位于第二个foreach循环之前,即使它没有记录,也会打印第二个表。如果有记录,请输入打印表格的条件
希望这能帮助你解决这个问题 尝试使用include\u once()
函数包含文件。不起作用…它只显示一次数据,但仅在标题中显示您如何在内容区域中调用短代码?刚刚看到您的url,您在哪里调用短代码以及如何调用短代码,请在此处提供。尝试使用include\u once()包含文件
function.not working…它只显示一次数据,但仅在标题中显示您如何在内容区调用快捷码?刚刚看到您的url,您在哪里调用快捷码以及如何调用,我把所有有问题的代码放在我看不到代码运行的地方两次了我把所有有问题的代码放在我看不到代码运行的地方两次了谢谢你对我来说它工作得很好谢谢你对我来说它工作得很好