6
votes

I got one "front-page.php" that is a static one side page. If I use the Wordpress loop to see my latest posts at the front-page.php they all shown up. Now I want to create a news page so I created a file "page-news.php". Removed the loop code from front-page and pasted it into page-news. Though, nothing happens.

Loop code:

<?php get_header();?>

<?php
if (have_posts()):
while (have_posts()): the_post();?>

<?php the_title();?>
<?php the_content();?>

<?php
endwhile;
else: echo '<p>no posts were found</p>';
endif;

 ?>

<?php get_footer();?>

What have I missed?

1
I am not sure why you are opening and closing the php tags for every line, can't you open it once at the top and close it once at the bottom?myselfmiqdad
@miqdadamirali Maybe there is some other (HTML) code, which is not relevant for the question. ;)KittMedia
Have you created a page called news? are you 100% this template is being run? If you just add <p>test</p> or something in the code does that show up.Simon Pollard
I got my header/footer that is visible. Also, yes, I have created a page via Wordpress dashboard with the name "news".Michael
Add the code I put <p>Test</p> after your get_header line - and let me know if that displays - need to make sure your template is actually getting loaded.Simon Pollard

1 Answers

2
votes

you need to add wp_Query the main page is consider a blog page so it have the Query default .

$args = array (
/*'cat'                    => $catNum,*/
'post_type'              => 'post',
'pagination'             => false,
'posts_per_page'         => '-1',
'ignore_sticky_posts'    => false,
'order'                  => 'DESC',
'orderby'                => 'date',
);

// The Query
$query = new WP_Query( $args );

you should add this code before

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

the this part about have_posts() will be

// The Loop
if ( $query->have_posts() ) { ?>
    <?php while ( $query->have_posts() ) {
        $query->the_post();

dont forget to add wp_reset_postdata(); at the end so you can use many Query in one page .