I am new to PHP and WordPress plugin so I am a bit ignorant of some features. I want to write a plugin that restricts the number of posts shown on the main page (index.php). I want to use plugin because changing index.php of a certain theme would only affect that theme so I have been writing some code to actualize the concept but does not work and I want to know how I would achieve this to happen.

<?php
/*Initalize to 0 */
$numPosts = 0;
if(have_posts()) : 
    while($numPosts <=0) : the_post();
    $numPosts = $numPosts + 1; ?>
    <article class="post">
        <h2> <a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a> </h2>
        <?php the_content(); ?>
    </article>
<?php endwhile;
else :
    echo '<p> No Contents Found </p>';
endif;
?>

Read more here: Writing plugin to affect the index.php file


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , ,

Wordpress related questions and answers: