The Famous loop in Wordpress for Generating posts
Go to index.php file and write below code to display post
<?php
while(have_posts()) {
the_post(); ?>
<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<?php the_content(); ?>
<hr>
<?php } ?>
and save and check blog to display posts.
to display single post add new file single.php in theme folder.
Add below loop code in single.php for display single post.
<?php
while(have_posts()) {
the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<hr>
<?php } ?>
For Page
First create new test page with dummy content and publish
And add page.php file in theme folder.
and add below code in page.php
<?php
while(have_posts()) {
the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<hr>
<?php } ?>
and save and check page
Comments
Post a Comment