Pat if amp - ⚡ A Textpattern Conditional Plugin for Google's Accelerated Mobile Pages Project (AMP)

Overview

pat_if_amp

Download | Packagist

AMP pages for Textpattern CMS.

This conditional tag examines the URL of the current page and determines if the URL ends in ‘amp.’ This allows for a custom page to be rendered using the standards for Google’s Accelerated Mobile Pages (AMP) project.

Links

Don’t forget to check out my other plugin that’s also Google AMP compatible: pat_article_social

Note

Since TXP 4.7+ and its new features, you can choose to use build-in tags solution instead of this plugin. Read more about from this forum post by Oleg (don’t forget to add a TXP variable on the fly for further usages within you website):

<txp:evaluate query='contains(<txp:page_url escape="quote" />, "/amp")'>
    AMP page
<txp:else />
    regular page
</txp:evaluate>

Installing

Using Composer:

$ composer require cara-tm/pat_if_amp:*

Or download the latest version of the plugin from the GitHub project page, paste the code into the Textpattern Plugins administration panel, install and enable the plugin.

pat_if_amp

Attributes

  • url string (optional): The location (URL) of the website. Default: hu (website URL as set in the Textpattern preferences panel).
  • subdomain string (optional): Sets the subdomain name of where to redirect to. Default: amp.
  • permlink boolean (optional): if set to 0 (false) the redirection for the same article’s URL mode within the subdomain will be not made. Default: 1 (true).

Example

Place code similar to below within your individual article template header, so that the AMP page can be properly detected:

<txp:if_individual_article>
    <link rel="canonical" href="<txp:permlink />">
    <link rel="amphtml" href="<txp:permlink />/amp/">
</txp:if_individual_article>

Place something similar to below within your individual article template to display the alternative formatting:

<txp:pat_if_amp>
    <txp:output_form form="amp_page" />
<txp:else />
    <txp:output_form form="standard_page" />
</txp:mkp_if_amp>

Textpattern variable usage

A <txp:variable name="pat_amp" /> with a true/false value (1 or 0) is automatically generated, for testing when this is an AMP context or not.

Usage

<txp:if_variable name="pat_amp" value="1">
    AMP context
<txp:else />
    Normal context
</txp:if_variable>

Example

<txp:if_variable name="pat_amp" value="1">
    ...Do some AMP things...
    <a href="<txp:site_url />category/<txp:category name='<txp:category1 />' />?amp">AMP Category 1 Link</a>
<txp:else />
    ...Do some normal (non-AMP) things...
</txp:if_variable>

This example concerns categories, use kind of the same model for pages and/or archives.

pat_amp_sanitize

A tag to render article text content without any inline styles. To use as a drop-in replacement of the standard Textpattern <txp:body /> tag and/or <txp:excerpt /> tag.

Attributes

  • content string (optional): choose either body or excerpt article content to sanitize. Default: body.

Usage

In an article Form context:

<txp:pat_amp_sanitize content="excerpt" />

pat_amp_redirect

A simple tag for web redirection to a subdomain name. Same behaviour as used in The Guardian website. Must be used with a mobiles detection script (i.e. adi_mobile plugin). Some web designers could choose to use a subdomain for their mobiles websites (may be not recommended, but the official AMP Blog is located in a subdomain, see: https://amphtml.wordpress.com). In this case, the Textpattern multi-sites capacities makes things easier.

Note: Doesn’t work on local server installations, only on live servers.

Usage

<txp:pat_amp_redirect url="" subdomain="" permlink="" />

Good advice: Copy the config.php file of the main site into the subdomain configuration folder in order to share the same database. So, all articles written by the Copy Editors will be sent automatically to the ‘AMP powered website’ from only one Textpattern administration interface attached to the ‘normal’ website. But designers have a separate and cleaner space to build their AMP pages.

Attributes

  • url string (optional): The location (URL) of the website. Default: hu (website URL as set in the Textpattern preferences panel).
  • subdomain string (optional): Sets the subdomain name of where to redirect to. Default: amp.
  • permlink boolean (optional): Choose to redirect the same individual article’s title URL within the subdomain. Default: 0 (false).

Example

<txp:pat_amp_redirect subdomain="amp" permlink="1" />

In this case, if your main domain is example.com, it redirects to the amp.example.com subdomain and uses the same individual article’s URL from the main domain.

Acknowledgments

Many thanks to Phil Wareham who tidied up this plugin code and its help file.
Thank you to Michael K. Pate, for its original idea, who accepted to distribute my entire rewriting code as a ‘pat’ prefixed plugin.

You might also like...
An async process dispatcher for Amp.

process This package provides an asynchronous process dispatcher that works on all major platforms (including Windows). As Windows pipes are file hand

This plugin allows you to create many-to-many relationships between pages in Kirby and synchronizes them on both sides.
This plugin allows you to create many-to-many relationships between pages in Kirby and synchronizes them on both sides.

Kirby 3 Many To Many Field This plugin allows you to create many-to-many relationships between pages in Kirby.

The plugin generates posts/pages. Useful to generate millions of records in wp_posts table
The plugin generates posts/pages. Useful to generate millions of records in wp_posts table

KAGG Generator The plugin generates posts/pages. Useful to generate millions of records in wp_posts table. In WordPress development, sometimes it is n

WooCommerce Empty Cart Button plugin helps you to add Empty Cart button to WooCommerce Pages/Sections using Shortcode only.

WooCommerce Empty Cart Button plugin helps you to add Empty Cart button to WooCommerce Pages/Sections using Shortcode only. How to use? Download the p

MassPlugCompiler - Textpattern CMS plugin compiler

mtxpc mtxpc compiles Textpattern CMS plugin sources into installer packages. Supports multi-file structure and a JSON manifest file. Install Using Com

Oui cookie - Cookie management plugin for @Textpattern

oui_cookie Introduction Set, check, read, reset or delete cookies manually or through GET/POST parameters. . According to the EU legislation, some coo

Arc social share - A Social Bookmarking Plugin for Textpattern

arc_social_share A Social Bookmarking Plugin for Textpattern; easily add links for sharing content with numerous social networks. arc_social_share 1.4

Unicode-url-for-Textpattern - Plugin for using unicode urls instead of transliterations to ASCII characters

Unicode-url-for-Textpattern Summary textpattern plugin wcz_utf8_url – uses UTF-8 permlinks instead of transliterated ones for SEO Features automatical

Arc meta - Textpattern plugin for meta tags to improve site SEO and social marketing.

arc_meta A Textpattern plugin for meta tags to improve site SEO and social marketing. arc_meta adds meta fields to your article, section and category

Comments
  • Composer GitHub Service Hook?

    Composer GitHub Service Hook?

    Hi there, I've just tagged a new pre-prerelease (0.3.6-beta) but Packagist is not auto-updating. I assume this is because you haven't created the GitHub Service Hook as yet? See instructions at bottom of page here.

    opened by philwareham 4
  • Composer support prep work

    Composer support prep work

    Hi there,

    I want to use this plugin via Composer for the upcoming Textpattern.com website. This pull request starts that process.

    You'll then need to:

    1. Go to https://packagist.org, register an account (you can use your GitHub credentials) and then submit your Composer package here: https://packagist.org/packages/submit
    2. Follow the instructions at foot of page here https://packagist.org/about to hook the Packagist service into your GitHub repo.
    3. Unrelated: please go to your repo settings and turn of wiki tab and turn on issues tab.
    4. Tag a release (version 0.3.6). I can tag a release for you if you give me collaborator access to your repo.
    5. I've removed the compiled txt files from the repo - those should be attached to the releases as binaries - again I can do that with repo collab access.
    opened by philwareham 4
  • Not sure the Packagist hook is set up

    Not sure the Packagist hook is set up

    Hi,

    I don't think the service hook is set up properly between GitHub and Packagist for this repo. Can you confirm? Instructions here (at bottom): https://packagist.org/about

    I tagged a new release on GitHub earlier today put it's not registering so at Packagist.

    opened by philwareham 3
  • Doesn't work with PHP 5.4

    Doesn't work with PHP 5.4

    Hi,

    The plugin doesn't work in PHP 5.4 (only seems to work in PHP 5.5 onwards) and I need it to so I can launch the new Textpattern.com website. Any chance you can find a way of backporting this to 5.4.

    I don't have the luxury of upgrading PHP on that server unfortunately.

    opened by philwareham 1
Releases(v0.3.7)
Owner
Patrick LEFEVRE
“Why would I have a cat while I have a mouse?” ― Philip Marlowe
Patrick LEFEVRE
Pat eu cookies law - 🌝 EU Cookie Law Compliance: A Textpattern plugin (or standalone script) for Third-Party Cookies (RGPD compliance)

pat_eu_cookies_law EU Cookie Law Compliance: A Textpattern plugin (or a standalone script) for Third-Party Cookies. A simple solution that respects th

Patrick LEFEVRE 3 Aug 16, 2020
A tidy conditional Blade directive for checking if something is in an array

A tidy conditional Blade directive for checking if something is in an array. This package provides a small @in directive that allows you to simplify i

Ryan Chandler 0 Oct 7, 2022
Textpattern-installer - Textpattern plugin and theme installer for Composer

Textpattern Installer for Composer Package directory | Issues Install plugins and themes to Textpattern CMS with Composer. $ composer require rah/rah_

Jukka Svahn 7 Apr 14, 2022
Run your WP site on github pages, php innovation award winner https://www.phpclasses.org/package/12091-PHP-Make-a-WordPress-site-run-on-GitHub-pages.html

Gitpress Run wordpress directly on github pages Gitpress won the innovation award for may 2021 Read more about this https://naveen17797.github.io/gitp

naveen 13 Nov 18, 2022
A Magento 2 module that allows for creating discrete PDP (Product Detail Pages) page layouts for customers landing on the site from a PPC (Pay Per Click) link/ad by allowing routing to the same pages using a `/ppc/` prefix in the URL path.

A Magento 2 module that allows for creating discrete PDP (Product Detail Pages) page layouts for customers landing on the site from a PPC (Pay Per Click) link/ad by allowing routing to the same pages using a `/ppc/` prefix in the URL path.

null 16 Nov 11, 2022
Rah cache - Cache Textpattern's dynamic pages as flat files

rah_cache Packagist | Issues Rah_cache is a simple, experimental full-page caching plugin for Textpattern CMS. It caches Texpattern’s dynamic pages as

Jukka Svahn 2 Apr 24, 2022
Textpattern-for-Panic-Coda - A Textpattern CMS mode for Panic Coda

Textpattern elements for Panic Coda 2 Handy elements for use with Panic Coda 2 on a Mac when authoring files for the Textpattern CMS. This repository

Phil Wareham 8 Jun 26, 2017
Ied plugin composer - Inspired Plugin Composer: Create, publish and edit plugins from within Textpattern CMS.

ied_plugin_composer Create, publish and edit plugins from within Textpattern CMS. Creates a new page under the Extensions tab where you can edit and e

Stef Dawson 8 Oct 3, 2020
AMP Optimizer PHP library

AMP Toolbox for PHP A collection of AMP tools making it easier to publish and host AMP pages with PHP. The following tools are part of this library: A

AMP 71 Dec 28, 2022
Artax is an asynchronous HTTP client for PHP based on Amp

Artax is an asynchronous HTTP client for PHP based on Amp. Its API simplifies standards-compliant HTTP resource traversal and RESTful web service consumption without obscuring the underlying protocol. The library manually implements HTTP over TCP sockets; as such it has no dependency on ext/curl.

AMPHP 21 Dec 14, 2022