[英]WordPress: Remove get_the_title from my content template
我正在為我的客戶站點運行 _underscores 主題的變體,並且我們已經在自定義標題元素中顯示了頁面或帖子標題,因此它不再需要在模板部分/內容的循環內。 php.ini 我以為只要刪除“get_the_title”就可以避免在我的帖子正文中看到標題,但相反,我收到了各種錯誤,例如“意外的 ')”或類似的錯誤。 那么我如何擺脫 get_the_title 引用並仍然使其有效? 這是我目前所擁有的。
<div class="entry-content">
<?php if ( is_category() || is_archive() ) {
the_excerpt('');
} else {
the_content( sprintf(
wp_kses(
/* translators: %s: Name of current post. Only visible to screen readers */
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'orchestra' ),
array(
'span' => array(
'class' => array(),
),
)
),
get_the_title()
) );
if ( is_category() || is_archive() ) {
echo '<p class="btn-cc"><a href="%s" rel="bookmark">Read More</a></p>';
}
wp_link_pages( array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'orchestra' ),
'after' => '</div>',
) );
}
?>
這方面的格式使其相對難以閱讀。 所以首先我會清理一下。 如果您查看the_content()
的文檔,您會看到第一個參數是$more_text_link
。 因此,第5
行到第15
行添加了“繼續閱讀 [帖子標題]”測試。
如果你根本不需要它,你可以像這樣使用the_content()
:
<div class="entry-content">
<?php
if( is_category() || is_archive() ){
the_excerpt('');
} else {
the_content();
if( is_category() || is_archive() ){
echo '<p class="btn-cc"><a href="%s" rel="bookmark">Read More</a></p>';
}
wp_link_pages( array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'orchestra' ),
'after' => '</div>',
) );
}
?>
否則,您需要添加自己的默認文本:
<div class="entry-content">
<?php
if( is_category() || is_archive() ){
the_excerpt('');
} else {
the_content( 'Continue Reading' );
if( is_category() || is_archive() ){
echo '<p class="btn-cc"><a href="%s" rel="bookmark">Read More</a></p>';
}
wp_link_pages( array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'orchestra' ),
'after' => '</div>',
) );
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.