darryncooke
Technical User
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.
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
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">></a>' . "\n";
}
else
echo "\t" . '<a rel="prev" href="[URL unfurl="true"]http://www.darryncooke.com/wordpress-test/profile/"[/URL] id="rightSide">></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"><</a>' . "\n";
}
else
echo "\t" . '<a rel="next" href="[URL unfurl="true"]http://www.darryncooke.com/wordpress-test/the-work/"[/URL] id="leftSide"><</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