Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wordpress Navigation

Status
Not open for further replies.

darryncooke

Technical User
May 6, 2009
308
US
So I am trying to create a pretty unique navigation structure in my site. Each page has left and right arrows fixed positioned on the left and side respectively. they are either for 1. Pagination between the page or controls for in page sliders.

the bump I have hit is when you are in a single post page I have an if then statement that serves the correct link. If there is a next post then the link will go there, if no next post then go to the next page.

the problem is I have a custom post type and regular post type. Each time you are in single.php the scripts defaults (as it should since its programmed that way) to the previous page or next page when it hits the first or last page in the loop.

Code:
 <?php
$prev_post = get_previous_post();
if($prev_post) {
   $prev_title = strip_tags(str_replace('"', '', $prev_post->post_title));
   echo "\t" . '<a rel="prev" href="' . get_permalink($prev_post->ID) . '" title="' . $prev_title. '" id="rightSide">&gt;</a>' . "\n";
                }
else 
echo "\t" . '<a rel="prev" href="[URL unfurl="true"]http://www.darryncooke.com/wordpress-test/profile/"[/URL] id="rightSide">&gt;</a>' . "\n";

$next_post = get_next_post();
if($next_post) {
   $next_title = strip_tags(str_replace('"', '', $next_post->post_title));
   echo "\t" . '<a rel="next" href="' . get_permalink($next_post->ID) . '" title="' . $next_title. '" id="leftSide">&lt;</a>' . "\n";
                }
else 
echo "\t" . '<a rel="next" href="[URL unfurl="true"]http://www.darryncooke.com/wordpress-test/the-work/"[/URL] id="leftSide">&lt;</a>' . "\n";
?>

I am not proficient enough in php to figure out how to nest this if then statement anymore that if in custom post type and there is no post before or after then output this HTML. If in standard posts then this should be the output.

Pretty much what I am looking for is say.

If first post then leftlink=x and rightlink=next
If last post then leftlink=previous and rightlink=y
if first custom post then leftlink=a and rightlinnk=next
if last custom post then leftlinnk=previous and rightlink=b

of course any post between first and last will serve leftlink=previous and rightlink=next.


Darryn Cooke
| Marketing and Creative Services
 
Ya,

the wordpress forum is pretty desolate. I looked at your link and I think it could be a direction towards what I am looking for.

to clarify I am just trying to create a nested if statement with 4 possible results.

result 1 is if the page you are on is the first post in the table
result 2 is if the page is the last post in the table
result 3 is if the page is the first of a CUSTOM post type in the table
result 4 is if the page is the last of a CUSTOM post type in the table

The custom posts are excluded from posts so there is no duplicate content. Is a nested if statement the best option?

Darryn Cooke
| Marketing and Creative Services
 
yes - a set of two nested ifs makes sense unless you are going to use different templates for your custom post type.

in the alternative you could hook the actions and insert your logic there.
 
I solved the problem by digging around the internets. In case anyone is ever interested here goes.

Code:
<?php

if (!$wp_query) global $wp_query;
if ( !$wp_query->query['paged']) {
  //ACTION FOR FIRST PAGE
} 
elseif ($wp_query->max_num_pages == $wp_query->query['paged']) {
  //ACTION FOR LAST PAGE
}
elseif ($wp_query->max_num_pages != $wp_query->query['paged'] and $wp_query->query['paged']) {
	//ACTION FOR ALL PAGES IN BETWEEN
	
}

?>

I used echo to output the 2 lines of code at each respective point.

Darryn Cooke
| Marketing and Creative Services
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top