• 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?

Viewing 9 replies - 1 through 9 (of 9 total)
  • To create a custom page you should create a custom page template file and start with this. So modify your “page-news.php” like this

    <?php
    /**
    * Template Name: My custom Page
    *
    */

    You can now assign this template from pages on backed to whichever page you want this template to be rendered for.

    Thread Starter Michael

    (@kcmello)

    I did as you suggested but this is the result:

    —Header— Visible

    Content shows the text: /* Template Name: My Awesome Custom Page */ Blog

    —Footer– Visible

    Thread Starter Michael

    (@kcmello)

    This is the raw code for “page-news.php”.
    https://jsfiddle.net/0bg2pphn/

    There was a problem with your code.

    Previous :

    <?php get_header();?>
    
    /*
    Template Name: My Awesome Custom Page
    */

    Should have been :

    <?php get_header();
    
    /*
    Template Name: My Awesome Custom Page
    */
    ?>

    Change this and now it will show up correctly.

    Thread Starter Michael

    (@kcmello)

    Oh, now I feel noobish.
    Anyway, it did not quite solve my problem.
    Instead of “Content shows the text: /* Template Name: My Awesome Custom Page */ Blog” it says “Blog” only. Which is the page’s name.

    Yes. You will have to put content on the page. It will display the content inside your content box.

    What content do you want on this page. ?

    Thread Starter Michael

    (@kcmello)

    I want the latest posts. And I have three so far. They appear when we use the main loop function on my index page. But not on this secondary page.

    Try this. You can set the number of posts you want to display
    with showposts.

    <?php
    /*
    Template Name: My Awesome Custom Page
    */
    
    get_header();
    
    query_posts('showposts=2');
    if (have_posts()):
        while (have_posts()):
            the_post();
            the_title();
            the_content();
        endwhile;
    else:
        echo '<p>no posts were found</p>';
    endif;
    
    get_footer();

    Thread Starter Michael

    (@kcmello)

    Thanks! That solved the problem.
    Do you have any idea why the basic loop-code did not work?

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Content and title won't show on certain page in WordPress’ is closed to new replies.