How To Display Post In WordPress Custom Theme

How To Display Post In WordPress Custom Theme

Spread the love

Today we will see how to display posts in WordPress custom theme.

Display Post in WordPress Custom Theme If you want to show in home page then you have to do dynamic code in it. The index.php file for the blog is called. If you want to make a home page then you have to create a home page template and for blog then index.php will be called then dynamic code will have to be done in it.

Use this function to display posts in a WordPress custom theme. and we will fetch dynamic post for that we will use while loop which is mentioned below.

1.The basic loop is:

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

<!-------- Post Content here -------->

<?php endwhile; else : //End the while loop ?>
<p><?php _e( 'No Posts To Display.' ); ?></p>
<?php endif; //end If statement ?> 

2.The basic loop is:

<?php 
while (have_posts()) {
the_post();
?>

<!-------- Post Content here -------->


<?php } ?>

To make the featured image appear in the WordPress blog, we will take a variable and paste the url inside the img.


<?php 
while (have_posts()) {
the_post();
$imagepath = wp_get_attachment_image_src(
get_post_thumbnail_id(),'large');
//print_r($imagepath);
?>
<!-------- Post Content here -------->

<img src="<?php echo $imagepath[0]; ?>" alt="">

<?php } ?>

Full Code Here:

<?php 
while (have_posts()) {
the_post();
$imagepath = wp_get_attachment_image_src(
get_post_thumbnail_id(),'large');
//print_r($imagepath);
?>
<!-------- Post Content here -------->

<img src="<?php echo $imagepath[0]; ?>" alt="">
<h4> <?php the_title(); ?> </h4>
<h2> <?php the_author(); ?> </h2>
<span> <?php echo get_the_date(); ?> </span>
<p> <?php the_excerpt(); ?> </p>

<?php } ?>

Spread the love

Related Posts

Leave a Reply

Your email address will not be published.