[resolved] Page of posts - no posts, using modified wordpress theme (5 posts)

  1. matthisco
    Posted 3 years ago #

    Hi Folks,

    My page of posts is an empty white space. I've set it as a template for my news page and added a few posts, here is my code. Can anyone help?

    Template Name: News template
    // if you are not using this in a child of Twenty Eleven, you need to replicate the html structure of your own theme.
    get_header(); ?>
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'category_name' => 'Latest News', // Change these category SLUGS to suit your use.
    	'paged' => $paged
    if( have_posts() ) :?>
    <?php twentyeleven_content_nav( 'nav-above' );?>
    <?php while ( have_posts() ) : the_post(); ?>
    <?php get_template_part( 'content', get_post_format() ); ?>
    <?php endwhile; ?>
    <?php twentyeleven_content_nav( 'nav-below' ); ?>
    <?php else : ?>
    <?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
    <?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
    <?php get_search_form(); ?>
    <?php endif; ?>
    <?php $posts = get_posts( "category=3&days=7" ); ?>
    <?php if( $posts ) : ?>
    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
    <a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
    <?php endforeach; ?>
    <?php endif; ?>
    <?php get_footer(); ?>
  2. esmi
    Forum Moderator
    Posted 3 years ago #

    Assuming the name of the category that you want is Latest News, you have to use its slug - not its name - in the query arguments. My guess is that you need to change:

    'category_name' => 'Latest News'


    'category_name' => 'latest-news'

  3. matthisco
    Posted 3 years ago #

    Thanks very much for your reply.

    No joy - the page is still blank, but the get posts query at the end of the page works using:

    get_posts( "category=3&days=7" );

  4. esmi
    Forum Moderator
    Posted 3 years ago #

    Can you post a link to the relevant category?

  5. matthisco
    Posted 3 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic