将 WordPress 支持的网站中的所有标题转为“大写”案件
所以我需要的是关于如何将 wordpress 支持的网站上的所有标题转换为大写字母的查询或一些提示。
我现在拥有的是这样的:
AAAAA BBBBB CCCCC
我希望它是这样的:
Aaaaa Bbbbb Ccccc
我确实尝试在这里谷歌搜索和搜索,但在该任务中失败了,所以非常感谢任何帮助!
更新:
我需要更新数据库内的标题。只是要明确一点。 :)
So what i need is a query or some tip on how to turn all titles on a wordpress powered website into capitalized case.
What i have now is something like this:
AAAAA BBBBB CCCCC
I want it to be like this:
Aaaaa Bbbbb Ccccc
I did try googling and searching here, but have failed at that task so any help is much appreciated!
UPDATE:
I need to update titles inside the database. Just to be clear. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
MySQL 中没有用于此目的的函数,但您可以创建如下函数:
From 这里。
您可以通过运行轻松更新:
There is no function in MySQL for this, but you can create one like this:
From here.
The you can update easily by running:
您可以将其按原样保留在数据库中,并通过 css 强制标题以大写字母显示:
You could leave it as-is in the database and force the title to display with first-letters in capitals via css:
只需单独使用 ucwords( $title ) - 但要仔细检查您的用例 - 首字母缩略词最终不会像您的用户期望的那样显示。
“TLAs 初学者指南”将变为“TLA 初学者指南”
Just use ucwords( $title ) on their own - but check your use cases very carefully - acronyms do not end up displaying as your users might expect.
"beginners guide to TLAs" will become "Beginners Guide To Tlas"
您可以尝试使用 ucwords 和 strtolower
据我所知,这需要标题值使用 strtolower 将其转换为小写,然后使用 ucwords 将每个单词大写。
我自己没有尝试过,所以我不知道它是否有效,但这就是我尝试的方法。
希望这有助于
编辑:对,我查看了我的一个旧文件,在你的functions.php中,你可以定义一个函数来挂钩save_post操作。使用 post 变量,您应该能够调整该数据,但就像其他人所说的那样,您必须小心,以防它不会产生所需的效果。
我正在使用 update_post_meta() 函数,我不完全确定这是否有能够编辑标题,不幸的是我无法运行测试。
你们觉得怎么样?
could you try wrapping wordpresses the_title(); function with ucwords and strtolower
From what i can gather this takes the title value uses strtolower to turn it into lowercase, then ucwords to capitalize each word.
I haven't tried this myself so i don't know it it works but this is how i would try it.
Hope this helps
EDIT: right i've had a look at one of my old files, in your functions.php you could define a function to hook into the save_post action. Using the post variable you should be able to adjust that data, but like others have said you have to be careful incase it doesnt produce the desired effect.
I'm using the update_post_meta() function, i'm not entirely sure if this has the ability to edit the title, i don't have to ability to run a test unfortunately.
What do you guys think?
根据记录,当最后一个字符单独存在时,上面引用的 MySQL 函数会失败,例如,
如果不需要填充,有一个简单的解决方法:
For the record, the MySQL function quoted above fails when the last character stands alone, e.g.,
There's an easy workaround, if you don't need padding: