Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Content and title won't show on certain page in Wordpress

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?

like image 312
Michael Avatar asked Dec 16 '15 09:12

Michael


1 Answers

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 .

like image 119
J.Tural Avatar answered Sep 22 '22 14:09

J.Tural