0

I am trying to get my category page content to show up in my custom page template, it returns everything I call, except for the actual page content when I am testing it. Hope this is somewhat clear :\ I've tried a bunch of things but nothing seems to get the job done so I have no real example code.

Thanks in advance :-))

1
  • 2
    Without seeing any code it is difficult to say what you are doing wrong. Commented Mar 20, 2015 at 23:20

1 Answer 1

0

If I understood correctly you need to show a specific category index on a page template, right?

If that's the case you can use WP_Query:

<?php /* Template Name: My Page Template */ ?>
<?php get_header(); ?>

    <!-- If you want to retrieve the page title, content, ... -->
    <?php the_post(); // set up the post ?>
    <h1> <?php the_title(); ?> </h1>
    <div class="content"> <?php the_content(); ?> </div>

    <!-- Then your category index -->
    <?php
    $category_id = get_cat_ID('YOUR CATEGORY NAME');
    $args = array(
        'cat'   => $category_id,
        'paged' => get_query_var('paged') ? get_query_var('paged') : 1
    );
    $cat_posts = new WP_query( $args );
    if($cat_posts->have_posts()):
        while($cat_posts->have_posts()):
            $cat_posts->the_post();
    ?>

        <div class="cat_post">
            <h1> <?php the_title(); ?> </h1>
            <div class="content"> <?php the_content(); ?> </div>
        </div>

        <?php endwhile; ?>

        <div class="pagination">
            <?php next_posts_link( __('Older Entries'), $cat_posts->max_num_pages ); ?>
            <?php previous_posts_link( __('Next Entries') ); ?>
        </div>

        <?php wp_reset_postdata(); ?>

    <?php endif; ?>

<?php get_footer(); ?>

Remember to change YOUR CATEGORY NAME accordingly.

1
  • thanks a lot for your reply :D That indeed should do the job, and it did. I had already fixed it, there was a minor mistake in my code and after staring at it for too long I was no longer able to recognize it.
    – magin
    Commented Mar 22, 2015 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.