Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WordPress- Using custom Single.php to show 1 post, & paginate other posts below

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #194498
    Joseph Levin
    Participant

    Hello!

    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!

    -Joe

    #194924
    Soren
    Participant

    Hi Joe

    Could you maybe show me your query? Is it being paged?
    http://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query

    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 page

    #194925
    Joseph Levin
    Participant

    Soren,

    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!

    #194927
    Soren
    Participant

    I’ll post the code I used asap. I wasn’t trying to tease you with just a gif :)

    #194968
    Soren
    Participant

    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.

    #195002
    Joseph Levin
    Participant

    Soren,

    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:
    This Link

    I want to say thank you very much for doing as much as you have already!

    #195024
    Soren
    Participant

    Ah, shame that didn’t work but we’ll figure it out! Just downloaded your files now.

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘Back End’ is closed to new topics and replies.