我正在尝试在调用函数时回显表单。我的代码如下:
function add_post(){
....
echo '<form method="post" action="">
<input type="text" name="post_title" size="45" id="input-title"/>
<textarea rows="5" name="post_content" cols="66" id="text-desc"></textarea>'
.wp_dropdown_categories().'
<input type="hidden" name="new_post" value="1"/>
<input class="subput round" type="submit" name="submit" value="Post"/>
</form>
';
}
但wp_dropdown_categories()
显示两次。这是HTML输出:
<div class="entry-content">
<!-- this should not be displayed -->
<select class="postform" id="cat" name="cat">
<option value="9" class="level-0">Entertainment</option>
</select>
<!-- form starts here -->
<form action="" method="post">
<input type="text" id="input-title" size="45" name="post_title">
<textarea id="text-desc" cols="66" name="post_content" rows="5"></textarea>
<select class="postform" id="cat" name="cat">
<option value="9" class="level-0">Entertainment</option>
</select>
<input type="hidden" value="1" name="new_post">
<input type="submit" value="Post" name="submit" class="subput round">
</form>
</div>
任何想法为什么wp_dropdown_categories()
被调用两次?
答案 0 :(得分:1)
默认情况下,wp_dropdown_categories()
echo
是结果。所以你应该按照以下方式破解你的代码:
echo '<form method="post" action="">
<input type="text" name="post_title" size="45" id="input-title"/>
<textarea rows="5" name="post_content" cols="66" id="text-desc"></textarea>
';
wp_dropdown_categories();
echo '<input type="hidden" name="new_post" value="1"/>
<input class="subput round" type="submit" name="submit" value="Post"/>
</form>
';
或将echo
变量传递给函数为零:
echo '<form method="post" action="">
<input type="text" name="post_title" size="45" id="input-title"/>
<textarea rows="5" name="post_content" cols="66" id="text-desc"></textarea>'
.wp_dropdown_categories('echo=0')).'
<input type="hidden" name="new_post" value="1"/>
<input class="subput round" type="submit" name="submit" value="Post"/>
</form>
';
答案 1 :(得分:0)
试试这个...... 请参阅此函数的文档wp_dropdown_categories()
function add_post(){
....
echo '<form method="post" action="">
<input type="text" name="post_title" size="45" id="input-title"/>
<textarea rows="5" name="post_content" cols="66" id="text-desc"></textarea>'
.wp_dropdown_categories(array('echo'=>0)).'
<input type="hidden" name="new_post" value="1"/>
<input class="subput round" type="submit" name="submit" value="Post"/>
</form>
';
}