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