2011-03-18 37 views
1

誰能幫助我與PHP腳本,我很新的PHP和具有使這個代碼的麻煩工作幫助用PHP爲WordPress

$current = $post->ID; 
    $parent = $post->post_parent; 
    $grandparent_get = get_post($parent); 
    $grandparent = $grandparent_get->post_parent; 
    if ($root_parent = get_the_title($grandparent) !== $root_parent = get_the_title($current)) {echo ' <a href="get_permalink($grandparent)">get_the_title($grandparent)</a>';}else {echo '<a href="get_permalink($parent)">get_the_title($parent)</a>';} 

從「如果不工作我猜的最後一位有一些語法問題

非常感謝,如果它們與單引號引用

+0

有什麼語法錯誤? – 2011-03-18 11:17:17

+0

不,但我的輸出是get_the_title($ parent),它應該是封裝在href中的頁面的標題 – jmysona 2011-03-18 11:19:52

+0

如果您打算對WP代碼進行更多編輯,那麼我會建議閱讀一些PHP基礎知識。 – Dunhamzzz 2011-03-18 11:28:45

回答

1

變量不解析。

有許多方法來分析他們,但我張貼他們中的一個嘗試下面的代碼

echo " <a href=\"get_permalink($grandparent)\">get_the_title($grandparent)</a>";} 
else {echo "<a href=\"get_permalink($parent)\">get_the_title($parent)</a>";} 

OR

echo '<a href="'.get_permalink($grandparent).'">'.get_the_title($grandparent).'</a>';} 
else {echo '<a href="'.get_permalink($parent).'">'.get_the_title($parent).'</a>';} 
+0

<?php $ current = $ post-> ID; $ parent = $ post-> post_parent; $ grandparent_get = get_post($ parent); $ grandparent = $ grandparent_get-> post_parent; 如果($ root_parent = get_the_title($祖父母)== $ root_parent = get_the_title($電流)!){回聲 ''.get_the_title($grandparent).' ';}其他{回聲' '.get_the_title($parent).'';} \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t?> 這就是我現在出於某種原因,它打破了網頁,遺憾的是疼痛 – jmysona 2011-03-18 11:42:33

+0

完善它的工作非常感謝 – jmysona 2011-03-18 12:19:08

+0

@jmysona:如果通過點擊除答案之外的右箭頭幫助接受答案 – 2011-03-18 12:21:34