0
votes

I'm not quite sure where I've gone wrong here. One of my template parts that I'm using for listing a bunch of posts of a certain category doesn't seem to be working.

Here is the code where I'm trying to get a template part named "content-offer.php" to display these posts, but it will not show any.

 <?php query_posts('cat=3'); ?>
            <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

                <?php static $count = 0;
                    if ($count == "4") { break; }
                else { ?>

                <?php get_template_part( 'content', 'offer', get_post_format() ); ?>

            <?php $count++; } ?>
            <?php endwhile;
            endif;
            wp_reset_query(); ?>

Here's what's actually within the template part file:

<div class="offer-box">
<div class="offer-left">
    <?php
        if(has_post_thumbnail()) {                    
        $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'full' );
        echo '<img src="' . $image_src[0]  . '" height="100%" height="auto"  />';
        } 
    ?>
</div>

<div class="offer-right">
    <h2 class="offer-title">
        <a href="<?php the_permalink(); ?>">
            <?php the_title(); ?>
        </a>        
    </h2>
    <p class="offer-text">
        <a href="<?php the_permalink(); ?>">
            <?php the_excerpt(); ?>
        </a>        
    </p>
    <a href="<?php the_permalink(); ?>">
        <div class="offer-cta">Claim now!</div>
    </a>
</div>

Take note that all my files are in the root folder of the wordpress theme currently, so it's surely nothing to do with sub directories.

I have another area that displays posts with the same method just fine, so I'm confused as to why this one doesn't work.

If anyone can help me out and point where I've gone wrong it would be greatly appreciated.

1
Do you have category whose id is 3?Ahmad Hassan
I do. If I use the other template part to display posts it works fine, but I need these ones to have a different layout, so I think the problem lies with the content-offer.php file.user9807138

1 Answers

0
votes

So, it looks like I had the "content-offer.php" file in the root wordpress folder, not the theme root folder. Oops.