2013-08-16 79 views
0

我嘗試了幾種解決方案,從網站中查看類似的問題,但它不起作用。 =(請幫助不能讓php在短代碼內容中工作

這是我原來的代碼的摘錄:

<form action="" method="get"> 
<input type="text" name="search" value=""> 
<input type="submit" value="Search"> 
<?php echo do_shortcode('[expand] 
<input type="checkbox" name="title" <?php if(isset($_GET['title'])) echo "checked='checked'"; ?>> 
    <label for="ti">Title</label></td> 
[/expand]'); ?> 
</form> 

基本上,我希望我的複選框保持選中狀態,如果他們點擊提交不幸的是,它一直小時,我前檢查。不能讓PHP的簡碼內工作。

請幫助。

+0

你需要你的時候它是有一次,在你的do_shortcode FUNC再次打開<?PHP的? –

回答

0

你可以試試這個,

<form action="" method="GET"> 
    <input type="text" name="search" value=""> 
    <input type="submit" value="Search"> 
    <?php 
    $check=isset($_GET['title']) ? "checked='checked'" : ''; 
    echo do_shortcode('[expand] 
    <input type="checkbox" name="title" '.$check.' ><label for="ti">Title</label></td> 
    <input type="submit" value="Search"> 
    [/expand]'); 
    ?> 
</form> 
+0

完美的工作,謝謝! –

0

不,你不能。在字符串中的PHP代碼是沒有的PHP代碼。你必須檢測部件是實際上是PHP,並對它們進行評估。

在將其傳遞給do_shortcode()函數之前,將要嵌入的字符串創建爲[expand]標記。

0

而不是> 標題 [/ expand]'); ?>

根本就

<?php 
$state = isset($_GET['title'])?"checked='checked'":""; 
$expand = "[expand] 
<input type=\"checkbox\" name=\"title\" ".$state. " >"; 
echo do_shortcode($expand);?>