将文本区域添加到 wordpress options-general.php
我不确切知道如何定义我的问题,我正在处理我的自定义 WordPress 主题,并且我在 Wordpress 管理的常规设置中添加了自定义输入字段,方法是编辑 generic.php 并在常规列表中添加一个新数组,然后我在 options-general.php 中创建了一个新的 tablerow:
<tr valign="top">
<th scope="row"><label for="siteupdates"><?php _e('Site Updates') ?></label></th>
<td><input name="siteupdates" type="text" id="content"
"value="<?php form_option('siteupdates'); ?>" class="regular-text" ></>
<span class="description"><?php _e('Site news,updates,etc.') ?></span></td>
</tr>
并在 header.php 中添加了一个 div,我希望它显示在其中:
<div id="siteInfo">
<?php form_option('siteupdates'); ?>
</div><!--siteInfo end-->
然后我在 phpmyadmin 的 wordpress 数据库中添加了新的查询('siteupdates'),一切都很好,因为我很新php,我看了很多教程,发现这种方式对我来说是最简单的。 现在我想将此输入更改为文本区域字段,但是当我将 html 更改为:
<tr valign="top">
<th scope="row"><label for="siteupdates"><?php _e('Site updates') ?></label></th>
<td><textarea name="siteupdates" type="text" id="content"
cols="50" rows="6" value="<?php form_option('siteupdates'); ?>" class="regular-text">
</textarea>
<span class="description"><?php _e('Site news,updates,etc.') ?></span></td>
</tr>
它看起来不错,我看到文本字段而不是输入,但我无法在其中存储数据。我哪里错了?
I don't know exactly how to define my question, im working on my custom Wordpress theme, and I've added custom input field in General Settings in Wordpress admin, by editing general.php and adding a new array in general list, then i created a new tablerow in options-general.php:
<tr valign="top">
<th scope="row"><label for="siteupdates"><?php _e('Site Updates') ?></label></th>
<td><input name="siteupdates" type="text" id="content"
"value="<?php form_option('siteupdates'); ?>" class="regular-text" ></>
<span class="description"><?php _e('Site news,updates,etc.') ?></span></td>
</tr>
and also added a div in header.php where i wanted it to be shown:
<div id="siteInfo">
<?php form_option('siteupdates'); ?>
</div><!--siteInfo end-->
then i added new Query in wordpress database in phpmyadmin ('siteupdates') and everything works great,since im very new in php, i have watched lots of tutorials and found that way was the easiest for me.
Now i want to change this input to a textarea field, but when i changed html to:
<tr valign="top">
<th scope="row"><label for="siteupdates"><?php _e('Site updates') ?></label></th>
<td><textarea name="siteupdates" type="text" id="content"
cols="50" rows="6" value="<?php form_option('siteupdates'); ?>" class="regular-text">
</textarea>
<span class="description"><?php _e('Site news,updates,etc.') ?></span></td>
</tr>
Its looks fine, i see textfield instead of input, but i cant store data in it. Where am i wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我只是做了你所做的,我在 options-general.php 中插入了相同的代码来添加一个新字段,并在“选项”表上创建了一条新记录。
当我进行常规调整时,我会看到新字段,其中包含我之前插入新记录中的值。但是当我尝试更新它时什么也没有发生。
但我发现了 options.php 如果你从浏览器访问它,你可以找到所有的调整,有趣的一点是,如果我尝试更新新记录的值,它确实如此!
这个方法真的很简单,因为正确的方法,创建一个插件等等,它需要很多时间而且更复杂。
如果这个解决方案是为了我自己,我会这样做,但如果是为了其他人,可能会很粗糙,因为他必须在每个新版本的 WordPress 出现时修改代码。
I just did exactly what you did, i inserted the same code in options-general.php to ad a new field and i created a new record on "options" table.
When i go through General Adjustmenst i see the new field with the value that i early inserted on the new record. But when i try to update it nothing happens.
But i found the options.php if you accces it from browser, you can find all the adjustmets, the interesting point, is if i try to update the value of the new record, it does!!!
This method is really simple, because the right way, create a plugin and so on, its take to much time and more complicated.
If this solution if for myself, ill do it, but if is for someone else, could be rought cause he has to modify the code every new version of wordpress comes out.
有几件事:
a) 考虑创建您自己的管理菜单。 更多信息
b) 您不应使用自定义数据库查询来存储选项,而应使用
add_option
c) 您的文本区域有一个
type="text"
,它是't需要。d) 如果您要在其中添加内容,则应该查看
wp_editor
< /a> 这是 WP 3.3 中的新功能A few things :
a) Look into creating your own Administrative menus. More information here
b) Instead of storing your options with custom db queries, you should use
add_option
c) Your textarea has a
type="text"
which isn't needed.d) If you are going to have content in there, you should look into
wp_editor
It's new in WP 3.3更改您的
基本上摆脱 value 属性并使用 textarea 标记内的内容。
Change your <textarea> into this one:
Bascially get rid of the value attribute and use the content inside the textarea tag.