Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Getting pagination work for a category template #299

Closed
mrcodefinger opened this issue Apr 8, 2015 · 7 comments
Closed

Getting pagination work for a category template #299

mrcodefinger opened this issue Apr 8, 2015 · 7 comments

Comments

@mrcodefinger
Copy link

Hi,
I've got a new question. For different categories I would like to have different layouts. So far so good, I created one:


    <?php if ( have_posts() ) : ?>

            <?php do_action('foundationPress_before_content'); ?>
            <?php query_posts('category_name=Allgemein'); ?>
            <?php while ( have_posts() ) : the_post(); ?>
                    <?php get_template_part( 'content', get_post_format() ); ?>
            <?php endwhile; ?>

            <?php else : ?>
                    <?php get_template_part( 'content', 'none' ); ?>

            <?php do_action('foundationPress_before_pagination'); ?>

    <?php endif;?>



        <?php if ( function_exists('FoundationPress_pagination') ) { FoundationPress_pagination(); }   else             if ( is_paged() ) { ?>
            <nav id="post-nav">
                        <div class="post-previous"><?php next_posts_link( __( '&larr; Older posts', '    FoundationPress' ) ); ?></div>
                        <div class="post-next"><?php previous_posts_link( __( 'Newer posts &rarr;', 'FoundationPress' ) ); ?></div>
            </nav>
        <?php } ?>

    <?php do_action('foundationPress_after_content'); ?>

    </div>
<!--    <?php get_sidebar(); ?>-->
</div>
 <?php get_footer(); ?>

The pagination is visible but not working... Does anyone allready had a similar case and could help me? Here a link to a sandbox: http://54.149.165.135
Thanks in advance
musicgabser

@mrcodefinger
Copy link
Author

Really no one has an idea???

@ghost
Copy link

ghost commented Apr 14, 2015

Hey musicgabser, let's start with creating a decent category template! Now you have just a page template named 'Blog' and a custom loop in it.
As you might have noticed, there's no category.php in the theme directory. archive.php will take care of your category and tag archives.
Here's a good read: https://codex.wordpress.org/Template_Hierarchy#Category_display
If you'd like to have different layout for categories, you could just copy the contents of archive.php to a new file and name it like: category-allgemein.php, and style it to your liking.
After this we could debug the pagination problem.

@ghost
Copy link

ghost commented Apr 14, 2015

Also, have a look at #286

@mrcodefinger
Copy link
Author

Hi Eccola,
thanks! I do not understand it unfortunately. I created a category-allgemein.php like you said but pagination isn't still working. The thing in the issue #286 I don't understand too, the more I learn, the more I realize how little I can so I will be thankfull for another hint.
Thx in advance
musicgabser

@ghost
Copy link

ghost commented Apr 20, 2015

@musicgabser , I see you have a working pagination on your category archives now, which is nice.

@ghost
Copy link

ghost commented Apr 21, 2015

@musicgabser, please, deactivate your Blog-template.
Settings > Reading > Frontpage > Latest posts

WordPress will now use the index.php for your frontpage blog view. Pagination should work now too.

If you want to filter the main query to show the posts from allgemeine category only,
you can do so using pre_get_posts action hook:

https://gist.github.com/corsonr/4647909
Copy and paste this to the end of your functions.php. Don't care about the name of the function.
Just update the ID of your category: $query->set( 'cat', 'ID' ); and you're good to go. Your frontpage blog will now only list posts from your favorite category.

@olefredrik
Copy link
Owner

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants