WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Pagination, Not sure what to do (43 posts)

  1. jimmyt1988
    Member
    Posted 4 years ago #

    I have set my page up like this. Perhaps it sucks in terms of code layout, but it's working great.

    Website:
    http://www.jamestrusler.co.uk

    Code:
    http://jamestrusler.co.uk/wp-content/themes/jamestrusler/helpMe.txt

    I have been struggling to add a pagination feature.

    In the code I have written "<!--PAGINATE THESE-->" At that point, can anyone tell me what must be done to paginate those posts. I want to not show more than 5 posts within those loops. and have something like page 1 out of 3.

    I have been trying for ultra long now.

    Thanks in advance.

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    Have you tried using posts_nav_link?

  3. jimmyt1988
    Member
    Posted 4 years ago #

    Yes, exactly what I have been using. As you can see, I got it to work for the "IF POST IS IN A CATEGORY" section. but I cant get it to work for the "//IF PAGE IS ONE OF ARRAY PAGENAMES" section :) Any ideas?

    So first problem is limiting the amount of pages listed to 7.
    Second is getting a link to show up only on the last post of that page. Which links to another page which shows only 7 posts and then has a link to another page etc.

    thanks for any help btw.

  4. esmi
    Forum Moderator
    Posted 4 years ago #

    I'm not 100% sure if you can successfully paginate when using get_posts - mainly because I don't think I've tried it myself. You could try replacing:

    $lastposts = get_posts('category=' . $i);

    with:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $lastposts = get_posts('category=' . $i . '&posts_per_page=5');

    and see if that helps.There are also some tutorials on multiple Loops in the Resources section on http://codex.wordpress.org/The_Loop#Multiple_Loops You might find some ideas in there.

  5. jimmyt1988
    Member
    Posted 4 years ago #

    I have tried this:

    http://jamestrusler.co.uk/wp-content/themes/jamestrusler/helpMe2.txt
    find : /*PROBLEMMM ISSS HEREEEEEE*/

    But it returns no posts. Any ideas why is_page isn't working. I'm going crazy I think, I can't solve simple thing :S.

    If you visit my page it returns 4 page names. If that helps at all lol :S.

    EDIT: I now have a working next button too. But because there is problem displaying the posts It does not work. view site for visual.

    EDIT: If I replace:

    if (is_page($pageNames[$i])) {?>

    with

    if (is_page($pageNames[$i])) continue;?>

    It outputs a post from 1 category 8 times.. I don't get it :D

  6. Shane G.
    Member
    Posted 4 years ago #

  7. jimmyt1988
    Member
    Posted 4 years ago #

    It's not what I'm looking for, but thanks. Esmi was on the right lines. Perhaps She/He will know where I'm going wrong.

  8. jimmyt1988
    Member
    Posted 4 years ago #

    I'm still stuck. 5 hours overall of trying. *cries*. Please refer to previous posts for information on my problem. I'm so grateful for the help.

  9. esmi
    Forum Moderator
    Posted 4 years ago #

    Can you confirm whether the code at http://jamestrusler.co.uk/wp-content/themes/jamestrusler/helpMe.txt is still being used? If not, drop a copy of the current file into the WordPress pastebin and post the pastebin url here. I'll try and have another look at it.

  10. jimmyt1988
    Member
    Posted 4 years ago #

  11. jimmyt1988
    Member
    Posted 4 years ago #

    I'm kind of stuck now because i'm scared to touch my site just in case you're checking it out. lol.

    Any thoughts or should I just scrap that whole part and be happy with what i coded before *looks with puppy eyes* ?

  12. esmi
    Forum Moderator
    Posted 4 years ago #

    I'm looking at the code again now. Is the is_page() conditional intended to check for a specific Page in that custom query on line 121? Only query_posts('category=' . $i . '&posts_per_page=1'); is going to pull in Posts not Pages. Try replacing:

    if (is_page($pageNames[$i])) {?>

    with:

    if ($post->post_title == $pageNames[$i])) {?>

  13. jimmyt1988
    Member
    Posted 4 years ago #

    Ah, it is suppose to pull in certain posts if the website is currently on a certain page.

    for example:

    If it's page "blog", show only Blog posts. etc. (I got this part to work. It's changing that whole loopy part to succesfully give me a goto next page link thats the problem)

    what i needed was, show only 1 Post on the first blog page, then have a next button that leads to another page with only 1 post. ie... pagination. If I wrote too many amazing blogs, I need them to go onto archive pages.

    (infact i want it to be 7 posts per page, but i can only test with 1 post per page, coz only 2 posts exist :) )

    P.S I just changed that line. Removed the extra ) that was there. It shows the same result.

    :(

  14. esmi
    Forum Moderator
    Posted 4 years ago #

    it is suppose to pull in certain posts if the website is currently on a certain page.

    Aha! In that case, the logic flow is incorrect. You need to test which page you're on before you set up the custom query . Also, rather than loop through your Page array, you could try using:

    $page_title = wp_title('',false,'');
    if( in_array($page_title, $pageNames) ) :
    [ set up query ]
    [ do stuff ]
    endif;

    What should happen if you're not on one of the pages in your array? Anything?

    Elsewhere, I'd suggest incorporating <?php wp_head();?> just before </head> and <?php wp_footer(); ?> just before </div></body>. Both are used by the core (and many plugins) to initiate specific actions.

  15. vtxyzzy
    Member
    Posted 4 years ago #

    Sorry I'm coming to the party late, and this may not help, but you can paginate any array using the code in this template.

  16. jimmyt1988
    Member
    Posted 4 years ago #

    Thankyou Esmi. You always save my ass.

    I "did a cowboy" (I heard somoene use this phrase.. apparently it means you get something to work then leave it alone but it might be the worst way... I cant believe I just explained that. *sighs*) on my website and got it to work. I was so happy, I completely forgot about including the default head and footer stuff..

    I knew there was an easier way of doing if page then do this post. But I couldn't be bothered to check it out after I had got it to work.

    You know i'll post again but you've got me started. hehe.

    Cheers once again!!! You're a credit to wordpress!

  17. esmi
    Forum Moderator
    Posted 4 years ago #

    Glad to hear that you've negotiated this particualr bump. :-)

  18. jimmyt1988
    Member
    Posted 4 years ago #

    vtx.. before I look at your page, Ill ask:

    what does that do: wp_title('',false,'');

    I have got this... But tbh, It's going over my head. I wish I didn't suck so much.

    $page_title = wp_title('',false,'');
                                    if( in_array($page_title, $pageNames) ) :
                                    query_posts('category=3,4,5,6&posts_per_page=1');
                                    while (have_posts()) : the_post();?>
                                    <div class = "leftSideWrap">
                                        <h2><?php the_title(); echo " <small>"; the_time(get_option('date_format')); ?></small></h2>  
    
                                        <div class = "top"></div>
                                        <div class = "middle">
                                            <div class = "cornerImage"></div>
                                            <?php the_content(); ?>
                                            <div class = "commentSeperateLine dotted main"></div><br />
                                            <p>
                                                <a href="<?php comments_link(); ?>">
                                                    Add / View Comments to this post</a> -
                                                     <?php comments_number('There are currently no comments', 'There is 1 comment', 'There are % Responses' ); ?>
    
                                            </p>
                                        </div>
                                        <div class = "bottom"></div>
                                    </div>
                                    <?php
                                    endwhile;
                                    endif;
                                    ?><?php posts_nav_link(); ?>

    P.S I have no idea what a bump is. P.S, what? lol

    P.S

    I have put that function in my functions.php that vtxyzzy supplied.

    Added the code from the <head></head> part of the header.php, I am seeing some next and back buttons. lovely lovely but I get this:

    Warning: Cannot modify header information - headers already sent by (output started at /customers/jamestrusler.co.uk/jamestrusler.co.uk/httpd.www/wp-content/themes/jamestrusler/functions.php:36) in /customers/jamestrusler.co.uk/jamestrusler.co.uk/httpd.www/wp-includes/pluggable.php on line 868

    When I press the next page button.. hmmm.

  19. jimmyt1988
    Member
    Posted 4 years ago #

    Ok,

    This is my current code.

    You may be thinking, why has he not listened to our posts.

    I have, I have run through them.

    I'm not quite grasping them.

    current code:
    http://wordpress.pastebin.com/p4vvDNak
    current site:
    http://www.jamestrusler.co.uk

    What I thought my code is doing is:

    1. If the page is blog, get posts from the category id I specify.
    2. While there is posts for that category, for each one, display the content. And when you reach the limit (1), then stop outputting.
    3. After you done all the for each ones, Stop the while loop. Then display a link to another page that displays the remaining archived posts for that category.

    The problem is, I cannot comprehend just how it all works.

  20. esmi
    Forum Moderator
    Posted 4 years ago #

    Warning: Cannot modify header information

    You've got a leading or trailing blank line in one of your files - possibly functions.php.

    Solving "headers already sent" warnings

    (Oh - and I meant "bump" as in hitting and then getting over a bump on the road to getting your theme up & running :-) )

  21. jimmyt1988
    Member
    Posted 4 years ago #

    firstly, you're a genius. You must have absored the wordpress codex.

    It's kind of unnatural.

    Secondly, the phrase "bump" is worse than the "cowboy" phrase. ^_^

    Thirdly.. And this is the exciting part:

    http://jamestrusler.co.uk/

    Is now returning some junk with the current code.

    http://wordpress.pastebin.com/Ta5341Tu

    Unfortunately, the code has gone well out of my range. I havent just bummed out on it, I really read it and don't understand it :S.

    What's your radar picking up esmi. I wish I could understand this stuff. It's using the stuff vtx had recommended.. literally because it is the closest I have been.

    I wonder what the wordcount is for "stuff" in this post ^_^

    P.S

    I see a pattern.. Its posting one comment from each section.. *reads over code*... *squeezes brain juice out*

  22. vtxyzzy
    Member
    Posted 4 years ago #

    Can you describe the problem a little more? I can't see any pagination on your site, so I don't have a clue what is wrong.

  23. esmi
    Forum Moderator
    Posted 4 years ago #

    The code has changed completely since I last looked at it. Which bit is outputting junk?

  24. jimmyt1988
    Member
    Posted 4 years ago #

    Ok, here is my site at the moment:
    http://www.jamestrusler.co.uk

    with the code (search for "if ($mypages)"):
    http://wordpress.pastebin.com/6BgM1Nvg

    I had to change it to its working state before because I didn't want the site to be down all day. So here it is, in non-functioning state.

    this is what i want:

    I want a loop that says:

    if the page is blog, display posts i associate with blog page.
    if there is more than 5 posts on the blog page, create a link at bottom that says goto next page of blog posts.

    In summary, it would be an archive. I only want the blog / poetry / picture / music page to display maximum of 5 posts, if there are more, I want them to archive.

    I thought this was called pagination.

    What you were seeing earlier was this (search for "/*IF PAGE IS ONE OF ARRAY PAGENAMES*/"):

    http://wordpress.pastebin.com/kqrr1EN5

    This code has no pagination but works great. If you would like to see this code in action then please just say.

    I'm really stuck on what to do :S .

  25. vtxyzzy
    Member
    Posted 4 years ago #

    I see the problem: the last page links are not formed properly for some reason. Please post your functions.php to the pastebin so I can take a look.

    Sorry for the trouble.

  26. jimmyt1988
    Member
    Posted 4 years ago #

    functions code:
    http://wordpress.pastebin.com/N1WDfwab

    Please dont say sorry. You are all working your ass of and im so happy you're all helping. Thanks for your trouble.

    Side note: The posts showing do not only belong to do blog page, it is showing 1 post from each category. I need it to display blog posts on blog page, poetry posts on poetry page.. etc.

    You can see from my array at top of page which category belongs to which page:

    $i = 3;
        $pageNames[$i++] = "blog";
        $pageNames[$i++] = "music";
        $pageNames[$i++] = "poetry";
        $pageNames[$i++] = "pictures";
  27. vtxyzzy
    Member
    Posted 4 years ago #

    No, I really am sorry - I had only used that function on pages other than the home page, and it works there. I will rework and post a revised version.

    Question: does the 'Music' page use a template? It seems to direct to index.php.

    As for the posts not showing on the correct page, I will leave that for later.

  28. jimmyt1988
    Member
    Posted 4 years ago #

    every part of the website comes from the index page.

    The working version originally went through my array at the top and just output posts which I assigned to categories I made.

    Is that the info you needed?

  29. vtxyzzy
    Member
    Posted 4 years ago #

    OK - I think that I posted a link to an older version of the code. Please replace that function with the one found here.

  30. jimmyt1988
    Member
    Posted 4 years ago #

    Done.

    Now i need to show blog posts on blog page, poetry posts on poetry page etc.

    Is there any way I can help?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags