亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 sprintf 中添加 html

在 sprintf 中添加 html

PHP
Qyouu 2023-03-26 15:28:35
我有一些代碼'next_text' => sprintf( esc_html__( '%s', 'mytheme' ), '%title' ),我需要在其中添加 html?;旧衔蚁胙a充<span>Previous article</span>在標題之前。我怎樣才能做到這一點?編輯:完整的功能是function mytheme_single_post_navigation() {if ( ! is_singular( 'post' ) ) {    return;}if ( ! intval( mytheme_get_theme_mod( 'blog_single_navigation' ) ) ) {    return;}the_post_navigation( array(    /* translators: %s: title syntax. */    'prev_text' => sprintf( esc_html__( '%s', 'mytheme' ), '%title' ),    /* translators: %s: title syntax. */    'next_text' => sprintf( esc_html__( '%s', 'mytheme' ), '%title' ),) );}endif;
查看完整描述

1 回答

?
慕萊塢森

TA貢獻1810條經驗 獲得超4個贊

如果你想在你的帖子的 single.php 中編輯 wordpress 帖子導航,你可以使用:


<span> <?php previous_post_link( '%link', '? Previous article' ); ?> </span>

<span> <?php next_post_link( '%link', 'Next article ?' ); ?> </span>

如果你想通過設置'next_text'來實現它,你也可以將你的輸出放在一個字符串中并使用它:


<?php $next_post = '<span>Previous article</span>'; ?>

然后將其分配給“next_text”:


'next_text' => $next_post

如果您閱讀 sprintf() 函數https://www.w3schools.com/php/func_string_sprintf.asp ,您可以毫無問題地添加 html 標簽。所以它也可以用于:


'next_text' => sprintf( esc_html__( '%s', 'mytheme' ), '<span> %title </span>' ),

但是你不想擁有這個頭銜,所以你實際上不需要這個,如果我沒問錯的話。


編輯:


如果你想在你的帖子名稱前顯示跨度,你可以使用:


<?php previous_post_link( '%link', '<span>Previous article</span>'.' %title' ); ?>

用點 . 您正在將 span 元素與標題連接起來。


所以在你的代碼中,你的 the_post_navigation 看起來像:


the_post_navigation( array(

    /* translators: %s: title syntax. */

    'prev_text' => sprintf( esc_html__( '%s', 'mytheme' ), '<span>Previous article</span>'.' %title' ),


    /* translators: %s: title syntax. */

    'next_text' => sprintf( esc_html__( '%s', 'mytheme' ), '<span>Next article</span>'.' %title' ),

) );


查看完整回答
反對 回復 2023-03-26
  • 1 回答
  • 0 關注
  • 143 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號