繁体   English   中英

为什么某些Wordpress主题没有标题图像部分

[英]Why some of Wordpress theme doesn't have Header Image Section

我是Wordpress的新手。 我想知道。 为什么某些Wordpress主题在主题自定义中没有标题图像部分? 如何将此部分添加到主题定制器? 有什么办法吗

在此处输入图片说明

还有一个问题。 如何在主题定制器中修改上传文件图像? 我想添加更多字段并更改作物大小

在此处输入图片说明

这取决于WordPress主题开发人员如何设计和开发主题,但是您可以通过在定制工具区域中添加您自己的选项(例如(图像,文本区域,输入)字段)来实现。

这是在function.php文件中添加此代码的示例

// Header Logo
    function add_logo_customizer($wp_customize) {
    $wp_customize->add_section(
            'logo_image',
            array(
                'title' => 'Logo Image',
                'priority' => 45,
            )
        );
        $wp_customize->add_setting( 'Logo-upload' );
        $wp_customize->add_control(
            new WP_Customize_Image_Control(
                $wp_customize,
                'lp-image_selector',
                array(
                    'label' => 'Logo Image',
                    'section' => 'logo_image',
                    'settings' => 'Logo-upload'
                )
            )
        );
    }
    add_action('customize_register', 'add_logo_customizer');

您可以将其称为<?php echo get_theme_mod( 'Logo-upload' ); ?> <?php echo get_theme_mod( 'Logo-upload' ); ?>

上面的代码已经过测试,可以正常工作

在此处输入图片说明

首先,您需要为自定义标题添加支持。

参见编解码器: https : //developer.wordpress.org/themes/functionality/custom-headers/

显然,您需要使用该代码创建一个php文件,并将其包含在functions.php中,或将代码直接添加到您的functions.php文件中。

    function themename_custom_header_setup() {
    $defaults = array(
        // Default Header Image to display
        'default-image'         => get_template_directory_uri() . '/images/headers/default.jpg',
        // Display the header text along with the image
        'header-text'           => false,
        // Header text color default
        'default-text-color'        => '000',
        // Header image width (in pixels)
        'width'             => 1000,
        // Header image height (in pixels)
        'height'            => 198,
        // Header image random rotation default
        'random-default'        => false,
        // Enable upload of image file in admin 
        'uploads'       => false,
        // function to be called in theme head section
        'wp-head-callback'      => 'wphead_cb',
        //  function to be called in preview page head section
        'admin-head-callback'       => 'adminhead_cb',
        // function to produce preview markup in the admin screen
        'admin-preview-callback'    => 'adminpreview_cb',
        );
}
add_action( 'after_setup_theme', 'themename_custom_header_setup' );

然后在您的header.php上获取图像并将其放在您想要的位置。

<?php if ( get_header_image() ) : ?>
<div id="site-header">
    <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
        <img src="<?php header_image(); ?>" width="<?php echo absint( get_custom_header()->width ); ?>" height="<?php echo absint( get_custom_header()->height ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>">
    </a>
</div>

* functions.php位于主题文件夹的根目录下,如果主题使用“子主题”,请使用此文件夹进行更改。

回答您的问题,当您上传图像时,可以裁剪图像并调整其大小。 WordPress无法以编辑器的形式编辑照片,只能调整大小和裁剪。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM