1

I'm having trouble displaying posts from a single category on the homepage the way I want them to appear. The theme I'm using uses a 3 column layout for the homepage and a content-sidebar layout for the blog page.

Basically I want the homepage to display exactly like the blog page, but include the slider. So what I did was just copy the code from category.php and pasted it into a new custom page template titled hompage.php and set that as my homepage.

But for some reason its not displaying any posts and I have no idea why.

category.php

<?php
/**
 * The template for displaying Category pages.
 *
 */
$settings = get_option( "ntl_theme_settings" );
get_header(); ?>



        <div class="outer">
                <div class="frameset container clear">
                        <?php if ($settings['ntl_disable_audio'] != 'off'){     ?>
                        <div class="clear headtop">    
                                <div class="page-title" >
                                        <h1 class="vfont"><?php single_cat_title(); ?></h1>
                                </div>

                                <?php echo lets_get_albumselector(); ?>                                        
                                <?php echo lets_get_musicplayer(); ?>

                        </div>                         
                        <?php } else { ?>

                        <div class="clear headtop" style="height: auto;">                                      
                                <div class="page-title" style="width: 100%; margin-bottom: 40px;">
                                        <h1 class="vfont"><?php single_cat_title(); ?></h1>
                                </div>                 
                        </div>

                        <?php } ?>

                        <?php if (!$settings['ntl_show_timer']) { ?>
                                <div class="cdowntop"> 
                                <?php echo get_for_timer(''); ?>
                        <?php } else { ?>
                                <div class="cdownnone">
                        <?php } ?>

<div class="bodymid hfeed hpage">
        <?php if ($settings['ntl_disable_audio'] != 'off'){     ?>
                <div class="drawer">&nbsp;</div>
        <?php } ?>
        <div id="main">
                <div id="content" role="main">
                        <div class="container clear">
                                <div class="grid8 first">              
                                        <div id="content" role="main">
                                                <?php get_template_part( 'loop', 'category' ); ?>                              
                                                <?php adminace_paging(); ?>
                                        </div>
                                </div>
                                <?php get_sidebar(); ?>
                        </div>
                </div>
        </div>
</div>
</div>
<?php lets_make_carousel(); ?>


<?php get_footer(); ?>

loop.php

<?php
/**
 * The loop that displays posts.
 *
 */

?>

<?php /* If there are no posts to display */ ?>
<?php if ( ! have_posts() ) : ?>
        <div id="post-0" class="post error404 not-found">
                <h1 class="entry-title"><?php _e( 'Not Found', 'localize' ); ?></h1>
                <div class="entry-content">
                        <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'localize' ); ?></p>
                        <?php get_search_form(); ?>
                </div><!-- .entry-content -->
        </div><!-- #post-0 -->
<?php endif; ?>

<?php
        /* Start the Loop.
         *
         *
         * Without further ado, the loop:
         */ ?>
<?php while ( have_posts() ) : the_post(); ?>


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

                        <?php if ( !is_search() ) { ?>
                        <h3 class="entry-title excpts vfont" style="margin: 0px;"><?php the_title(); ?></h3>
                        <div class="vmeta smallfont">
                                <?php ntl_posted_on(); ?><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' )); ?>"><?php echo get_the_author(); ?></a>
                        </div>
                        <?php
                        $pphoto = '';
                        $pphoto = get_the_post_thumbnail($post->ID, 'imlink');
                        if ($pphoto) {
                        ?>

                        <div class="excpt">
                                <?php the_excerpt(); ?>

                        </div>
                        <div class="menu-content" style="width: 286px; position: relative;">
                        <div class="mencontent">
                                <div class="imgblock" ><div class="imlk imgoverlink6 menimg">
                                <?php the_post_thumbnail('imlink'); ?>
                                <a href="<?php the_permalink(); ?>"><span class="imgblockover imgoverlink6">&nbsp;</span></a>
                                </div></div>
                                <div class="ctime clear smallfont">
                        <?php the_time('j') ?>
                        <?php the_time('M') ?>
                                </div> 
                        </div>
                        </div>
                        <?php } else { ?>
                        <?php the_excerpt(); ?>
                        <?php } ?>

                        <?php } else { ?>
                        <div class="foodmenu searchresult">
                        <h2 class="entry-title vfont excpts"><?php the_title(); ?></h2>
                        <?php the_excerpt(); ?>
                        <a href="<?php the_permalink(); ?>">Read More</a>
                        <span class="clear"></span>
                        </div>
                        <?php } ?>

                </div>

                <?php comments_template( '', true ); ?>

<?php endwhile; ?>

Any suggestions would be much appreciated!

  • 1
    A question should not rely on external pages. Please include minimal code examples in your questions. – fuxia Apr 4 '14 at 6:06
  • 1
    Not sure if this is relevant, but if you've set a certain page to display as the home page in Settings > Reading, then you need to save your template as front-page.php not homepage.php. homepage.php is used when the home page just displays the most recent posts. – Steve Apr 4 '14 at 7:56
  • Actually, homepage.php is not a valid template file name, and won't be used at all, unless as a properly configured custom page template. – Chip Bennett Apr 4 '14 at 13:00
  • The page you have linked as the "blog page" is not, in fact, the blog page, where "blog page" means blog posts index. The page you've linked as the "blog page" is actually the archive index page for category ID 7. – Chip Bennett Apr 4 '14 at 13:01
1

I think you're making this far more difficult on yourself than you need to.

Easiest Solution

First, I'm a bit confused, because the page you call the "blog page" is not actually the blog page. The blog page is the blog posts index page, and the page you've linked is actually the category archive index for category ID 7.

If you really want this:

Basically I want the homepage to display exactly like the blog page, but include the slider.

And you want to call the Category 7 Archive Index page the "Blog" page, then the solution is really quite simple:

  1. Go to Settings -> Reading
  2. Change "Front page displays" from "a static page" to "latest posts"

Then, you can do one of two things:

  1. Add the slider to header.php, using as if ( is_front_page() ) conditional wrapper
  2. Create a home.php template file (the template file used to display the blog posts index), and add your slider there.

Convoluted Solution

If you really want a custom static front page and a separate blog page, first ensure that you have the static front page configured properly:

  1. Create a static page, named (arbitrarily) "Front Page" or "Home Page" or whatever you want
  2. Create a static page, named (arbitrarily) "Blog" or whatever you want
  3. Go to Settings -> Reading
  4. Change "Front page displays" from "latest posts" to "a static page"
  5. Select the page created in Step 1 as the "Front page"
  6. Select the page created in Step 2 as the "Posts page"

Then, you just need to configure your template files.

In this case, you can let the blog posts index fallback to index.php, and you'll be good to go there. But for the front page, you'll need to create front-page.php, with the following:

  1. The slider code where appropriate
  2. A custom/secondary query, using new WP_Query().
  3. Pagination fix.

This solution is much more complicated. I would recommend going with the easier solution.

  • I tried both solutions without any luck. Let me try to clarify what's happening using images. – aizas5544 Apr 6 '14 at 2:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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