我正在尝试翻译WPML翻译器的链接锚点 - 单词“Next”:
function getPrevNext(){
$pagelist = get_pages('sort_column=menu_order&sort_order=asc');
$pages = array();
foreach ($pagelist as $page) {
$pages[] += $page->ID;
}
$current = array_search(get_the_ID(), $pages);
$prevID = $pages[$current-1];
$nextID = $pages[$current+1];
echo '<div class="prev-next-page-bottom-navigation">';
if (!empty($prevID)) {
echo '<div class="prevpage-bottom-navi">';
echo '<a href="';
echo get_permalink($prevID);
echo '"';
echo 'title="';
echo get_the_title($prevID);
echo'">Previous</a>';
echo "</div>";
}
if (!empty($nextID)) {
echo '<div class="nextpage-bottom-navi">';
echo '<a href="';
echo get_permalink($nextID);
echo '"';
echo 'title="';
echo get_the_title($nextID);
echo'">Next</a>';
echo "</div>";
}
}
我需要将echo'">Next</a>';
的以下行更改为:
<?php echo __('Next','my_wp_theme');?>
echo内部回显会产生PHP错误
SOLUTION:
使用echo'">Next</a>';
echo'">'.__('Next','my_wp_theme').'</a>';
答案 0 :(得分:2)
您可以以更好的方式编写所有这些内容,以便按照您的需要阅读和打印。
<?php if (!empty($nextID)) { ?>
<div class="alignright">
<a href="<?php echo get_permalink($nextID); ?>" title="<?php echo get_the_title($nextID); ?>">
<?php _e('Next','my_wp_theme'); ?>
</a>
</div>
<?php } ?>
答案 1 :(得分:0)
您还可以使用sprintf
简化此操作echo sprintf('<div class="alignright"><a href="%s" title="%s">%s</a></div>', get_permalink($nextID), get_the_title($nextID), __('Next','my_wp_theme'));