我需要从归档页面标题中删除“归档:”标签。我尝试了此字符串,但没有结果:
<?php the_archive_title(\'<h2>\',\'</h2>\', false);?>
标题在标题前始终显示“存档:”标签。我怎样才能摆脱它?
这是我的页面的完整代码:
<?php get_header(\'inner\');?>
<div class="row large-uncollapse">
<div class="columns small-12 medium-12 large-12">
<div class="breadcrumbs" typeof="BreadcrumbList" vocab="http://schema.org/">
<?php if(function_exists(\'bcn_display\'))
{
echo \'<b>Sei in:</b>\';
bcn_display();
}?>
</div>
</div>
</div>
<div class="row large-uncollapse">
<div class="columns small-12 medium-12 large-12 large-centered text-center pad-vr-2">
<?php echo get_the_archive_title();?>
</div>
</div>
<?php if(is_singular(\'rassegna-stampa\')): ?>
<div id="rassegna-stampa">
<div class="row large-collapse">
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
echo \'<div class="columns small-12 medium-6 large-4 float-left" style="margin-bottom:10px;">\';
echo \'<div class="columns small-3 medium-3 large-3">\';
if(has_post_thumbnail()){
echo the_post_thumbnail();
}
if( get_field(\'file\') ) {
echo \'<a href="\';
the_field(\'file\');
echo \'" data-featherlight="iframe" target="_blank">\';
echo \'<button>\';
echo \'<img src="\';
echo get_site_url();
echo \'/wp-content/uploads/2016/09/pdf.png" width="20px">\';
echo \'</button>\';
echo \'</a>\';
}
if( get_field(\'link\') ) {
echo \'<a href="\';
echo the_field(\'link\');
echo \'" data-featherlight="iframe">\';
echo \'<button>\';
echo \'<img src="\';
echo get_site_url();
echo \'/wp-content/uploads/2016/09/link.png" width="20px">\';
echo \'</button>\';
echo \'</a>\';
}
echo \'</div>\';
echo \'<div class="columns small-9 medium-9 large-9">\';
echo \'<h3 style="margin:0px;">\';
echo the_title();
echo \'</h3>\';
echo \'<small>\';
echo \'—\';
echo the_field(\'testata\');
echo \'</small>\';
echo \'<small>\';
echo the_field(\'data\');
echo \'</small>\';
echo \'<span style="font-size:12px;">\';
the_excerpt();
echo \'</span>\';
echo \'</div>\';
echo \'</div>\';
endwhile;
else :
echo wpautop( \'Sorry, no posts were found\' );
endif;
?>
</div>
</div>
<?php else :?>
<div id="libri">
<div class="row large-collapse">
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
echo \'<div class="columns small-12 medium-6 large-4 float-left" style="margin-bottom:10px;padding-bottom: 12px; height:220px;">\';
echo \'<div class="columns small-3 medium-3 large-3">\';
if(has_post_thumbnail()){
echo the_post_thumbnail();
}
echo \'</div>\';
echo \'<div class="columns small-9 medium-9 large-9">\';
echo \'<h3 style="margin:0px;">\';
echo the_title();
echo \'</h3>\';
echo \'<div style="float:left;width:100%;">\';
echo \'<small style="float:left;width:auto;">\';
echo the_field(\'anno_pubblicazione\');
echo \'</small>\';
echo \'<div style="float:left; line-height:15px;">\';
echo \' — \';
echo \'</div>\';
echo \'<small style="float:left;width:auto;">\';
echo the_field(\'editore\');
echo \'</small>\';
echo \'</div>\';
echo \'<span style="font-size:12px;">\';
the_excerpt();
echo \'</span>\';
echo \'</div>\';
echo \'<div class="columns small-12 medium-12 large-6">\';
echo \'<a href="\';
the_permalink();
echo \'">\';
echo \'<button style="width:auto; padding:0.4rem; float:left; border:1px #000 solid;">\';
echo \'Leggi tutto\';
echo \'</button>\';
echo \'</a>\';
echo \'</div>\';
echo \'<div class="columns small-12 medium-12 large-6">\';
if( get_field(\'link_acquisto\') ):
echo \'<a href="\';
echo the_field(\'link_acquisto\');
echo \'" style="color:#D34D3D;">\';
echo \'<button style="width:auto; padding:0.4rem; float:left; border:1px #D34D3D solid;">\';
echo \'COMPRA\';
echo \'</button>\';
echo \'</a>\';
endif;
echo \'</div>\';
echo \'</div>\';
endwhile;
else :
echo wpautop( \'Sorry, no posts were found\' );
endif;
?>
</div>
</div>
<?php endif ;?>
<?php get_footer();?>
谢谢!
最合适的回答,由SO网友:Benoti 整理而成
您需要使用过滤器get_the_archive_title
. 工作原理如下the_title
滤器有关嵌入筛选器的函数的更多详细信息here
更多关于这个问题remove category tag
编辑:
如果是自定义帖子类型存档页面,您可以使用其他功能打印标题:post_type_archive_title()
然后你就可以用过滤器连接标题了post_type_archive_title
, 但此函数没有前缀。
因此,在模板中,将调用替换为get_the_archive_title()
具有以下功能:
post_type_archive_title();
SO网友:Sergey Fedirko
此外,您还可以从任何标准标题中删除不必要的单词:
add_filter( \'get_the_archive_title\', function ($title) {
if ( is_category() ) {
$title = single_cat_title( \'\', false );
} elseif ( is_tag() ) {
$title = single_tag_title( \'\', false );
} elseif ( is_author() ) {
$title = \'<span class="vcard">\' . get_the_author() . \'</span>\' ;
} elseif ( is_tax() ) { //for custom post types
$title = sprintf( __( \'%1$s\' ), single_term_title( \'\', false ) );
} elseif (is_post_type_archive()) {
$title = post_type_archive_title( \'\', false );
}
return $title;
});