previous post link not working
-
I’m trying to create a custom navigation bar and I don’t want the previous post’s title to be in the navigation buttons,
Instead I just want the << , < , > and >> symbols to appear
I tried using this in the page.php<?php previous_post_link($format, < , $in_same_cat = false, $excluded_categories = ''); ?>But it keeps crashing my site,
what am I doing wrong?
-
The second parameter (the less than sign) has to be a string, so put quotation marks (apostrophes) around it, like this:
<?php previous_post_link($format, '<' , $in_same_cat = false, $excluded_categories = ''); ?>Thanks! though I still don’t think I’m using the code correctly.
How do I get this to work in a tag?Sorry it ate my code
How do I get this to work in a
<a href= > tag?What did you set $format to? Try this in place of $format:
<?php previous_post_link('%link', '<' , $in_same_cat = false, $excluded_categories = ''); ?>Here’s how I made the the navigation button for the “First Post” button
<a href="<?php echo Get_First_permalink(); ?>"> <div class="navButton"> <h5> << </h5> </div> <!--- End of navButton---> </a>and here’s how I have it for last post
<div class="navButton"> <h5> <?php previous_post_link('%link', '<'); ?> </h5> </div> <!--- End of navButton--->It works but it doesn’t take to my styling like the first one.
so if I do this will it work?
<a href="<?php previous_post_link('%link', '<' , $in_same_cat = false, $excluded_categories = ''); ?>"> <h5> < </h5> </div> <!--- End of navButton---> </a>I would actually put your navButton DIV for your First Post outside (i.e., around) the anchor link, so the link is contained within the DIV.
Then, for the previous post link, try this:<div class="navButton"> <?php previous_post_link('<h5>%link</h5>', '<'); ?> </div>Your code works!
but not exactly like how I need it to.
The reason I put the anchor link around the first post div is so that the entire navigation button is a link and clickable as opposed to how I have the last post div in which only the character (‘ < ‘) is clickable.
which is why im trying to get a code that will interact with the anchor link code like the function I have do
Ah, OK, then try this if you need the DIV inside the link for the last post.
<?php previous_post_link('<div class="navButton"><h5>%link</h5></div>', '<'); ?>I plugged it in your code but it still does the same thing where only the character is linked and not the whole button. Its still behaving the same way
Which baffles me.
That is how the function actually works unfortunately from what I can gather.
The %link is essentially the < a > wrapper for the title/label you set it to on the second parameter; so regardless of what you wrap around it you will still get
<a href="permalink">%title</a>Shoot! so then there is really no way to do this?
Wait, I wrote that wrong. Try this:
<?php previous_post_link('%link', '<div class="navButton"><h5><</h5></div>'); ?>You may need to use the escape code for “less than” instead of the actual less than character inside the h5 tags.
@crouchingbruin you would get a huge mess on your hands if you used that code since you aren’t using the HTML entity for the less than symbol. It may think that is the beginning of a tag so its best to try and use the HTML entity equivalent: < or < so as not to break the theme with weird markup.
@mot13 yeah, I could be wrong but like I said from my reading. I know there is a core patch that was submitted to just get the previous/next post link but not fully sure if and when that will make it.
That’s why I added the note to use the HTML escape code for “less than” at the end of my message. I tried entering the code itself into the comment, but as you can see, this support software changes it to an actual less than sign.
GREAT SCOTT! It worked! @crouchingbruin you magnificient genius!
glorious working code
<?php previous_post_link('%link', '<div class="navButton"><h5><</h5></div>'); ?>I assume this same method will work for the next post link as well
I didn’t have to use the escape code but I think I’ll do it anyway just to avoid errors
The topic ‘previous post link not working’ is closed to new replies.