• Hello,

    I’m developping a wordpress theme. I’m making a custom theme for a specific page.

    I created a “Home” page with the identifier “home”. I created a page-home.php file, with this loop:

    get_header();
    get_topmenu(); ?>
    
        <div class="catch"></div>
    
        <div id="primary" class="content-area page-home">
            <div id="content" class="site-content" role="main">
                <?php /* The loop */ ?>
                <?php if(have_posts()) : ?>
                <?php while (have_posts()) : the_post(); ?>
    
                    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                        <h1 class="entry-title"><?php the_title(); ?></h1>
    
                        <div class="entry-content">
                            <?php the_content(); ?>
                        </div><!-- .entry-content -->
                    </article><!-- #post -->
    
                    <?php comments_template(); ?>
                 <?php endwhile; ?>
                <?php endif; ?>
    
            </div><!-- #content -->
        </div><!-- #primary -->
        PAGE HOME.PHP
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    But doing this, I’ve got ALL my pages displayed in the loop, and not just the “home” page… What is the cleanest way to get just the “Home” page ?

    Thanks for your help to a theme-developpement newbie 😉

    Maxime

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    I want to say part of that reason is because you are looping over the posts. What happens if you remove the while/endwhile and simply use: the_post()?

    Thread Starter maximelebastard

    (@maximelebastard)

    Annd POW! It just works !

    It seems quite evident now that I’ve got the answer, thank you !

    Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    Welcome!

    Thread Starter maximelebastard

    (@maximelebastard)

    Finally, it does not work… I added another page with the identifier “gear”, and even if the page-home.php template is the one which is displayed, the_content() function returns the “gear” page content…

    I tried this piece of code, but the_content() stills return the wrong page:

    $page_object = get_queried_object();
                    $page_id     = get_queried_object_id();
                    var_dump($page_id);
                    get_post($page_id);

    Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    Are you able to post a link?

    Thread Starter maximelebastard

    (@maximelebastard)

    Unfortunately no, I’m working in a local environnement…

    What details do you want ?

    Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    What page is is supposed to be showing?

    Thread Starter maximelebastard

    (@maximelebastard)

    I call localhost/mywordpress/?q=home, which is also the homepage I setted in the WordPress admin panel.
    Wordpress renders the page with the page-home.php file, that I created. The Page “Home”, with the identifier “home” is supposed to be showed, but instead of that, I get the “Gear” page content.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Custom theme : page-home.php displays all posts’ is closed to new replies.