飞龙博客

feilong.org

define global varations wordpress theme php

feilong.org 修订于2010-11-04 03:58:56 563 次浏览

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:56 feilong.org 于广州

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

所在分类: wordpress

新作:

旧文:

AI音乐 blog money bui 教程 echarts 教程 eclipse 教程 html css 教程 IT趋势 js 教程 json 教程 mysql 教程 nodejs npm 教程 onblog SQLite 教程 tutorials vscode 教程 wap网站 winpe启动盘 wordpress 主机推荐 人工智能 前端开发 博客 名企名网 域名注册 常用软件 建站程序 操作系统 教程 数码 无线上网 日记 电子商务 电脑笔记本 网站 网站优化 网站开发 网站推广 网站策划 网络 虚拟现实 默认