Skip to main content
added 156 characters in body
Source Link
kierzniak
  • 2.5k
  • 11
  • 11

WordPress is fetching current post for you, you have to only type to the right url. When you get e.g. to example.com/lorem-ipsum/ WordPress will load automatically post with title Lorem ipsum and display it using page.phppage.php template. Your page.phppage.php template should be looking something like that.

<?php get_header(); ?>

    <div id="content">

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

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

            // If comments are open or we have at least one comment, load up the comment template.
            <?php if ( comments_open() || get_comments_number() ) : ?>
                <?php comments_template(); ?>
            <?php endif; ?>

        <?php endwhile; ?>
    </div>

<?php
get_sidebar();
get_footer();

KeyThe concept which beginners do notof a loop is difficult to understand arefor novice developers. Only in the loop you can use functions like loopsthe_title or the_content. Outside of the loop, these functions won't return you anything.

https://codex.wordpress.org/The_Loop

WordPress is fetching current post for you, you have to only type to the right url. When you get e.g. to example.com/lorem-ipsum/ WordPress will load automatically post with title Lorem ipsum and display it using page.php template. Your page.php template should be looking something like that.

<?php get_header(); ?>

    <div id="content">

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

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

            // If comments are open or we have at least one comment, load up the comment template.
            <?php if ( comments_open() || get_comments_number() ) : ?>
                <?php comments_template(); ?>
            <?php endif; ?>

        <?php endwhile; ?>
    </div>

<?php
get_sidebar();
get_footer();

Key concept which beginners do not understand are loops. https://codex.wordpress.org/The_Loop

WordPress is fetching current post for you, you have to only type to the right url. When you get e.g. to example.com/lorem-ipsum/ WordPress will load automatically post with title Lorem ipsum and display it using page.php template. Your page.php template should be looking something like that.

<?php get_header(); ?>

    <div id="content">

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

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

        <?php endwhile; ?>
    </div>

<?php
get_sidebar();
get_footer();

The concept of a loop is difficult to understand for novice developers. Only in the loop you can use functions like the_title or the_content. Outside of the loop, these functions won't return you anything.

https://codex.wordpress.org/The_Loop

Source Link
kierzniak
  • 2.5k
  • 11
  • 11

WordPress is fetching current post for you, you have to only type to the right url. When you get e.g. to example.com/lorem-ipsum/ WordPress will load automatically post with title Lorem ipsum and display it using page.php template. Your page.php template should be looking something like that.

<?php get_header(); ?>

    <div id="content">

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

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

            // If comments are open or we have at least one comment, load up the comment template.
            <?php if ( comments_open() || get_comments_number() ) : ?>
                <?php comments_template(); ?>
            <?php endif; ?>

        <?php endwhile; ?>
    </div>

<?php
get_sidebar();
get_footer();

Key concept which beginners do not understand are loops. https://codex.wordpress.org/The_Loop