我有一个在WordPress上运行的客户端站点 . 它使用WooThemes Canvas作为基本主题(具有自定义的子主题),并使用Time.ly All-in-one-Event日历 . 它可以被视为here .

我想出的设计要求我在主要内容区域之外移动页面/帖子 Headers . 我按照WooThemes customization document上的说明进行操作,并根据注释进行修改,以便它也适用于帖子和Time.ly事件发布 . 我的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()

这产生了一些不良结果,可以在我为此帖子设置的DEV站点上看到(dev.thebrewworks.com):

  • 由于Time.ly事件日历也使用the_title显示它's events, in the three instances I used the calendar inside a page loop (the homepage and the two restaurant location pages), the event titles don' t显示 . 通过创建测试页面(dev.thebrewworks.com/test-page)确认了这一点,您可以在其中看到循环内部的两个日历实例,以及一个外部(在侧边栏中) . 循环中的两个实例没有 Headers ,而侧边栏则没有 .

  • 抑制循环中的the_title没有抑制Post Meta,它仍然出现在主要内容区域中,但是我希望它在新DIV的 Headers 下,所以在循环外部重新发布woo_post_meta会给我留下两个Post的实例元 .

为了让网站生效,我必须在我的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() {}
?>

请注意更改:

  • 我完全禁用了post_meta . 不完全是我想要的,但比它出现两次更好 .

  • 我修改了禁用页面 Headers 的功能,使其仅适用于使用某些模板的页面(我上面提到的三个实例使用Canvas中已禁止页面 Headers 的业务模板) . 这将需要我进入并添加我想要取消 Headers 的每个新页面模板,尽管......而且最重要的是,它不起作用 . 看看现场网站 . 页面 Headers 在静态页面上显示两次 . 一旦进入白色内容区域,一旦进入黄色 Headers .

我不是PHP开发者......我更像是一个设计/ HTML / CSS人 . 我知道足够危险...如何修改现有代码等,但不一定如何从头开始编写自己的代码 . 我不知道我提出的方式是否是最好/最优雅的方式 . 既然你掌握了所有的事实,这是我的问题:

  • 在一个理想的世界中,Post Meta只会出现在博客条目上(不是日历条目......真的不需要它们),而是在我移动的页面 Headers 下面的主要内容区域外面 . 我怎样才能做到这一点?我'm guessing it'将成为某种条件语句,从循环内的所有实例中删除woo_post_meta,并且仅在它是标准帖子时将其添加到woo_custom_add_title,但是如何到达那里我不知道 .

  • 如何抑制显示在所有静态页面上内容区域顶部的the_title,无论模板如何,但是它不会影响循环中其他位置出现的the_title实例(如日历联合) . 在我的脑海中,必须有一种方式来表明你只想在我自己提出解决方案的情况下禁用the_title .

提前感谢您的意见 .