自定義頂部圖像功能 - 下劃線主題代碼片段

    Wordpress 頂部圖像自定義調用

    該功能的Wordpress 函數為:

    add_theme_support()

    自定義頂部圖像功能 - 下劃線主題代碼片段-Npcink
    自定義頂部圖像功能 - 下劃線主題代碼片段-Npcink

    add_theme_support() - wordpress主題自定義頂部圖像功能

    Xitou 主題由以下程序構建:

    自定義頂部圖像功能 - 下劃線主題代碼片段-Npcink
    自定義頂部圖像功能 - 下劃線主題代碼片段-Npcink

    _s - WordPress 主題開發板子

    文件位于:

    /inc/custom-header.php

    代碼為(Xitou 為我的主題名):

    <?php
    /**
     * Sample implementation of the Custom Header feature
     * 自定義標頭功能的示例實現
     *
     * 
     *
     * You can add an optional custom header image to header.php like so ...
     * 您可以添加一個可選的自定義標題圖像到標題. php 喜歡這樣..。
     *
    ????<?php the_header_image_tag(); ?>
     *
     * @link https://developer.wordpress.org/themes/functionality/custom-headers/
     *
     * @package xitou
     */
    
    
    /**
     * Set up the WordPress core custom header feature.
     * 設置 WordPress 核心自定義標頭功能。
     *
     * @uses xitou_header_style()
     */
    function xitou_custom_header_setup() {
    ????add_theme_support( 'custom-header', apply_filters( 'xitou_custom_header_args', array(
    ????????'default-image'          => '',
    ????????'default-text-color'     => '000000',
    ????????'width'                  => 1000,
    ????????'height'                 => 250,
    ????????'flex-height'            => true,
    ????????'wp-head-callback'       => 'xitou_header_style',
    ????) ) );
    }
    add_action( 'after_setup_theme', 'xitou_custom_header_setup' );
    
    
    if ( ! function_exists( 'xitou_header_style' ) ) :
    ????/**
    ???? * Styles the header image and text displayed on the blog.
    ???? * 設置標題圖像和博客上顯示的文本的樣式。
    ???? *
    ???? * @see xitou_custom_header_setup().
    ???? */
    ????function xitou_header_style() {
    ????????$header_text_color = get_header_textcolor();
    
    
    ????????/*
    ???????? * If no custom options for text are set, let's bail.
    ???????? * 如果沒有設置文本的自定義選項, 讓我們保釋。
    ???????? * get_header_textcolor() options: Any hex value, 'blank' to hide text. Default: add_theme_support( 'custom-header' ).
    ???????? */
    ????????if ( get_theme_support( 'custom-header', 'default-text-color' ) === $header_text_color ) {
    ????????????return;
    ????????}
    
    
    ????????// If we get this far, we have custom styles. Let's do this.
    ????????//如果我們走了這么遠, 我們就有了自定義樣式。讓我們這樣做。
    ?????????>
    ????????<style type="text/css">
    ????????<?php
    ????????// Has the text been hidden?
    ????????if ( ! display_header_text() ) :
    ?????????????>
    ????????????.site-title,
    ????????????.site-description {
    ????????????????position: absolute;
    ????????????????clip: rect(1px, 1px, 1px, 1px);
    ????????????}
    ????????<?php
    ????????// If the user has set a custom color for the text use that.
    ????????else :
    ?????????????>
    ????????????.site-title a,
    ????????????.site-description {
    ????????????????color: #<?php echo esc_attr( $header_text_color ); ?>;
    ????????????}
    ????????<?php endif; ?>
    ????????</style>
    ????????<?php
    ????}
    endif;
    

    調用該圖片的方法為:

    <img src="<?php header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />
    具體內容見 add_theme_support() 函數介紹。

    具體功能如下圖:

    自定義頂部圖像功能 - 下劃線主題代碼片段

    點擊后進入自定義頁面

    自定義頂部圖像功能 - 下劃線主題代碼片段

    該功能與Wordpress 2017 主題類似,可以裁剪。

    以下內容可參考:

    WordPress 2017主題中,該功能的調用代碼在 header.php 的32行:

    <?php get_template_part( 'template-parts/header/header', 'image' ); ?>
    

    此代碼調用 /template-parts/header/header-image.php 中的代碼(15行):

    <?php the_custom_header_markup(); ?>
    
    

    the_custom_header_markup() 的作用是:打印自定義標題的標記。

    官方文檔:https://developer.wordpress.org/reference/functions/the_custom_header_markup/

    就是這一段代碼輸出類似這樣的html 代碼:

    <div id="wp-custom-header" class="wp-custom-header"><img src="https://baimu.org/wp-content/themes/twentyseventeen/assets/images/header.jpg" width="2000" height="1200" alt="百牧" /></div> </div>

    而類似上面提到的功能代碼在 /inc/custom-header.php 文件中的第36行,部分代碼如下:

    add_theme_support(
    ????????'custom-header',
    ????????apply_filters(
    ????????????'twentyseventeen_custom_header_args',
    ????????????array(
    ????????????????'default-image'    => get_parent_theme_file_uri( '/assets/images/header.jpg' ),
    ????????????????'width'            => 2000,
    ????????????????'height'           => 1200,
    ????????????????'flex-height'      => true,
    ????????????????'video'            => true,
    ????????????????'wp-head-callback' => 'twentyseventeen_header_style',
    ????????????)
    ????????)
    ????);
    

    我還是沒弄懂。

    維護頁倒計時單頁 - html單頁

    2020-5-28 23:15:09

    國外主題

    Baque - 多用途一頁wordpress創意主題

    2020-3-15 7:40:52

    ??
    Npcink上的部份代碼及教程來源于互聯網,僅供網友學習交流,若您喜歡本文可附上原文鏈接隨意轉載。
    無意侵害您的權益,請發送郵件至 1355471563#qq.com 或點擊右側 私信:Muze 反饋,我們將盡快處理。
    0 條回復 A文章作者 M管理員
      暫無討論,說說你的看法吧
    ?
    個人中心
    購物車
    優惠劵
    今日簽到
    有新私信 私信列表
    搜索
    主站蜘蛛池模板: 国产91久久精品一区二区| 精品国产一区二区三区在线| 中文国产成人精品久久一区| 亚洲熟妇av一区| 相泽南亚洲一区二区在线播放 | 国产欧美色一区二区三区| 熟妇人妻一区二区三区四区| 国产一区二区在线观看视频| 91精品一区二区三区在线观看| 伊人色综合一区二区三区| 久久国产三级无码一区二区| 日本一区免费电影| 日韩精品一区在线| 精品国产一区二区三区香蕉事| 中文字幕无码不卡一区二区三区| 亚洲美女视频一区| 3d动漫精品啪啪一区二区中文| 中文字幕一区二区三匹| 日韩人妻精品无码一区二区三区 | 人妻av无码一区二区三区| 国产午夜毛片一区二区三区| 国产成人久久精品麻豆一区| 亚洲国产综合无码一区二区二三区| 国产一区二区在线观看视频| 视频在线一区二区| 成人精品视频一区二区| 天堂成人一区二区三区| 在线日韩麻豆一区| 国产不卡视频一区二区三区| 久久久久国产一区二区| 日韩免费视频一区二区| 人妻体内射精一区二区三区| 日韩最新视频一区二区三| 天堂一区二区三区精品| 日韩精品免费一区二区三区| 丰满岳妇乱一区二区三区| 精品国产一区二区三区四区| 成人区人妻精品一区二区三区| 精品女同一区二区三区免费播放| 乱中年女人伦av一区二区| 亚洲成AV人片一区二区|