博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
城市简码_创建WordPress简码
阅读量:2511 次
发布时间:2019-05-11

本文共 2135 字,大约阅读时间需要 7 分钟。

城市简码

WordPress are super handy, especially when handing off a WordPress-based website to a client. The alternative to using shortcodes is creating complicated templates, and even then, you cannot adequately replace what shortcodes can do. I recently needed to implement a new shortcode for the Mozilla Hacks blog and was happy to learn how simple the WordPress API makes creating new shortcodes! Let me show you how to create your own WordPress shortcodes!

WordPress 非常方便,尤其是在将基于WordPress的网站移交给客户端时。 使用简码的替代方法是创建复杂的模板,即使那样,您也无法充分替换简码可以做什么。 我最近需要为Mozilla Hacks博客实现新的简码,并很高兴了解WordPress API如何使创建新的简码变得如此简单! 让我向您展示如何创建自己的WordPress短代码!

First you start by creating a function within your theme's functions.php file. The function should return a string which replaces the shortcode within the rendered content. Your function can accept an $args argument which is a key=>value array of parameters passed in.

首先,您需要在主题的functions.php文件中创建一个函数。 该函数应返回一个字符串,该字符串将替换呈现内容中的短代码。 您的函数可以接受$args参数,该参数是传入的参数的key=>value数组。

function my_shortcode_routine($args) {	// $args = array('key1' => 'value1', 'key2' => 'value2')	$return = '';	// a bunch of logic and string-building here	// return the result	return $return;}

Remember that your function shouldn't echo; a string must be returned.

记住你的函数不应echo ; 必须返回一个字符串。

After your function has been created, you can use WordPress' add_shortcode function to register the shortcode. The shortcode name function name doesn't need to match the shortcode:

创建函数后,您可以使用WordPress的add_shortcode函数注册该短代码。 简码名称函数名称不需要与简码匹配:

// Add a shortcode called 'shortcode_name' that runs the 'my_shortcode_routine' functionadd_shortcode('shortcode_name', 'my_shortcode_routine');

With the function created and the shortcode registered, now you can use said shortcode within your posts and pages:

创建函数并注册简码后,现在您可以在帖子和页面中使用所述简码了:

[shortcode_name key1="value1" key2="value2"]

The shortcode system is positively beautiful; it's of large value to both seasoned devs and trained clients, and a prime example of why WordPress is deep and flexible platform.

简码系统非常漂亮; 对于经验丰富的开发人员和训练有素的客户而言,它都具有巨大的价值,并且是WordPress为什么是深度而又灵活的平台的典型示例。

翻译自:

城市简码

转载地址:http://krswd.baihongyu.com/

你可能感兴趣的文章
Linux 如何写makefile文件
查看>>
flutter_webview_plugin 无法加载网页的异常处理
查看>>
bloc控制读写文件
查看>>
微信小程序
查看>>
洛谷 P1059 明明的随机数
查看>>
window自动任务实现数据库定时备份
查看>>
Windows 7 Ultimate(旗舰版)SP1 32/64位官方原版下载(2011年5月12日更新版)
查看>>
javascript操作cookie
查看>>
深入理解HTTP协议(转)
查看>>
NHibernate讲解
查看>>
客户端—表单验证信息—并能否提交到数据库
查看>>
Android开发环境搭建(原创)
查看>>
java IO流 对文件操作的代码集合
查看>>
js / jquery 获取和设置 FCK Editor 的值
查看>>
sql-leetcode Consecutive Numbers
查看>>
C# winform DataGridView操作 (转)
查看>>
一致性Hash算法及使用场景
查看>>
JS - Lexical Structure
查看>>
【2】oracle创建表空间
查看>>
剑指offer-二叉树中和为某一值的路径
查看>>