0

My categories are set up to display as a grid using the following code (category.php):

get_header(); ?>
<div id="content" class="site-content inner">
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">


                    <!-- START OF THE FLEX CONTAINER, THE UNORDERED LIST -->
            <ul class="grid-wrap">


                <!-- WP LOOP STARTS HERE -->
                <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

                    <!-- LIST ITEM FOR EACH POST -->
                    <li class="grid-item">

                        <!-- FEATURED IMAGE FOR THE POST -->
                        <p>
                            <?php if ( has_post_thumbnail() ) : ?>
                                            <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'small' ); ?></a>
                            <?php endif; ?>
                        </p>

                        <!-- POST TITLE -->
                        <h2 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>




                        <?php endwhile; ?>
                        <?php endif; ?>

                    <!-- END OF THE LIST ITEM -->
                    </li>

                <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>></div>

            <!-- END OF THE FLEX CONTAINER -->
            </ul>

        </main><!-- #main -->
    </div><!-- #primary -->

<?php
get_sidebar();
get_footer();

This is fine when filtering by category. I also want to have pages that shows the same category after some intro text, i.e.:

(header)

Some into text here

Grid display of posts (footer)

These pages will be linked from my header bar, not accessible through filtering. I've got as far as creating a template for each page, but how do I edit the category loop system to display just one category when it's on a page, not on the category's page? (if that makes sense).

I'm a total newbie to php and the wp loop, and am struggling with this. Thanks.

2
  • You say "how do I edit the category loop system to display just one category when it's on a page", which category are you referring to? You want a page to show an specific category?
    – Alvaro
    Commented Jan 4, 2017 at 20:28
  • Yes, sorry if I wasn't clear. I want a page (called Basics) to show the following: Title, Text description, All posts from 'basic' category, displayed in the grid that my category.php uses Effectively, I want to show the category, but in a page, after intro text. And so the URL is to the page (.com/basics) NOT to the category (.com/category/basics)
    – ts123
    Commented Jan 4, 2017 at 20:30

1 Answer 1

0

Sorted it...

get_header(); ?>
<div id="content" class="site-content inner">
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">

            <p class="sixhundred">Intro.</p>

                    <!-- START OF THE FLEX CONTAINER, THE UNORDERED LIST -->
            <ul class="grid-wrap">


                <!-- WP LOOP STARTS HERE -->
                <?php if ( have_posts() ) :

                query_posts( "category_name=basic-skills" );

                while ( have_posts() ) : the_post(); ?>

                    <!-- LIST ITEM FOR EACH POST -->
                    <li class="grid-item">

                        <!-- FEATURED IMAGE FOR THE POST -->
                        <p>
                            <?php if ( has_post_thumbnail() ) : ?>
                                            <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'small' ); ?></a>
                            <?php endif; ?>
                        </p>

                        <!-- POST TITLE -->
                        <h2 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>




                        <?php endwhile; ?>
                        <?php endif; ?>

                    <!-- END OF THE LIST ITEM -->
                    </li>

                <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>></div>

            <!-- END OF THE FLEX CONTAINER -->
            </ul>

        </main><!-- #main -->
    </div><!-- #primary -->

<?php
get_sidebar();
get_footer();

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.