简体   繁体   English

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

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

I am new in Wordpress. 我是Wordpress的新手。 I want to know. 我想知道。 Why some of the Wordpress themes don't have header image section in Theme customize? 为什么某些Wordpress主题在主题自定义中没有标题图像部分? How to add this section to the theme customizer? 如何将此部分添加到主题定制器? Is there any way to do it 有什么办法吗

在此处输入图片说明

And one question. 还有一个问题。 How can I modify the upload file image in the theme customizer? 如何在主题定制器中修改上传文件图像? I want to add more field and change the crop size 我想添加更多字段并更改作物大小

在此处输入图片说明

this depends on the WordPress theme developer how they design and develop themes but you can achieve this by adding your own option like (image, textarea , input) fields in the customizer area. 这取决于WordPress主题开发人员如何设计和开发主题,但是您可以通过在定制工具区域中添加您自己的选项(例如(图像,文本区域,输入)字段)来实现。

Here is the example add this code in a function.php file 这是在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');

and you can call it as <?php echo get_theme_mod( 'Logo-upload' ); ?> 您可以将其称为<?php echo get_theme_mod( 'Logo-upload' ); ?> <?php echo get_theme_mod( 'Logo-upload' ); ?>

The above code is tested and it works 上面的代码已经过测试,可以正常工作

在此处输入图片说明

For the first you need to add support to custom-header. 首先,您需要为自定义标题添加支持。

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

Obviously, you need to create a php file with the code and include in the functions.php or add the code directly to your functions.php file. 显然,您需要使用该代码创建一个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' );

Then on your header.php get the image and put in where you want it. 然后在您的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 is on the root of your theme folder, if your theme uses a "child-theme" please use this folder to do the changes. * functions.php位于主题文件夹的根目录下,如果主题使用“子主题”,请使用此文件夹进行更改。

And answering your question, when you upload the image you can crop and resize the image. 回答您的问题,当您上传图像时,可以裁剪图像并调整其大小。 Wordpress cannot edit photos as an editor, only resize and crop. WordPress无法以编辑器的形式编辑照片,只能调整大小和裁剪。

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

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