飞龙博客

feilong.org 前端开发教程

define global varations wordpress theme php

飞龙修订于 20101104 03:58 47 次浏览

When custom wordpress theme,feilong wants to repeatly use some values, such as the category id on category.php,the first category id or all category ids on single.php.If you do not want to use custom post type, instead,you should often use a post's top category id or slug to determine "the type of a post".

To avoid duplicate definition of these basic values,feilong would like adopt a function to define these common or public variables in functions.php first. But how to customize functions to define global variables in a wordpress theme? Feilong test here: http://feilong.org/wordpress-define-global-var-en edited on 2010-11-02. I hope it useful for you,my friends.

One, usage of '&'


Two, usage of valuable


Three, valuable and function


Four, dominate valuable


Five, globals
including Super globals,which are built-in variables that are always available in all scopes

1, Super globals
$GLOBALS — References all variables available in global scope
$_SERVER — Server and execution environment information
$_GET — HTTP GET variables
$_POST — HTTP POST variables
$_FILES — HTTP File Upload variables
$_REQUEST — HTTP Request variables
$_SESSION — Session variables
$_ENV — Environment variables
$_COOKIE — HTTP Cookies

2, Other globals
$php_errormsg — The previous error message
$HTTP_RAW_POST_DATA — Raw POST data
$http_response_header — HTTP response headers
$argc — The number of arguments passed to script
$argv — Array of arguments passed to script

Six, use gloabl valuables in wordpress themes

1, In fuctions.php, some testing snippets


2, Then in other template file for example sidebar.php of your wordpress theme,retrieve the global values


Ok,blog() and getblog() just the same cat and dog!Welcome for a better fuction to define common or global varations in php!

网址:https://feilong.org/wordpress-define-global-var-en
初发:20101104 03:58

想学前端?长按二维码加我微信

想学前端?点击飞龙QQ

分类: wordpress

新作:

旧文:

关闭

长按二维码 -> 识别图中二维码

打开微信,发现,扫一扫

支付完成后,点击下一步

感谢大力支持

然后你手机号:

最后点这,稍等即可