• Resolved arturocivit

    (@arturocivit)


    Hi there, I have a doubt with something that is not working as it should be, or maybe I’m confused to not think clearly and find the response, I have a blog.php document where I call my blog articles under the “blog” category, I call all the articles under that category with this:

    <?php query_posts('cat=9&order=DSC&showposts=14&paged='.get_query_var('paged')); ?>

    Then I have all my regular loop, then, those articles link to my single.php file where I have the regular loop:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php the_post_thumbnail('full', array('class' => 'img-responsive')); ?>
    <h1><?php the_title(); ?></h1>
    <?php the_content(); ?>
    <?php endwhile; ?>
    <?php else : ?>
    <?php endif; ?>

    But then if I add a pagination links the pagination will “call” posts that are not inside the blog category, as pagination I’m using

    <?php previous_post('? ? %', '', 'yes'); ?> <?php next_post('% ? ? ', '', 'yes'); ?>

    I just want to paginate only thru my “blog” category articles, wondering if there’s a way to filter the pagination by category?

    Thanks everybody!

    A.

Viewing 4 replies - 1 through 4 (of 4 total)
  • This topic is oft confused. Pagination and Next Post/Prev. Post links do not work the same. Single.php should take you to the next or prev. post (chronologically). A Page of Posts, such as a Category, Tag, or Archive Page, may include Pagination.

    What you want to do is create a custom category page template based on your theme’s category page template.

    https://codex.www.ads-software.com/Category_Templates

    With a good theme, it is often as simple as just copying category.php and then renaming to, for example, category-news.php then uploading the new file (for the category with a slug of ‘news’). You can then with proper HTML/PHP/CSS/JS fully change this page.

    Thread Starter arturocivit

    (@arturocivit)

    Hi there, thanks so much for your explanation, however, seems like I didn’t explain myself in the right way, sorry about that and let me try better.

    As you know, I have a blog.php page where all my blog posts are being called from, so here: Example you’ll see the page that displays only posts from the blog category, I do this by using this loop:

    <?php query_posts('cat=9&order=DSC&showposts=14&paged='.get_query_var('paged')); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php the_title(); ?>
    <?php echo get_the_date(get_option('date_format'));?>
    <p><?php echo substr(strip_tags($post->post_content), 0, 250);?></p>
    <a class="btn btn-default" href="<?php the_permalink() ?>">Read More <i class="icon-angle-right"></i></a>
    <?php endwhile; endif; ?>

    You can see that I’m just calling category number 9 which happens to be the “blog” category. So far everything is good, now, when you click a title you go to the regular single.php page and everything looks great there, as I mentioned in my previous message, my loop is fairly regular:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php the_post_thumbnail('full', array('class' => 'img-responsive')); ?>
    <h1><?php the_title(); ?></h1>
    <?php the_content(); ?>
    <?php endwhile; ?>
    <?php else : ?>
    <?php endif; ?>

    My client asked me to, from that page, move thru posts without the need to go back to the blog page, so, at the bottom of each single post, instead to have a pagination like, 1-2-3-4 etc or First Next Previous Last he wants to have the next title post link and the previous title post link, problem here is I’m calling ALL categories and not only the blog one:

    <?php previous_post('? ? %', '', 'yes'); ?> <?php next_post('% ? ? ', '', 'yes'); ?>

    But now thanks to you I investigated a little further and found its parameters, the 3rd one is same category, that one with value TRUE will call one articles belonging to the blog category, I used this:

    <?php previous_post_link('%link', '%title', TRUE); ?> &bull; <?php next_post_link('%link', '%title', TRUE); ?>

    So with this i think my question gets resolved, hope this helps someone else with the same problem in the future.

    Thank you buddy!

    Glad you got it working. Please mark this post as resolved as that is a great way for folks to find this!

    Thread Starter arturocivit

    (@arturocivit)

    There you go, thanks!!

    Arturo

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Filtering Pagination on single.php?’ is closed to new replies.