Luke Anderson WordPress

create wordpress theme and show posts

We can create WordPress theme by creating 2 files style.css and index.php.

Create a WordPress theme from scratch

Create a folder and put these 2 files in that folder. So for example i want to create a theme with the name “Sky”, Then i will create a folder name “Sky” and the i will put these 2 files in that folder.

Next Define theme Details

In style.css add this code

/
Theme Name: Sky
Author: Manu
Author URI: https://zarx.biz
Version: 1.0
/

Here we added a comment which tells wordpress about Theme name, Version and author details. You can customize it as you like.

In Index.php you can put “posts”. Make sure you have some posts created in WordPress dashboard and display them in index.php using below given code.

if(have_posts()):


        while(have_posts()):the_post();
        ?>
            <a href="<?php the_permalink(); ?>">
                <h2>
                    <?php the_title();  ?>
                </h2>
            </a>
            <p>
                <?php the_content();  ?>
            </p>
        <?php
        endwhile;
    
    else :


        echo "No Posts Found";


    endif;

This code goes inside “PHP” tags. We are checking if there is posts then show posts title and content.

Hope this helps

Discussion

Be the first to comment

Leave a comment

Get a quote