Php 在WordPress中将页面/帖子标题移出循环

Php 在WordPress中将页面/帖子标题移出循环,php,wordpress,Php,Wordpress,我有一个在WordPress上运行的客户端站点。它使用WooThemes画布作为基础主题(带有自定义的子主题),并使用Time.ly All-in-one事件日历。可以查看它 我提出的设计要求我将页面/帖子标题移到主要内容区域之外。我遵循了这方面的说明,并根据评论进行了修改,以便它也适用于帖子和Time.ly事件帖子。my functions.php文件中的条目如下所示: add_filter( 'the_title', 'woo_custom_hide_single_post_title',

我有一个在WordPress上运行的客户端站点。它使用WooThemes画布作为基础主题(带有自定义的子主题),并使用Time.ly All-in-one事件日历。可以查看它

我提出的设计要求我将页面/帖子标题移到主要内容区域之外。我遵循了这方面的说明,并根据评论进行了修改,以便它也适用于帖子和Time.ly事件帖子。my functions.php文件中的条目如下所示:

add_filter( 'the_title', 'woo_custom_hide_single_post_title', 10 );
function woo_custom_hide_single_post_title ( $title ) {
    if ( is_singular( array( 'post', 'ai1ec_event' ) ) && in_the_loop() ) { $title = ''; }

    return $title;
} // End woo_custom_hide_single_post_title()

add_filter( 'the_title', 'woo_custom_hide_single_page_title', 10 );

function woo_custom_hide_single_page_title ( $title ) {
    if ( is_page() && in_the_loop() ) { $title = ''; }

    return $title;
} // End woo_custom_hide_single_page_title()

// Add Titles above Content Area on all Posts & Pages

add_action( 'woo_content_before_singular-post', 'woo_custom_add_title', 10 ); 
add_action( 'woo_content_before_singular-ai1ec_event', 'woo_custom_add_title', 10 );
add_action( 'woo_content_before_singular-page', 'woo_custom_add_title', 10 ); 

function woo_custom_add_title () {
    if ( ! is_page_template(array('template-biz.php', 'template-brewpub.php')) ) {
        global $post;
        $title = '<h1 class="page-title">' . get_the_title( $post->ID ) . '</h1>' . "";
        echo '<div id="title_container"><header class="col-full">';
        echo $title;
        woo_post_meta();
        echo '</header></div>';
    }
} // End woo_custom_add_post_title()
add_filter('the_title','woo_custom_hide_single_post_title',10);
函数woo_自定义_隐藏_单个_发布_标题($title){
if(是单数的(数组('post','ai1ec_event'))&&in_the_loop()){$title=''';}
返回$title;
}//结束woo_自定义_隐藏_单个_发布_标题()
添加过滤器(“标题”、“自定义”隐藏单个页面标题”,10);
函数woo_自定义_隐藏_单个_页面_标题($title){
如果(是_page()&&in_the_loop()){$title=''';}
返回$title;
}//End-woo\u-custom\u-hide\u-single\u-page\u-title()
//在所有帖子和页面的内容区域上方添加标题
添加动作(单数post前添加内容,自定义添加标题,10);
添加行动('woo_内容\u在单个ai1ec_事件之前,'woo_自定义\u添加标题',10);
添加动作(“单数页前添加内容”,“自定义添加标题”,10);
函数woo_自定义_添加_标题(){
如果(!is_page_template(数组('template-biz.php','template-brewpub.php')){
全球$员额;
$title=''。获取标题($post->ID)。'';
回声';
echo$标题;
woo_post_meta();
回声';
}
}//End-woo\u custom\u add\u post\u title()
这产生了一些不理想的结果,可以在本文的开发站点I设置(DEV.thebrewworks.com)上看到:

  • 由于Time.ly事件日历也使用_标题来显示其事件,因此在我在页面循环(主页和两个餐厅位置页面)中使用日历的三个实例中,事件标题不会显示。通过创建一个测试页面(dev.thebrewworks.com/Test页面)确认了这一点,在该页面中,您可以在循环中看到两个日历实例,在侧栏中看到一个日历实例。循环中的两个实例没有标题,而侧边栏有标题
  • 在循环中取消标题并没有取消Post Meta,它仍然显示在主内容区域中,但我希望它位于新DIV的标题下,因此在循环外重新发布woo_Post_Meta会给我留下两个Post Meta实例
  • 为了让网站上线,我不得不在functions.php文件中做出一些让步:

    // Hide Titles on All Posts & Pages
    
    add_filter( 'the_title', 'woo_custom_hide_single_post_title', 10 );
    function woo_custom_hide_single_post_title ( $title ) {
        if ( is_singular( array( 'post', 'ai1ec_event' ) ) && in_the_loop() ) { $title = ''; }
    
        return $title;
    } // End woo_custom_hide_single_post_title()
    
    add_filter( 'the_title', 'woo_custom_hide_single_page_title', 10 );
    
    function woo_custom_hide_single_page_title ( $title ) {
        if ( is_page() && in_the_loop() && is_page_template( array('page.php', 'template-contact.php' ) ) ) { $title = ''; }
    
        return $title;
    } // End woo_custom_hide_single_page_title()
    
    // Add Titles above Content Area on all Posts & Pages
    
    add_action( 'woo_content_before_singular-post', 'woo_custom_add_title', 10 ); 
    add_action( 'woo_content_before_singular-ai1ec_event', 'woo_custom_add_title', 10 );
    add_action( 'woo_content_before_singular-page', 'woo_custom_add_title', 10 ); 
    
    function woo_custom_add_title () {
        if ( ! is_page_template(array('template-biz.php', 'template-brewpub.php')) ) {
            global $post;
            $title = '<h1 class="page-title">' . get_the_title( $post->ID ) . '</h1>' . "";
            echo '<div id="title_container"><header class="col-full">';
            echo $title;
            woo_post_meta();
            echo '</header></div>';
        }
    } // End woo_custom_add_post_title()
    
    // Disable Post Meta
    function woo_post_meta() {}
    ?>
    
    //隐藏所有帖子和页面上的标题
    添加过滤器(“标题”、“自定义标题”、“隐藏单个标题”、“发布标题”10);
    函数woo_自定义_隐藏_单个_发布_标题($title){
    if(是单数的(数组('post','ai1ec_event'))&&in_the_loop()){$title=''';}
    返回$title;
    }//结束woo_自定义_隐藏_单个_发布_标题()
    添加过滤器(“标题”、“自定义”隐藏单个页面标题”,10);
    函数woo_自定义_隐藏_单个_页面_标题($title){
    如果(is_page()&&in_the_loop()&&is_page_模板(数组('page.php','template contact.php')){$title=''';}
    返回$title;
    }//End-woo\u-custom\u-hide\u-single\u-page\u-title()
    //在所有帖子和页面的内容区域上方添加标题
    添加动作(单数post前添加内容,自定义添加标题,10);
    添加行动('woo_内容\u在单个ai1ec_事件之前,'woo_自定义\u添加标题',10);
    添加动作(“单数页前添加内容”,“自定义添加标题”,10);
    函数woo_自定义_添加_标题(){
    如果(!is_page_template(数组('template-biz.php','template-brewpub.php')){
    全球$员额;
    $title=''。获取标题($post->ID)。'';
    回声';
    echo$标题;
    woo_post_meta();
    回声';
    }
    }//End-woo\u custom\u add\u post\u title()
    //禁用后元数据
    函数woo_post_meta(){}
    ?>
    
    注意这些变化:

  • 我完全禁用了post_meta。这不完全是我想要的,但总比让它出现两次要好
  • 我修改了禁用页面标题的函数,使其仅适用于使用某些模板的页面(我上面提到的三个实例使用的是画布中的业务模板,该模板已经抑制了页面标题)。这将需要我进入并添加每个新的页面模板,我想抑制标题,但…最重要的是,它不起作用。看一看现场。页面标题在静态页面上显示两次。一次在白色内容区域内,一次在黄色标题外部
  • 我不是PHP开发人员……我更喜欢设计/HTML/CSS。我知道的足够危险……如何修改现有代码等等,但不一定是如何从头开始编写自己的代码。我不知道我提出问题的方式是否是最好/最优雅的方式。既然你掌握了所有的事实,下面是我的问题:

  • 在理想情况下,Post Meta只会出现在博客条目上(而不是日历条目上……那里真的不需要它们),并且出现在我移动的页面标题下的主内容区域之外。我怎样才能做到这一点?我猜这将是一种条件语句,它从循环中的所有实例中删除woo_post_meta,并将其添加到woo_custom_add_标题中,前提是它是一篇标准文章,但我不知道如何实现
  • 如何抑制显示在所有静态页面上内容区域顶部的_标题,而不考虑模板,但不影响循环中其他地方出现的_标题实例(如日历联合)。在我的头脑中,必须有一种方式来表明,你只想禁用某个div/id中的_标题,等等,但是,同样……只足以造成危险,除非我在其他地方看到它,否则我无法自己想出解决方案
  • 提前谢谢