In this article we’ll look into the theme structure and it’s working.
<?php /* Plugin Name: AMP Theme Framework Plugin URI: https://wordpress.org/plugins/accelerated-mobile-pages/ Description: This is a custom AMP theme built to show how easy it is to make custom AMP themes. Version: 1.0 Author: Mohammed Kaludi, Ahmed Kaludi Author URI: http://ampforwp.com/themes License: GPL2 AMP: AMP Framework */ // Exit if accessed directly. if ( ! defined( 'ABSPATH' ) ) exit;
This file is for WordPress to let it know that This is a plugin and treat it as such.
<?php amp_header() ?> <?php amp_archive_title(); ?> <?php amp_loop_template(); ?> <?php amp_footer()?>
</div> <footer class="footer container"> <?php amp_non_amp_link(); ?> </footer> <?php amp_footer_core(); ?>
this file is to add the support to all the components present in the AMP Theme Framework.
If you wish to add any component say “search” then you should use the following code.
add_amp_theme_support('AMP-search');
AMP-search is used to initiate the support for the search component.
following is the list of all the components.
<?php
// Loading the Components
//Search
add_amp_theme_support('AMP-search');
//Logo
add_amp_theme_support('AMP-logo');
//Social Icons
add_amp_theme_support('AMP-social-icons');
//Menu
add_amp_theme_support('AMP-menu');
//Call Now
add_amp_theme_support('AMP-call-now');
//Sidebar
add_amp_theme_support('AMP-sidebar');
// Featured Image
add_amp_theme_support('AMP-featured-image');
//Author box
add_amp_theme_support('AMP-author-box');
//Loop
add_amp_theme_support('AMP-loop');
// Categories and Tags list
add_amp_theme_support('AMP-categories-tags');
// Comments
add_amp_theme_support('AMP-comments');
//Post Navigation
add_amp_theme_support('AMP-post-navigation');
// Related Posts
add_amp_theme_support('AMP-related-posts');
// Post Pagination
add_amp_theme_support('AMP-post-pagination');In this file, you’ll be adding the components like sidebar, search and social icons.
<?php amp_header_core() ?>
<header class="header container">
<?php amp_logo(); ?>
<?php amp_sidebar(['action'=>'open-button']); ?>
<?php amp_call_now(); ?>
<?php amp_social([
'twitter' => 'https://www.twitter.com/marqas36',
'facebook' => 'https://www.facebook.com'
]);?>
</header>
<?php amp_sidebar(['action'=>'start',
'id'=>'sidebar',
'layout'=>'nodisplay',
'side'=>'right'
] ); ?>
<?php amp_sidebar(['action'=>'close-button']); ?>
<?php amp_menu(); ?>
<?php amp_search();?>
<?php amp_social(); ?>
<?php amp_sidebar(['action'=>'end']); ?>
<div class="content-wrapper container">amp_header_core() is a must to add in this file which will get the core of AMP HTML
amp_logo() is used to add the logo component and similarly, the other components can be loaded such as
amp_sidebar()
amp_search()
amp_menu()
amp_social()
<?php amp_header(); ?> <?php amp_loop_template(); ?> <?php amp_footer(); ?>
here in index.php
this is one of the most important files for the theme which is responsible to load the content of the loop.
<?php while(amp_loop('start')): ?>
<div class="loop-post">
<?php amp_loop_image(); ?>
<?php amp_loop_title(); ?>
<?php amp_loop_excerpt(); ?>
<?php amp_loop_category(); ?>
<?php amp_loop_date(); ?>
</div>
<?php endwhile; amp_loop('end'); ?>
<?php amp_pagination(); ?>here we check the condition while the loop is start
<?php amp_header(); ?> <?php amp_title(); ?> <?php amp_featured_image(); ?> <?php amp_content(); ?> <?php amp_footer(); ?>
It is used to load the AMP content for the page.
this file is responsible for displaying the posts in AMP theme.
We can add any component we want to display in single as per our need.
<?php amp_header(); ?>
<?php amp_title(); ?>
<?php amp_featured_image();?>
<?php amp_content(); ?>
<?php amp_post_pagination();?>
<?php amp_author_box(); ?>
<?php amp_social(array('twitter'));?>
<?php amp_categories_list();?>
<?php amp_tags_list();?>
<?php amp_comments();?>
<?php amp_post_navigation();?>
<?php amp_related_posts(); ?>
<?php amp_footer()?>this file contains all the css style for the entire theme.
<?php add_action('amp_post_template_css', 'ampforwp_custom_style', 11);
function ampforwp_custom_style() {
global $redux_builder_amp;
$get_customizer = new AMP_Post_Template( $post_id );
?>
/****
* AMP Framework Reset
*****/
body{ font-family: sans-serif; font-size: 16px; line-height:1.4; }
ol, ul{ list-style-position: inside }
p, ol, ul, figure{ margin: 0 0 1em; padding: 0; }
a, a:active, a:visited{ color:#ed1c24; text-decoration: none }
a:hover, a:active, a:focus{}
pre{ white-space: pre-wrap;}
.hidden{ display:none }
.clearfix{ clear:both }
blockquote{ background: #f1f1f1; margin: 10px 0 20px 0; padding: 15px;}
blockquote p:last-child {margin-bottom: 0;}
.amp-wp-unknown-size img {object-fit: contain;}
.amp-wp-enforced-sizes{ max-width: 100% }
/* Image Alignment */
.alignright {
float: right;
}
.alignleft {
float: left;
}
.aligncenter {
display: block;
margin-left: auto;
margin-right: auto;
}
amp-iframe { max-width: 100%; margin-bottom : 20px; }
/* Captions */
.wp-caption {
padding: 0;
}
.wp-caption-text {
font-size: 12px;
line-height: 1.5em;
margin: 0;
padding: .66em 10px .75em;
text-align: center;
}
/* AMP Media */
amp-iframe,
amp-youtube,
amp-instagram,
amp-vine {
margin: 0 -16px 1.5em;
}
amp-carousel > amp-img > img {
object-fit: contain;
}
/****
* Container
*****/
.container {
max-width: 600px;
margin: 0 auto;
}
/****
* AMP Sidebar
*****/
amp-sidebar {
width: 250px;
}
/* AMP Sidebar Toggle button */
.amp-sidebar-button{
position:relative
}
.amp-sidebar-toggle {
}
.amp-sidebar-toggle span {
display: block;
height: 2px;
margin-bottom: 5px;
width: 22px;
background: #000;
}
.amp-sidebar-toggle span:nth-child(2){
top: 7px;
}
.amp-sidebar-toggle span:nth-child(3){
top:14px;
}
/****
* AMP Navigation Menu with Dropdown Support
*****/
.toggle-navigation ul{
list-style-type: none;
margin: 0;
padding: 0;
display: inline-block;
width: 100%
}
.toggle-navigation ul li{
font-size: 13px;
border-bottom: 1px solid rgba(0, 0, 0, 0.11);
padding: 11px 0px;
width: 25%;
float: left;
text-align: center;
margin-top: 6px
}
.toggle-navigation ul ul{
display: none
}
.toggle-navigation ul li a{
color: #eee;
padding: 15px;
}
.toggle-navigation{
display: none;
background: #444;
}
/****
* Loop
*****/
.loop-wrapper .loop-img{
float: left;
margin-right: 15px;
}
.loop-category{
list-style-type:none
}
.loop-category li{
display:inline;
margin-right:1px;
}
/****
* Single
*****/
/****
* Comments
*****/
.comments_list ul{
margin:0;
padding:0
}
.comments_list ul.children{
padding-bottom:10px;
margin-left: 4%;
width: 96%;
}
.comments_list ul li p{
margin: 0;
font-size: 14px;
clear: both;
padding-top: 5px;
}
.comments_list ul li .says{
margin-right: 4px;
}
.comments_list ul li .comment-body{
padding: 10px 0px 15px 0px;
}
.comments_list li li{
margin: 20px 20px 10px 20px;
background: #f7f7f7;
box-shadow: none;
border: 1px solid #eee;
}
.comments_list li li li{
margin:20px 20px 10px 20px
}
.comment-author{ float:left }
/****
* RTL Styles
*****/
<?php if( is_rtl() ) {?> <?php } ?>
/****
* Custom CSS
*****/
<?php echo $redux_builder_amp['css_editor']; ?>
<?php } ?>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.
If you want to add an AWeber form in AMP then first you need to…
Webpushr is the fastest growing web push notifications platform that marketers love & developers rely…
Follow these steps to add Adobe Analytics in AMP Step 1: Go to WordPress Admin Area -> AMP…
Core Web Vitals are the subset of Web Vitals that apply to all web pages,…
The following reasons can be shown for non-indexing. Server error (5xx) Your server returned a 500-level…
We have added the Google Analytics 4 ( GA 4 ) integration in AMPforWP v1.0.80.…