Reputation: 267
I am trying to get the translation of a link anchor for WPML translator - for the word "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>";
}
}
I need to change the following line of echo'">Next</a>';
to be:
<?php echo __('Next','my_wp_theme');?>
echo inside echo makes a PHP error
SOLUTION:
Change echo'">Next</a>';
with echo'">'.__('Next','my_wp_theme').'</a>';
Upvotes: 0
Views: 3114
Reputation: 682
You could also simplify this with 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'));
Upvotes: 0
Reputation: 1383
You can write all of this in a better way to read and to print it like you wanted.
<?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 } ?>
Upvotes: 2