Revision: 29533
Updated Code
at August 6, 2010 01:46 by trepmal
Updated Code
<?php /* prev/next links */ if ($post->post_parent == 19) { /* 19 == id of 'Rooms' page */ $exclude = implode(',',array('984')); $toplevel = 'title_li=&depth=1&echo=0&exclude='.$exclude; $siblings = $toplevel.'&child_of='.$post->post_parent; if (function_exists(pause_exclude_pages)) { pause_exclude_pages(); $links = ($post->post_parent) ? wp_list_pages($siblings) : wp_list_pages($toplevel); resume_exclude_pages(); } else { $links = ($post->post_parent) ? wp_list_pages($siblings) : wp_list_pages($toplevel); } $links = array_filter(explode("</li>",$links)); foreach($links as $k=>$v) { if (strpos($v,'current_page_item') !== FALSE) { $current = $k; } $links[$k] = $v.'</li>';} $total = count($links)-1; $prev = (int)$current-1; $next = $current+1; if ($current == $total) $next = '0'; // if you're on the last page, next will be the first if ($current == '0') $prev = $total; // if you're on the first page, prev will be the last $prevLink = strip_tags($links[$prev],'<a>'); //remove the <li> tags $nextLink = strip_tags($links[$next],'<a>'); //remove the <li> tags function change_anchor_text($link, $newtext, $placement) { $pos1 = strpos($link, '>')+1; $pos2 = strpos($link, '<', 1); $anchortext = substr($link, $pos1, $pos2-$pos1); if($placement == 'before') { return str_replace($anchortext, $newtext.' '.$anchortext, $link); } else if ($placement == 'after') { return str_replace($anchortext, $anchortext.' '.$newtext, $link); } else if ($placement == 'replace') { return str_replace($anchortext, $newtext, $link); } } $prevLinkb = $prevLink; $prevLink = change_anchor_text($prevLink, ' < View Previous Room ', 'replace'); /* link customization goes here */ $nextLink = change_anchor_text($nextLink, ' View Next Room > ', 'replace'); $prepend = ''; $separator = '<a href="/lodging/" class="norm">Return to All Rooms</a>'; $separator2 = '<a href="#" class="norm">Check Availability Online</a>'; echo '<p class="pnpn">'.$prepend.$prevLink.$separator.$nextLink.'</p>'; } /* end prev/next links */ ?>
Revision: 29532
Updated Code
at August 6, 2010 01:46 by trepmal
Updated Code
<?php /* prev/next links */ if ($post->post_parent == 19) { /* 19 == id of 'Rooms' page */ $exclude = implode(',',array('984')); $toplevel = 'title_li=&depth=1&echo=0&exclude='.$exclude; $siblings = $toplevel.'&child_of='.$post->post_parent; if (function_exists(pause_exclude_pages)) { pause_exclude_pages(); $links = ($post->post_parent) ? wp_list_pages($siblings) : wp_list_pages($toplevel); resume_exclude_pages(); } else { $links = ($post->post_parent) ? wp_list_pages($siblings) : wp_list_pages($toplevel); } $links = array_filter(explode("</li>",$links)); foreach($links as $k=>$v) { if (strpos($v,'current_page_item') !== FALSE) { $current = $k; } $links[$k] = $v.'</li>';} $total = count($links)-1; $prev = (int)$current-1; $next = $current+1; if ($current == $total) $next = '0'; // if you're on the last page, next will be the first if ($current == '0') $prev = $total; // if you're on the first page, prev will be the last $prevLink = strip_tags($links[$prev],'<a>'); //remove the <li> tags $nextLink = strip_tags($links[$next],'<a>'); //remove the <li> tags function change_anchor_text($link, $newtext, $placement) { $pos1 = strpos($link, '>')+1; $pos2 = strpos($link, '<', 1); $anchortext = substr($link, $pos1, $pos2-$pos1); if($placement == 'before') { return str_replace($anchortext, $newtext.' '.$anchortext, $link); } else if ($placement == 'after') { return str_replace($anchortext, $anchortext.' '.$newtext, $link); } else if ($placement == 'replace') { return str_replace($anchortext, $newtext, $link); } } $prevLinkb = $prevLink; $prevLink = change_anchor_text($prevLink, ' < View Previous Room ', 'replace'); /* link customization goes here */ $nextLink = change_anchor_text($nextLink, ' View Next Room > ', 'replace'); $prepend = ''; $separator = '<a href="/lodging/" class="norm">Return to All Rooms</a>'; $separator2 = '<a href="#" class="norm">Check Availability Online</a>'; echo '<p class="pnpn">'.$prepend.$prevLink.$separator.$nextLink.'</p>'; } /* end prev/next links */ ?> <?php /** OLDER VERSION **/ /* prev/next links */ if ($post->post_parent == 5) { /* in this case, I only want the subnav displayed on certain child pages */ $exclude = implode(',',array('984')); //exclude this page id $toplevel = 'title_li=&depth=1&echo=0&exclude='.$exclude; $siblings = $toplevel.'&child_of='.$post->post_parent; if (function_exists(pause_exclude_pages)) { pause_exclude_pages(); $links = ($post->post_parent) ? wp_list_pages($siblings) : wp_list_pages($toplevel); resume_exclude_pages(); } else { $links = ($post->post_parent) ? wp_list_pages($siblings) : wp_list_pages($toplevel); } $links = array_filter(explode("\n",$links)); foreach($links as $k=>$v) { if (strpos($v,'current_page_item') !== FALSE) { $current = $k; } } $total = count($links)-1; $prev = $current-1; $next = $current+1; if ($current == $total) $next = '0'; // if you're on the last page, next will be the first if ($current == '0') $prev = $total; // if you're on the first page, prev will be the last $prevLink = strip_tags($links[$prev],'<a>'); //remove the <li> tags $nextLink = strip_tags($links[$next],'<a>'); //remove the <li> tags function change_anchor_text($link, $newtext, $placement) { $pos1 = strpos($link, '>')+1; $pos2 = strpos($link, '<', 1); $anchortext = substr($link, $pos1, $pos2-$pos1); if($placement == 'before') { return str_replace($anchortext, $newtext.' '.$anchortext, $link); } else if ($placement == 'after') { return str_replace($anchortext, $anchortext.' '.$newtext, $link); } else if ($placement == 'replace') { return str_replace($anchortext, $newtext, $link); } } $prevLink = change_anchor_text($prevLink, ' < Previous Room ', 'replace'); /* link customization goes here */ $nextLink = change_anchor_text($nextLink, ' Next Room > ', 'replace'); $prepend = ''; $separator = ' - '; $append = ''; echo '<p class="pnpn">'.$prepend.$prevLink.$separator.$nextLink.$append.'</p>'; } /* end prev/next links */ ?>
Revision: 29531
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at July 31, 2010 06:46 by trepmal
Initial Code
<?php /* prev/next links */ if ($post->post_parent == 5) { /* in this case, I only want the subnav displayed on certain child pages */ $exclude = implode(',',array('984')); //exclude this page id $toplevel = 'title_li=&depth=1&echo=0&exclude='.$exclude; $siblings = $toplevel.'&child_of='.$post->post_parent; if (function_exists(pause_exclude_pages)) { pause_exclude_pages(); $links = ($post->post_parent) ? wp_list_pages($siblings) : wp_list_pages($toplevel); resume_exclude_pages(); } else { $links = ($post->post_parent) ? wp_list_pages($siblings) : wp_list_pages($toplevel); } $links = array_filter(explode("\n",$links)); foreach($links as $k=>$v) { if (strpos($v,'current_page_item') !== FALSE) { $current = $k; } } $total = count($links)-1; $prev = $current-1; $next = $current+1; if ($current == $total) $next = '0'; // if you're on the last page, next will be the first if ($current == '0') $prev = $total; // if you're on the first page, prev will be the last $prevLink = strip_tags($links[$prev],'<a>'); //remove the <li> tags $nextLink = strip_tags($links[$next],'<a>'); //remove the <li> tags function change_anchor_text($link, $newtext, $placement) { $pos1 = strpos($link, '>')+1; $pos2 = strpos($link, '<', 1); $anchortext = substr($link, $pos1, $pos2-$pos1); if($placement == 'before') { return str_replace($anchortext, $newtext.' '.$anchortext, $link); } else if ($placement == 'after') { return str_replace($anchortext, $anchortext.' '.$newtext, $link); } else if ($placement == 'replace') { return str_replace($anchortext, $newtext, $link); } } $prevLink = change_anchor_text($prevLink, ' < Previous Room ', 'replace'); /* link customization goes here */ $nextLink = change_anchor_text($nextLink, ' Next Room > ', 'replace'); $prepend = ''; $separator = ' - '; $append = ''; echo '<p class="pnpn">'.$prepend.$prevLink.$separator.$nextLink.$append.'</p>'; } /* end prev/next links */ ?>
Initial URL
http://trepmal.com/scripts/previousnext-links-for-pages-in-wordpress/
Initial Description
Initial Title
Previous / Next page links for WordPress
Initial Tags
wordpress
Initial Language
PHP