Categories: Extending

Modify Homepage Posts Loop of AMP Version the Right Way

This tutorial is a part of the developer’s documentation. It is recommended that you have some knowledge of coding before you proceed because we don’t want to break your live sites 😉 – If coding isn’t your thing then you should forward this tutorial to your developer.

What’s the Goal:

In this tutorial, we will look at the way in which we can modify the list of posts (technically known as Loop) appearing on the Home Page to whatever we want.

Before we even start let’s get the main concept straight, What exactly are are we trying to modify on Homepage of our website ?

It is a set of posts that is output on Home Page

Now in order to modify the output, we need to follow the following steps:

    1. Go to Plugins folder located in your WordPress installation in
      “Your-WordPress-installation/wp-content/plugins/”
    2. Create a folder called “amp-home-output-modify” in the  plugin’s folder
    3. In the folder “amp-home-output-modify” create a file “index.php”
    4. write the following code to the file
    1. After this step just save the file and activate the plugin once, if everything’s working fine proceed
    2. add the following code to index.php file
    3. now you can look at another example at line 15-22
    4. to run this example copy lines between 15-22 and replace with lines 31-35, save and run

and you are done, change the parameters accordingly in the code to what you want to display and simply activate the plugin.

Making it Update Proof:

We don’t have to touch the core plugin to make these changes, so we’re making an external lightweight plugin to make these changes. Actually, this is a standard and recommended way by WordPress.

You can download the final plugin file and put it in your plugins folder. This will make sure that everything is update proof.

Closing notes:

In today’s tutorial, we learned how to modify the homepage loop and make changes to it. In the final code, we covered two use cases, ‘How to exclude specific categories from the homepage loop’ and  ‘How to show posts from other custom post types’.

Please let us know if this was helpful for you and please send other suggestions for the tutorials.

khaled

Share
Published by
khaled