飞龙博客

feilong.org

define global varations wordpress theme php (607)

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

2010-11-04 ~ 2010-11-04

加入收藏夹,查看更方便。

分类: wordpress

新作:

旧文:

以下是广告