This article is for AMP Theme Framework users.
About this Component
Loop Component is responsible to render the data on home, archive, search pages.
How to use:
Following are the steps to use this component.
To initiate the support for this component in your theme just add the following code to the functions.php of the theme files.
This was the back-end part where we’ve just initiated, now to make it appear in the front-end follow the next step.
To add the Loop in home, archive, search pages we need to call it where we want to display it.
example: add the following code in index.php, archive.php,search.php of the theme files.
with this, you’ll be able to set loop on your theme.
Now create loop.php to get loop contents on pages. In this page you can show the posts list details with pagination. follow these steps to add the required content in loop.php
To start loop
To end loop
Inside the loop, you can show different contents of the loop according to your needs like:
Show image of post
Show title of post
Show excerpt(Short description) of post
Show Categories of post
Show posted date of post
Show permalinks in the loop of post
If you want the permalinks in the loop for adding read more text etc then with the help of our amp_loop_the_permalink function you can add it easily like:
By using this function you will display the permalink for the loop
By using this function you will retrieve the full permalink for the loop. This function only gets the permalink from loop but it will not display you need to add echo for displaying.
Brief structure of loop.php
To Start the pagination( which will add next page and previous page links )
If you want to modify the loop and divide it into post categories
'post_type' => 'post',
'tax_query' => array(
'relation' => 'AND',
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => 83, // category ID
) ))): ?>
That’s it for this tutorial!
We hope it helped you. If you have any feedback or questions, then please share them in the comments section below.