• I can’t seem to get my custom page template to display posts right.

    So far I have this in there and it’s just displaying the title of the category.

    <?php get_header(); ?>
    <ul><?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <li>
    	<h3><?php the_title(); ?></h3>
    </li>
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
    </ul>
    
    <?php get_footer(); ?>

    Am I doing this wrong?

    The pages name is page-28.php which is the id of the category I’m trying to display on this page.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter MaTaX91

    (@matax91)

    Okay well I figured out how to get the categories to display on this page, however it does not display my custom post types that area also under that same category. How can I tell WordPress to also display post types of that category there?

    Moderator bcworkz

    (@bcworkz)

    You should hook the ‘pre_get_posts’ action. In your hook function, use a conditional tag or something to ensure you only modify the query you want, as ALL queries go through this action. Once the correct query is identified, set the ‘post_type’ query variable equal to an array containing ‘post’ and the name of your custom post type. You can also set the categories this way, not sure what you’re doing now, but it makes sense to do everything in one place.

    Here’s some useful resources for doing what I describe:
    Plugin_API/Action_Reference/pre_get_posts
    Class_Reference/WP_Query#Type_Parameters

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom page template’ is closed to new replies.