2015-06-29 18 views
-1

我的WordPress的網站工作正常。我沒有改變任何東西,但今天早上它只是顯示一個錯誤,我不知道爲什麼它顯示這樣以及如何解決。這些錯誤我得到:WordPress的生成未定義的變量:post.php

  1. 注意:未定義的變量:在後/home/afch1ealth1/public_html/wp-content/themes/afc/functions.php線154上

  2. 注意:未定義屬性:stdClass的:: $ POST_DATE在/home/afch1ealth1/public_html/wp-includes/query.php線4582.

而且在function.php線154我已經用下面的代碼:

<?php 

    function excerpt($num) { 

    $limit = $num+1; 
    $excerpt = explode(' ', get_the_excerpt(), $limit); 
    array_pop($excerpt); 
    $excerpt = implode(" ", $excerpt)."<a href='".get_permalink($post->ID)."'class='".readmore."'> [Read More]</a>"; <-------- this is exact 154 line 

    echo $excerpt; 

    } 
    ?> 

雖然我得到這個錯誤,但我的WordPress的工作完美。

爲了您的理解,我在此附上圖片。

+0

通知消息是不言自明的。 – Nilambar

+0

我覺得你在功能開始時缺少'global $ post;'。 – pbaldauf

回答

0
<?php 

    function excerpt($num) { 
    global $post; 
    $limit = $num+1; 
    $excerpt = explode(' ', get_the_excerpt(), $limit); 
    array_pop($excerpt); 
    $excerpt = implode(" ", $excerpt)."<a href='".get_permalink($post->ID)."'class='readmore'> [Read More]</a>"; <-------- this is exact 154 line 

    echo $excerpt; 

    } 
    ?> 
+0

感謝您的回覆,它解決了我的問題,但現在顯示一個新的錯誤:注意:使用未定義的常量readmore - 在/home/afch1ealth1/public_html/wp-content/themes/afc/functions.php中使用'readmore'在線152和我的確切的152無代碼是$摘錄= implode(「」,$摘錄)。「 [Read More]」; – Nazmul

+0

檢查,我編輯了代碼。 – sarath

0

注意:未定義的變量:在後/home/afch1ealth1/public_html/wp-content/themes/afc/functions.php線154上

在PHP 注意:是叫你在你的功能小問題

這個問題是你申報變量時解決$ post ='';

公告:未定義的屬性:在/home/afch1ealth1/public_html/wp-includes/query.php stdClass的:: $ POST_DATE上線4582.

這個問題解決了,而你是query.php上線4582.

isset($變量)