• Resolved vgrch

    (@govaleriia)


    Inside default category.php I have a sidebar with custom post types. I need to add pagination in order to enable infinite scroll. I tried at least 3 different snippets from the web and none did the job. Maximum result I get is the link to the page 2 of the current category.

    My code is below, site – http://www.jcvergara.com/category/videos-audios/. Thanks for any suggestions.

    <?php
    $temp = $wp_query;
    $wp_query = null;
    $wp_query = new WP_Query();
    $wp_query->query('showposts=2&post_type=external_article'.'&paged='.$paged);
    while ($wp_query->have_posts()) : $wp_query->the_post();
    ?>
    <div class="item <?php echo $tag_list; ?>">
        <div class="item-title">
            <h4><?php the_title(); ?><br/>Article on other sites</h4>
        </div>
        <div class="item-img">
            <a href="<?php echo get_post_meta( get_the_ID(), 'link_to_the_article', true ); ?>" target="_blank">
                <?php $image_ext = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
                <div class="thumb" style="background-image: url('<?php echo $image_ext[0]; ?>'); "></div>
            </a>
        </div>
    </div>
    <?php endwhile; ?>
    <nav id="ext-page-nav">
        <?php next_posts_link('Older &raquo;') ?>
    </nav>
    <?php
        $wp_query = null;
        $wp_query = $temp;  // Reset
    ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • Seems you are attempting to have the “effect” of paging only within the sidebar? While the rest of the category display remains the same? Is that right?

    If so, I don’t think it can be done quite that way. We probably need to see the entire category.php to figure it out. If it’s a really long file you could put it on pastebin.com and post the link here

    Thread Starter vgrch

    (@govaleriia)

    Hi santeven,
    Thanks for the reply.

    What I’m trying to do is to have all content on the page to be loaded by scrolling. Don’t ask me why, I wouldn’t recommend that design in the first place. But I gotta make it work.

    Infinite scroll for the category itself is working (you can’t see it because there is not enough posts). I only need to add pagination for custom post types to make scrolling work for them too.

    I put the full category.php code here: http://pastebin.com/xdQFEWXN.

    As an alternative, I wanted to try to create the template for this layout as a page, passing the current category as GET parameter. Do you think it will work outside of category.php?

    Thanks.

    Thread Starter vgrch

    (@govaleriia)

    Actually, while I was trying to fill up the page with post as an illustration of how it’s supposed to be working, it turned out that it’s already working as I wanted it to work.

    I have no clue why though, as the infinite scroll is supposed to take the content of the next load from the pagination links and pagination links for the sidebar are not correct, so it’s not supposed to be loading what it actually loads.

    Anyway, thanks for your time. )

    You are welcome … Seems like you attempt a contradiction of terms… if it’s paged its not infinite scroll … if it’s infinite scroll, it’s not paged … Am I missing something? I still don’t know exactly what you mean by:

    all content on the page to be loaded by scrolling

    I think one problem is on line 91. Shouldn’t it be posts_per_page=-1 to show all on one page? which is MY definition of infinite scroll? you just keep scrolling until you see all the posts and there is no page/2 (of that set of posts)

    From reference: http://codex.wordpress.org/Class_Reference/WP_Query

    posts_per_page (int) – number of post to show per page (available with Version 2.1, replaced showposts parameter). Use ‘posts_per_page’=>-1 to show all posts

    And before line 48 I think you need the same posts_per_page=-1 concatenated to the current query…

    from http://codex.wordpress.org/Function_Reference/query_posts :

    Preserving Existing Query Parameters

    If you want to preserve the original query parameter information that was used to generate the current query, and then add or over-ride some parameters, you can use the $query_string global variable in the call to query_posts().

    ( I modded this next sentence and code for your case)
    For example, to add the parameter without affecting the rest of the query string, you could place the following before The Loop:

    global $query_string;
    query_posts( $query_string . '&posts_per_page=-1' );

    I wanted to try to create the template for this layout as a page, passing the current category as GET parameter. Do you think it will work outside of category.php?

    To understand this I think you might want to study the template heirarchy: http://codex.wordpress.org/Template_Hierarchy

    I don’t think you ever need to pass in as GET … instead use template tag like get_the_category()
    http://codex.wordpress.org/Function_Reference/get_the_category

    And also on line 29 you could use some template tag +conditional instead of $_SERVER[‘REQUEST_URI’] … then again if it works it works.

    Hope I haven’t misunderstood too much, If I have, hopefully the references themselves will help you sort it. Good Luck for now

    Thread Starter vgrch

    (@govaleriia)

    Hi santeven,

    Thanks for your explanations, sorry it took me so long to reply.

    All you are saying is reasonable and useful but I had to stick to what I created initially as I probably didn’t explain it good enough.

    As for infinite scroll + pagination, I needed to have pagination links working to pass them to infinite scroll script, this is how it knows what to load next.

    In any case, I managed to make it work. Thanks for your time. )

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom post pagination inside’ is closed to new replies.