将文本和图标 link 打印到 Wordpress 上的相邻帖子
Print text and icon link to adjacent posts on Wordpress
我的 Wordpress 中有以下代码,它使我的 back/next post 导航:
<nav role="navigation" id="<?php echo esc_attr( $nav_id ); ?>" class="<?php echo $nav_class; ?>">
<?php if ( is_single() ) : // navigation links for single posts ?>
<?php next_post_link( '<div class="nav-next">%link</div>', '<span class="fa fa-chevron-right"></span>' . _x( '', 'Previous post link', 'bnNav' ) ); ?>
<?php previous_post_link( '<div class="nav-previous">%link</div>', _x( '', 'Next post link', 'bnNav' ). '<span class="fa fa-chevron-left"></span>'); ?>
...
这会将指向左右的 V 形 link 指向后面和下一个 post。
我希望 link 的文本与人字形一样显示,但不确定如何调整我的代码。
函数 _x() 用于 Wordpress 中的翻译等待作为参数:
$text (string) (Required) Text to translate.
$context (string)(Required) Context information for the translators.
$domain (string) (Optional) Text domain. Unique identifier for retrieving translated
strings. Default value: 'default'
为了使您的文本显示,只需填写第一个参数以设置要显示的文本,如果您愿意,也可以在之后翻译它。例如:
<nav role="navigation" id="<?php echo esc_attr( $nav_id ); ?>" class="<?php echo $nav_class; ?>">
<?php if ( is_single() ) : // navigation links for single posts ?>
<?php next_post_link( '<div class="nav-next">%link</div>', '<span class="fa fa-chevron-right"></span>' . _x( get_previous_post()->post_title;, 'Previous post link', 'bnNav' ) ); ?>
<?php previous_post_link( '<div class="nav-previous">%link</div>', _x( get_next_post()->post_title;, 'Next post link', 'bnNav' ). '<span class="fa fa-chevron-left"></span>'); ?>
有关详细信息,请查看 _x() and next_post_link() 的官方参考资料。
如果您想获取链接到的帖子的名称,可以使用 get_next_post() and get_previous_post() 函数。
希望对您有所帮助。
我的 Wordpress 中有以下代码,它使我的 back/next post 导航:
<nav role="navigation" id="<?php echo esc_attr( $nav_id ); ?>" class="<?php echo $nav_class; ?>">
<?php if ( is_single() ) : // navigation links for single posts ?>
<?php next_post_link( '<div class="nav-next">%link</div>', '<span class="fa fa-chevron-right"></span>' . _x( '', 'Previous post link', 'bnNav' ) ); ?>
<?php previous_post_link( '<div class="nav-previous">%link</div>', _x( '', 'Next post link', 'bnNav' ). '<span class="fa fa-chevron-left"></span>'); ?>
...
这会将指向左右的 V 形 link 指向后面和下一个 post。
我希望 link 的文本与人字形一样显示,但不确定如何调整我的代码。
函数 _x() 用于 Wordpress 中的翻译等待作为参数:
$text (string) (Required) Text to translate.
$context (string)(Required) Context information for the translators.
$domain (string) (Optional) Text domain. Unique identifier for retrieving translated strings. Default value: 'default'
为了使您的文本显示,只需填写第一个参数以设置要显示的文本,如果您愿意,也可以在之后翻译它。例如:
<nav role="navigation" id="<?php echo esc_attr( $nav_id ); ?>" class="<?php echo $nav_class; ?>">
<?php if ( is_single() ) : // navigation links for single posts ?>
<?php next_post_link( '<div class="nav-next">%link</div>', '<span class="fa fa-chevron-right"></span>' . _x( get_previous_post()->post_title;, 'Previous post link', 'bnNav' ) ); ?>
<?php previous_post_link( '<div class="nav-previous">%link</div>', _x( get_next_post()->post_title;, 'Next post link', 'bnNav' ). '<span class="fa fa-chevron-left"></span>'); ?>
有关详细信息,请查看 _x() and next_post_link() 的官方参考资料。
如果您想获取链接到的帖子的名称,可以使用 get_next_post() and get_previous_post() 函数。
希望对您有所帮助。