- This topic is empty.
January 28, 2015 at 10:11 am #194498
I am using a plugin that allows me to specify a custom single.php template for single posts. I have modified the custom single.php file to, after it has displayed a “main post” at the top of the page, to then run another query to show all posts having the same category as the “main post”, below it. Let’s call them the “other posts”. So far, everything works fine, but I cannot get pagination to work for the “other posts”. I can get next/prev links to format their URL’s correctly, but when I click on the links, only the “main post” and the first set of “other posts” show, based on my posts-per-page variable.
I do not wish to use any sort of pagination for the “main post”, but I do want to be able to paginate the “other posts”.
For example, say the slug for the main post is “foo”.
To see that post using its custom single.php file, the URL would be something like: http://mysite.com/foo .
What I am hoping to achieve, if possible, is that when someone clicks on the NEXT PAGE link, and the URL changes to:
http://mysite.com/foo/page/2, then the “main post” will show with the appropriate subset of “other posts” below it.
I don’t know if I’m facing a redirect issue (because the URL keeps popping back to http://mysite.com/foo when I click on the NEXT PAGE link), or what.
Funny thing is, I can do the very same sort of thing on a custom PAGE and things just work. What I mean by this is I can have a custom page (that shows its content at the top of the page) with a list of posts having a specific category beneath. Then the pagination works just fine.
I’m at a loss as to explain the difference.
I was hoping someone could direct me to a similar case with some example code I could follow in order to accomplish what I need to do.
Any light anyone could shed on this problem would be greatly appreciated. Thank you very much!
-JoeFebruary 2, 2015 at 1:00 pm #194924
Could you maybe show me your query? Is it being paged?
I’ve done something similar and it worked fine. Here’s a gif: http://i.giphy.com/lXiRpjAyZcvc9fM3K.gif
single post title is “Post 6”
slug is “post-6”
custom query underneath
3 posts per pageFebruary 2, 2015 at 1:28 pm #194925
At the moment I don’t have the single post template I was working on, as I’d given it up in frustration, hoping to table it for another day.
I have been to the Codex page you’d described and thought I’d been following its logic correctly, but apparently that wasn’t the case.
The GIF file you’ve shown is what I’m looking to do. Assuming you followed the steps in the Codex, I’ll remake my single post template as simply as possible from scratch using the examples from the Codex page you provided and see how that works for me.
I would really appreciate it if you could paste the logic from your example from the GIF file.
Thank you very much for responding to my post and for your help!February 2, 2015 at 1:53 pm #194927
I’ll post the code I used asap. I wasn’t trying to tease you with just a gif :)February 3, 2015 at 8:30 am #194968
Try this, Joe http://bit.ly/1vqejRD
Place this code in your single.php file, below the main single.php loop.
We’re grabbing the first category of the current single post and returning other posts from this cat. The only thing you need to edit is how many posts per page.
Let me know how you get on when you have a play.February 3, 2015 at 10:56 am #195002
After looking at the code in your bit.ly link, I realized that I had done almost 100% the same thing, but with different output formatting. Regardless, I removed my code, slapped in yours in its place, and it worked as expected- sadly.
What I achieved previously was the same as what happened when I tried your code- the pagination links generated with the proper URL but when clicking on the link for the next set of posts, all that I got was the original page (i.e., the URL did not show /page/2 in it). This is what happened before.
It seems there is some sort of redirect happening, but I’m not sure what to do to test for it.
I am doubtful that the issue is within the custom single.php file now. But it may be worth a look. If you would be able to take a look at it, I would really appreciate it. You can get a zipfile of the code snippets via:
I want to say thank you very much for doing as much as you have already!February 3, 2015 at 1:27 pm #195024
Ah, shame that didn’t work but we’ll figure it out! Just downloaded your files now.
- The forum ‘Back End’ is closed to new topics and replies.