WordPress主题制作中自定义头部的相关PHP函数解析
《:WordPress主题制作中自定义头部的相关PHP函数解析》要点: PHP应用header_image() PHP利用【Display header image path.】 即,显示顶部图像地址.
代码如下:
PHP利用<img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="" /> 函数声明源代码
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 自定义顶部 请注意,依据本文折腾你的主题时,请确保你的 WordPress 已经升级到 3.4版本. get_custom_header 意义详解 PHP利用函数使用实例 //判断是否存在该函数,以便兼容老版本 if ( function_exists( 'get_custom_header' ) ) { //get_custom_header()->width 挪用带向 width 属性 $header_image_width = get_custom_header()->width; //get_custom_header()->height 挪用带向 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(//将设置打包成数组 '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' => '',); //将数组中的设置添加到自界说顶部上 add_theme_support( 'custom-header',$headarg ); 自界说顶部图像 //打开主题自界说顶部支持 add_theme_support( 'custom-header' ); $headarg = array(//将设置打包成数组 'default-image' => '',$headarg ); 自适应顶部图像设置 $args = array( 'flex-width' => true,//自适应高度 'width' => 980,'flex-width' => true,//自适应宽度 'height' => 200,'default-image' => get_template_directory_uri() . '/images/header.jpg',); add_theme_support( 'custom-header',$args ); 自定义顶部图像的挪用 PHP利用
<img
src="<?php header_image(); ?>"
height="<?php echo get_custom_header()->height; ?>"
width="<?php echo get_custom_header()->width; ?>"
alt=""
/>
《:WordPress主题制作中自定义头部的相关PHP函数解析》是否对您有启发,欢迎查看更多与《:WordPress主题制作中自定义头部的相关PHP函数解析》相关教程,学精学透。编程之家 52php.cn为您提供精彩教程。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |