国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

WordPress主題制作中自定義頭部的相關(guān)PHP函數(shù)解析

2024-05-04 23:42:07
字體:
供稿:網(wǎng)友
這篇文章主要介紹了WordPress主題制作中自定義頭部的相關(guān)PHP函數(shù)解析,包括header_image()函數(shù)和get_custom_header()函數(shù)的用法講解,需要的朋友可以參考下
 

header_image()
header_image() 函數(shù)是 WordPress 自定頂部圖像的標(biāo)準(zhǔn)接口函數(shù),該函數(shù)可以自動判斷后臺設(shè)置,并返回字符串形式的用戶自定義頂部圖像地址。本文主要涉及該函數(shù)的詳解及使用。

【Display header image path.】 即,顯示頂部圖像地址。
使用

 

復(fù)制代碼代碼如下:

 

<img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" style="margin: 0px; padding: 0px; width: 660px; overflow: hidden; clear: both; color: rgb(0, 0, 0); font-family: tahoma, arial, 宋體;"> 函數(shù)聲明源代碼

function header_textcolor() { echo get_header_textcolor();}function get_header_image() { $url = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) );  if ( 'remove-header' == $url ) return false;  if ( is_random_header_image() ) $url = get_random_header_image();  if ( is_ssl() ) $url = str_replace( 'http://', 'https://', $url ); else $url = str_replace( 'https://', 'http://', $url );  return esc_url_raw( $url );}

get_custom_header 自定義頂部
get_custom_header 函數(shù)是 WordPress 3.4 送給我們的新禮物,該函數(shù)的出現(xiàn)是為了更好的集成和封裝頂部的使用,本文主要對 get_custom_header 這個函數(shù)進(jìn)行詳解、以及如何在 WordPress 3.4 版本的主題中集成頂部功能。

請注意,根據(jù)本文折騰你的主題時,請確保你的 WordPress 已經(jīng)升級到 3.4版本。

get_custom_header 意義詳解
自定義頂部目前大部分主題主要用到的還只是兩個功能 1.自定義頂部圖像 2.自定義頂部樣式
具體的效果你可以看一下 默認(rèn)主題 twenty eleven ,或者我的另一個博客 悠悠我心
本函數(shù)是 WP 3.4 版本后才出現(xiàn)的一個內(nèi)置函數(shù),主要用于將用戶設(shè)置的頂部的各項(xiàng)參數(shù)以對象(object)的形式返回。
單單說這么句屁話,也許你還不明白,想要明白的話,請往下看。
請注意本函數(shù)與get_header()有著本質(zhì)的區(qū)別。

函數(shù)使用實(shí)例
下面的例子來自于 默認(rèn)主題 twenty eleven 中 header.php 文件
PHP 代碼:

//判斷是否存在該函數(shù),以便兼容老版本if ( function_exists( 'get_custom_header' ) ) {//get_custom_header()->width 調(diào)用帶向 width 屬性$header_image_width = get_custom_header()->width;//get_custom_header()->height 調(diào)用帶向 height 屬性$header_image_height = get_custom_header()->height;} else {//兼容老版本的代碼$header_image_width = HEADER_IMAGE_WIDTH;$header_image_height = HEADER_IMAGE_HEIGHT;}

綜合使用詳解
以下主要援引官方文檔解釋 自定義頂部

//打開主題自定義頂部支持add_theme_support( 'custom-header' ); $headarg = array(//將設(shè)置打包成數(shù)組 'default-image'     => '', 'random-default'     => false, 'width'         => 0, 'height'         => 0, 'flex-height'      => false, 'flex-width'       => false, 'default-text-color'   => '', 'header-text'      => true, 'uploads'        => true, 'wp-head-callback'    => '', 'admin-head-callback'  => '', 'admin-preview-callback' => '',);//將數(shù)組中的設(shè)置添加到自定義頂部上add_theme_support( 'custom-header', $headarg );

自定義頂部圖像

//打開主題自定義頂部支持add_theme_support( 'custom-header' ); $headarg = array(//將設(shè)置打包成數(shù)組 'default-image'     => '', 'random-default'     => false, 'width'         => 0, 'height'         => 0, 'flex-height'      => false, 'flex-width'       => false, 'default-text-color'   => '', 'header-text'      => true, 'uploads'        => true, 'wp-head-callback'    => '', 'admin-head-callback'  => '', 'admin-preview-callback' => '',);//將數(shù)組中的設(shè)置添加到自定義頂部上add_theme_support( 'custom-header', $headarg );

自適應(yīng)頂部圖像設(shè)置

$args = array( 'flex-width'  => true,//自適應(yīng)高度 'width'     => 980, 'flex-width'  => true,//自適應(yīng)寬度 'height'    => 200, 'default-image' => get_template_directory_uri() . '/images/header.jpg',);add_theme_support( 'custom-header', $args );

自定義頂部圖像的調(diào)用

<img   src="<?php header_image(); ?>"   height="<?php echo get_custom_header()->height; ?>"   width="<?php echo get_custom_header()->width; ?>"   alt="" />
 


注:相關(guān)教程知識閱讀請移步到PHP教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 通海县| 太湖县| 华容县| 平果县| 阜阳市| 汝州市| 准格尔旗| 宜昌市| 青冈县| 腾冲县| 凯里市| 台东县| 建阳市| 南乐县| 炉霍县| 屏南县| 通辽市| 钦州市| 菏泽市| 昌邑市| 肥乡县| 隆子县| 无棣县| 蒲江县| 鄂伦春自治旗| 南部县| 丽水市| 和田市| 保定市| 洮南市| 广饶县| 邛崃市| 从化市| 华阴市| 噶尔县| 枣庄市| 独山县| 宣武区| 凤阳县| 桐柏县| 永泰县|