• Hello. I’m wondering if anyone can help.

    What I want to do is show specific categories ina page template.
    For example:

    <!-- START LOOP -->
            <?php query_posts('category_name=catname'); ?>
            <?php if (have_posts()): while (have_posts()) : the_post(); ?>
    
            <div class="col-sm-6 col-md-4 contentBlock">
            <div class="thumbnail"><?php the_post_thumbnail('featured-image'); ?>
            <div class="caption">
                    <h3><?php the_title(); ?></h3>
                    <p><?php the_excerpt(); ?></p>
    
            <div id="edit"><?php edit_post_link(); ?></div>
    
            </div><!--/CAPTION -->
            <div class="col-9 btnArrowBlack"><p><a href="#">More</a></p></div>
            </div><!--/THUMBNAIL -->
            </div><!--/COL -->
    
            <?php endwhile; else: ?>
            <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    
            <?php endif; ?>
            <!-- END LOOP -->

    And this mixes in with my styles fine.
    So I have that in the template and it shows all posts from that category in the page template.

    What I don’t want to do is have to create a new template and put in the new cat id or slug everytime I want a new page.

    I just want to create a page based on one page template and show the categories.

    Can anyone help and hopefully this make sense?

    Thank you in advance, I will reply.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Have you reviewed the examples in a page of posts?

    Thread Starter meandco

    (@meandco)

    I have. Can anyone who understands this help me?

    Thank you

    How about using custom fields to hold the slug/title of the category that you want to feature on the page? That way, you could grab the custom field value in the page template and feed it into category_name.

    Longer term, you might also want to look at replacing query_posts() with pre_get_posts() as th later would be better way to achieve a custom query.

    Thread Starter meandco

    (@meandco)

    Thank you esmi

    That’s a lot for me on a monday morning. I’ll look into this.
    I also have another issue wether to start a new thread for it or not, maybe it feeds in with this issue.

    However I can add custom fields to a post, hopefully you could help me answer this then. I have a post with categories:

    <?php the_content(); ?>
    
                <div id="edit"><?php edit_post_link(); ?></div>
                <?php endwhile; ?>
    			<?php else: ?>
    
                <h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
    
                <?php endif; ?>

    I want all that within a div that has a border,
    when I create a new post I want it to display another bordered box, instead of that new post just going into that same box.

    Hopefully that makes sense, but this would come down to again having custom styles within the codex above.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Use Categories In A Page Template’ is closed to new replies.