简体   繁体   English

语法错误,在WordPress的下一个/上一个发布链接中排除类别

[英]syntax error excluding category from next/prev post links in WordPress

I'm having some trouble with syntax when excluding a category from the prev/next nav on single posts. 从单个帖子的上一个/下一个导航中排除类别时,语法出现问题。 I have it working but not fully how I want it to be. 我有它的工作,但不是我想要的那样。

For the next link, it's working 100%: showing the linked post title and an arrow. 对于下一个链接,它正在100%起作用:显示链接的帖子标题和箭头。 For the previous link, it's showing a linked arrow but the title is missing. 对于上一个链接,它显示一个链接的箭头,但标题丢失。 I'm not quite sure where to insert category 7 in the previous post code in order to get it working properly. 我不太确定在前面的邮政编码中应在哪里插入类别7,以使其正常工作。 I've tried a few different spots but i keep breaking the page and getting errors... 我尝试了几个不同的地方,但我不断打破页面并得到错误信息...

This is how I have it now... 这就是我现在的方式...

<?php previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '&larr;', 'Previous post link', 'formationpro' ), '7' . '</span> %title' ); ?>
<?php next_post_link( '<div class="nav-next">%link</div>', '%title <span class="meta-nav">' . _x( '&rarr;', 'Next post link', 'formationpro' ), '7' . '</span>' ); ?>

... what do i need to do to make the previous_post_link work properly and show the title? ...我需要怎么做才能使previous_post_link正常工作并显示标题?

Thanks in advance for your help. 在此先感谢您的帮助。

Kellie 凯利

The title swapping only works on the second argument of those functions. 标题交换仅适用于这些函数的第二个参数。 You have %title in the argument for excluded_terms . 你必须%title中的参数excluded_terms Try this instead: 尝试以下方法:

$previous_text = '<span class="meta-nav">' . _x( '&larr;', 'Previous post link', 'formationpro' ) .'</span> %title'
$next_text = '%title <span class="meta-nav">' . _x( '&rarr;', 'Next post link', 'formationpro' ). '</span>'

previous_post_link( '<div class="nav-previous">%link</div>', $previous_text, 7);

next_post_link( '<div class="nav-next">%link</div>', $next_text, 7);

Or if you prefer to keep them in your format: 或者,如果您希望保留其格式,请执行以下操作:

<?php previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '&larr;', 'Previous post link', 'formationpro' ) . '</span> %title', 7 ); ?>
<?php next_post_link( '<div class="nav-next">%link</div>', '%title <span class="meta-nav">' . _x( '&rarr;', 'Next post link', 'formationpro' ) . '</span>', 7 ); ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM