2014-03-27 102 views
-1

我有工作的php代碼,我已經添加到我的WordPress主題functions.php文件。如何添加一個div元素到一個php函數

一切都很好。我所要做的就是添加一個div類以便能夠輸出樣式。

我不知道如何做到這一點,任何意見非常感謝。我嘗試添加

<div class="custom"> echo get_option  ('woo_customtext'</div>); 

但是,該網站返回頁面錯誤。我加入了完整的代碼如下:

add_action('woo_post_inside_before',  'woo_add_custom'); 

function woo_add_custom() { 

if (is_single()){ 
echo get_option ('woo_customtext'); 
} 
} 
+0

'

echo get_option ('woo_customtext'
);'是非常有效的語法。 –

+0

發佈錯誤可能會有用。 你似乎也沒有正確迴應。 標籤在哪裏? – Dynelight

+0

這是一團糟。這是在Wordpress中完成的嗎? – gtr1971

回答

0

使用

if (is_single()) { 
    echo '<div class="custom">'.get_option('woo_customtext').'</div>'; 
} 

或者

if (is_single()) { 
    ?> 
<div class="single"><?php echo get_option('woo_customtext'); ?></div> 
    <?php 
} 

要與PHP搭配HTML,你需要或者打印作爲一個字符串(因此第一個示例中的'引號)或在寫入HTML之前退出PHP(因此第二個中爲?><?php)。

+0

米勒,感謝您的支持和建議。 echo'

'.get_option('woo_customtext').'
';完美地工作。我可以看到你現在將它打印成字符串的意思。再次感謝你 ! – user3466488

相關問題