副标题标题取决于更改为静态后的标题

时间:2016-05-17 作者:Pat

在网站上我有副标题,总是显示最后一篇文章的标题。我想在这个地方有静态标题,如“博客”或“新闻”。

这是副标题的全部代码:

<?php 
    $output = \'\'; 
    $sub_img = array();
    global $post;

    if(!function_exists(\'thmtheme_call_sub_header\')){
        function thmtheme_call_sub_header(){
            global $themeum_options;
            if(isset($themeum_options[\'blog-banner\'][\'url\'])){
                $output = \'style="background-image:url(\'.esc_url($themeum_options[\'blog-banner\'][\'url\']).\');background-size: cover;background-position: 50% 50%;padding: 150px 0 90px;"\';
                return $output;
            }else{
                 $output = \'style="background-color:\'.esc_attr($themeum_options[\'blog-subtitle-bg-color\']).\';padding: 150px 0 90px;"\';
                 return $output;
            }
        }
    }

    if( isset($post->post_name) ){
        if(!empty($post->ID)){ 
            $image_attached = esc_attr(get_post_meta( $post->ID , \'thm_subtitle_images\', true ));
            if(!empty($image_attached)){
                $sub_img = wp_get_attachment_image_src( $image_attached , \'blog-full\'); 
                $output = \'style="background-image:url(\'.esc_url($sub_img[0]).\');background-size: cover;background-position: 50% 50%;padding: 150px 0 90px;"\';
                if(empty($sub_img[0])){
                    $output = \'style="background-color:\'.esc_attr(rwmb_meta("thm_subtitle_color")).\';padding: 150px 0 90px;"\';
                    if(rwmb_meta("thm_subtitle_color") == \'\'){
                        $output = thmtheme_call_sub_header();
                    }
                }
            }else{
                if(rwmb_meta("thm_subtitle_color") != "" ){
                    $output = \'style="background-color:\'.esc_attr(rwmb_meta("thm_subtitle_color")).\';padding: 150px 0 90px;"\';
                }else{
                    $output = thmtheme_call_sub_header();
                }
            }
        }else{
            $output = thmtheme_call_sub_header();
        }
    }else{
            $output = thmtheme_call_sub_header();
        }

?>

<?php if (!is_front_page()) { ?>

<div class="sub-title" <?php echo $output;?>>
    <div class="container">
        <div class="sub-title-inner">
            <h2><?php the_title(); ?></h2>
        </div>
    </div>
</div>

<?php } ?>
如何修改代码以实现此目的?

1 个回复
最合适的回答,由SO网友:cjbj 整理而成

大部分代码都是为背景图像或颜色生成样式。标题在此行中生成:

<h2><?php the_title(); ?></h2>
您只需将其替换为如下文本:

<h2>Whatever</h2>