drh19790711 2017-04-03 10:47
浏览 54

wordpress短代码内容显示两次

I am developing a shortcode for wordpress.

using the shortcode in word file as :

add_shortcode('LATEST_NOT_ROHIT','latest_notification_rohit');
function latest_notification_rohit()
{
    include("shortcode.php");
}

in shortcode.php file the code is as follow :

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

but when I am running this code in wordpress page/post then the content is displayed two times. The demo is at the front end

http://singhalrohitashv.com/latest-notification/

How can I resolve this problem ???

  • 写回答

3条回答 默认 最新

  • dongli7870 2017-04-03 11:15
    关注

    You are probably calling the latest_notification_rohit() function on one of the following files :

    • Header.php for the page
    • Page template file

    You might also be calling the content function twice for that page. Doing a search all for the_content() or latest_notification_rohit() might show you the places where the code is being called multiple times.

    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路