为了账号安全,请及时绑定邮箱和手机立即绑定

在 sprintf 中添加 html

在 sprintf 中添加 html

PHP
Qyouu 2023-03-26 15:28:35
我有一些代码'next_text' => sprintf( esc_html__( '%s', 'mytheme' ), '%title' ),我需要在其中添加 html。基本上我想补充<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 关注
  • 79 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信