因此,我不能完全确定完成这项任务的最佳方式到底是什么。我尝试了一些事情,只是为了看看效果如何,但我不知道我如何完成这项任务是最合适的方式,所以我希望一些比我聪明得多的人能启发我,希望。。。
简而言之,“我是孩子”主题似乎聚合使用函数,以便为主题布局执行不同的代码块。
我需要对其进行一些小修改的代码包含在父主题内的多个函数中,我通过反复试验找到的唯一方法是复制需要从父主题更改的函数,然后通过稍微附加函数名称来重新声明它们。
这很好,但我不知道这是不是一个坏习惯,所以我想与社区再次确认一下,处理这类事情的最佳方式是什么。
所有真正被改变的是Im删除标题中标记的头像。
父主题的原始函数集:
/**
* This function contains large post title markup.
* It is used in \'flexia_post_large_title\' method.
*
* @since v0.0.5
*/
function flexia_post_large_title_markup() {
$thumbnail = \'\';
if (function_exists(\'has_post_thumbnail\')) {
if ( has_post_thumbnail() ) {
$thumbnail = wp_get_attachment_url( get_post_thumbnail_id() );
}
}
?>
<header class="page-header single-blog-header" <?php if ( ! empty( $thumbnail ) ) : ?>
style="background-image: url(\'<?php echo esc_attr($thumbnail); ?>\');" <?php endif; ?> <?php if ( empty( $thumbnail ) ) : ?>
style="background-image: url(\'<?php echo esc_attr(get_header_image()); ?>\');" <?php endif; ?>>
<div class="header-inner">
<div class="header-content">
<?php the_title( \'<h1 class="blog-title">\', \'</h1>\' ); ?>
<?php flexia_post_large_title_author_avatar_markup(); ?>
</div>
</div>
<div class="header-overlay"></div>
</header>
<?php
}
/**
* This function contains large post title author avatar markup.
* It is used in \'flexia_post_large_title_markup\' method.
*
* @since v0.0.5
*/
function flexia_post_large_title_author_avatar_markup() {
if( class_exists( \'CMB2_Bootstrap_230\' ) ) {
global $post;
$post_title_header_meta = get_post_meta( $post->ID, \'_flexia_post_meta_key_header_meta\', true );
$post_title_header_post_author = get_post_meta( $post->ID, \'_flexia_post_meta_key_header_author_meta\', true );
if( $post_title_header_meta == \'yes\' || $post_title_header_meta == NULL ) {
if( $post_title_header_post_author == \'yes\' || $post_title_header_post_author == NULL ) {
?>
<div class="blog-author">
<div class="author-avatar">
<?php echo get_avatar( get_the_author_meta( \'ID\' ), \'flexia-thumbnail-avatar\' ); ?>
<div class="author-body">
<h4 class="author-heading"><?php the_author(); ?></h4>
</div>
</div>
</div>
<?php
}else {
return false;
}
}else {
return false;
}
}else {
?>
<div class="blog-author">
<div class="author-avatar">
<?php echo get_avatar( get_the_author_meta( \'ID\' ), \'flexia-thumbnail-avatar\' ); ?>
<div class="author-body">
<h4 class="author-heading"><?php the_author(); ?></h4>
</div>
</div>
</div>
<?php
}
}
/**
*
*/
function flexia_post_large_title_header_meta_markup() {
?>
<header class="entry-header single-blog-meta single-post-meta-large">
<?php
if ( \'post\' === get_post_type() ) : ?>
<div class="entry-meta">
<?php flexia_updated_on(); ?>
</div><!-- .entry-meta -->
<?php
endif; ?>
</header><!-- .entry-header -->
<?php
}
/**
* This function will show/hide large post title
*
* @since v0.0.5
*/
function flexia_post_large_title() {
$flexia_single_posts_layout = get_theme_mod(\'flexia_single_posts_layout\', \'flexia_single_posts_layout_large\');
if( class_exists( \'CMB2_Bootstrap_230\' ) ) {
global $post;
$post_title = get_post_meta( $post->ID, \'_flexia_post_meta_key_page_title\', true );
$post_title_header_meta = get_post_meta( $post->ID, \'_flexia_post_meta_key_header_meta\', true );
if( $post_title == \'default\' || $post_title == NULL ) {
if( $flexia_single_posts_layout == \'flexia_single_posts_layout_large\' ) {
flexia_post_large_title_markup();
if( $post_title_header_meta == \'yes\' || $post_title_header_meta == NULL ) {
flexia_post_large_title_header_meta_markup();
}
}else {
return false;
}
}elseif( $post_title == \'large\') {
flexia_post_large_title_markup();
if( $post_title_header_meta == \'yes\' || $post_title_header_meta == NULL ) {
flexia_post_large_title_header_meta_markup();
}
}else {
return false;
}
}else {
if( $flexia_single_posts_layout == NULL || $flexia_single_posts_layout == \'flexia_single_posts_layout_large\' ) {
flexia_post_large_title_markup();
flexia_post_large_title_header_meta_markup();
}
}
}
为了对放置在子主题中的标记进行一些简单的更改,我粗略地修改了代码
functions.php
:
(我把我从原来的功能中删除的部分注释掉了,这样你就可以更容易地看到我删除了什么)
// This function contains large post title markup.
// It is used in \'flexia_post_large_title\' method.
function hbps_flexia_post_large_title_markup() {
$thumbnail = \'\';
if (function_exists(\'has_post_thumbnail\')) {
if ( has_post_thumbnail() ) {
$thumbnail = wp_get_attachment_url( get_post_thumbnail_id() );
}
}
?>
<header class="page-header single-blog-header" <?php if ( ! empty( $thumbnail ) ) : ?>
style="background-image: url(\'<?php echo esc_attr($thumbnail); ?>\');" <?php endif; ?> <?php if ( empty( $thumbnail ) ) : ?>
style="background-image: url(\'<?php echo esc_attr(get_header_image()); ?>\');" <?php endif; ?>>
<div class="header-inner">
<div class="header-content">
<?php the_title( \'<h1 class="blog-title">\', \'</h1>\' ); ?>
</div>
</div>
<div class="header-overlay"></div>
</header>
<?php
}
// Change blog header titles by removing Avatar and including By: before Author
// This function contains large post title author avatar markup.
// It is used in \'flexia_post_large_title_markup\' method.
function hbps_flexia_post_large_title_author_avatar_markup() {
if( class_exists( \'CMB2_Bootstrap_230\' ) ) {
global $post;
$post_title_header_meta = get_post_meta( $post->ID, \'_flexia_post_meta_key_header_meta\', true );
$post_title_header_post_author = get_post_meta( $post->ID, \'_flexia_post_meta_key_header_author_meta\', true );
if( $post_title_header_meta == \'yes\' || $post_title_header_meta == NULL ) {
if( $post_title_header_post_author == \'yes\' || $post_title_header_post_author == NULL ) {
?>
<div class="blog-author">
<div class="author-avatar">
<!-- DELETE AVATAR IN HEADER -->
<!-- <?php echo get_avatar( get_the_author_meta( \'ID\' ), \'flexia-thumbnail-avatar\' ); ?> -->
<div class="author-body">
<h4 class="author-heading">By: <?php the_author(); ?></h4>
</div>
</div>
</div>
<?php
}else {
return false;
}
}else {
return false;
}
}else {
?>
<div class="blog-author">
<div class="author-avatar">
<!-- DELETE AVATAR IN HEADER -->
<!-- <?php echo get_avatar( get_the_author_meta( \'ID\' ), \'flexia-thumbnail-avatar\' ); ?> -->
<div class="author-body">
<h4 class="author-heading">By: <?php the_author(); ?></h4>
</div>
</div>
</div>
<?php
}
}
function hbps_flexia_post_large_title_header_meta_markup() {
?>
<header class="entry-header single-blog-meta single-post-meta-large">
<?php
if ( \'post\' === get_post_type() ) : ?>
<div class="entry-meta">
<?php flexia_updated_on(); ?>
</div><!-- .entry-meta -->
<?php
endif; ?>
</header><!-- .entry-header -->
<?php
}
// This function will show/hide large post title
function hbps_flexia_post_large_title() {
$flexia_single_posts_layout = get_theme_mod(\'flexia_single_posts_layout\', \'flexia_single_posts_layout_large\');
if( class_exists( \'CMB2_Bootstrap_230\' ) ) {
global $post;
$post_title = get_post_meta( $post->ID, \'_flexia_post_meta_key_page_title\', true );
$post_title_header_meta = get_post_meta( $post->ID, \'_flexia_post_meta_key_header_meta\', true );
if( $post_title == \'default\' || $post_title == NULL ) {
if( $flexia_single_posts_layout == \'flexia_single_posts_layout_large\' ) {
hbps_flexia_post_large_title_markup();
if( $post_title_header_meta == \'yes\' || $post_title_header_meta == NULL ) {
hbps_flexia_post_large_title_header_meta_markup();
}
}else {
return false;
}
}elseif( $post_title == \'large\') {
hbps_flexia_post_large_title_markup();
if( $post_title_header_meta == \'yes\' || $post_title_header_meta == NULL ) {
hbps_flexia_post_large_title_header_meta_markup();
}
}else {
return false;
}
}else {
if( $flexia_single_posts_layout == NULL || $flexia_single_posts_layout == \'flexia_single_posts_layout_large\' ) {
hbps_flexia_post_large_title_markup();
hbps_flexia_post_large_title_header_meta_markup();
}
}
}