2014-01-06 49 views
0

我只是試圖迴應這個文本與類別標題自動拉到WordPress的文本內。我該怎麼做呢 ?我認爲下面的代碼可以工作,但當我將其作爲短代碼實現時,我得到了php錯誤和空白頁。Simple Php Error Eludes Me

function get_quote($atts) { 
echo '<div id="le_quote">'<?php single_cat_title($prefix = '', $display = true); ?>' is your online supplier of Apache Accessories, Apache Hoses and Apache Pumps. Use our selection to compare Apache models , specs and more. Buy Apache products at the best price possible today.</div>'; 
} 
add_shortcode('random_quote', 'get_quote'); 
+0

*你準確得到了什麼*錯誤? –

+0

PHP語法不正確。 – Raptor

+0

一個空白頁面,如果我刪除''<?php single_cat_title($ prefix ='',$ display = true); '''短代碼將字符串拉好。這個代碼有什麼不對嗎 –

回答

3

試試這個,從<?php single_cat_title($prefix = '', $display = true); ?>刪除<?php?>標籤,並通過$prefix$display參數值。

function get_quote($atts) { 
     echo '<div id="le_quote">'.single_cat_title('', false).' is your online supplier of Apache Accessories, Apache Hoses and Apache Pumps. Use our selection to compare Apache models , specs and more. Buy Apache products at the best price possible today.</div>'; 
    } 
    add_shortcode('random_quote', 'get_quote'); 

編號:

$display: (boolean) (optional) Should the page title be displayed (true) or returned for use in PHP (false). 
Default: true 

網址:http://codex.wordpress.org/Function_Reference/single_cat_title

+0

是的,那個拉貓的名字,但是它的外部div和單獨的一行打破這一段... –

+0

你可以用'single_cat_title('',false)' –

0

你有<?php?>您的迴音裏,更換了。和INT將工作:

function get_quote($atts) { 
    echo '<div id="le_quote">' . single_cat_title('', true) . ' is your online supplier of Apache Accessories, Apache Hoses and Apache Pumps. Use our selection to compare Apache models , specs and more. Buy Apache products at the best price possible today.</div>'; 
} 
add_shortcode('random_quote', 'get_quote'); 
+0

當我這樣做時,該類別被拉好,但它的外部和獨立的線? (http://www.aquapumps.org/product-category/brand/be-pumps/) –

+0

我不確定,但在single_cat_title()中嘗試將true更改爲false。我相信這是用於PHP而不是顯示 –

0

保存貓標題給一個變量,然後回顯。

function get_quote($atts) { 
$cat_title = single_cat_title('', false); 
echo '<div id="le_quote">AquaPumps.Org is your online supplier of '.$cat_title.'  
Accessories, '.$cat_title.' Hoses and '.$single_cat_title.' Pumps. Use our selection 
to compare '.cat_title('', true).' models , specs and more. Buy '.cat_title.' 
products at the best price possible today.</div>'; 
} 
add_shortcode('random_quote', 'get_quote');