Implementing AMP

tonmo

Well-known member
I have a ton of articles set up as pages. These would seem to be good candidates for AMP. I suppose I could create hidden (unlisted) doppelgangers of each of my articles and leverage the AMP snippets accordingly... i.e., do it manually. Maybe go through the trouble of this for the top 10 or so trafficked entrance pages which are articles.

Ok, I think I have figured this out for pages... but could use a little help.

1) create AMP pages per google instructions: https://www.ampproject.org/docs/get_started/create

2) in the xenforo PAGE_CONTAINER template, add the following above </head>:
Code:
<xen:if is="{$contentTemplate} == 'pagenode_container'">
<link rel="amphtml" href="https://www.example.com/url/to/amp/$ampMatch.html">
</xen:if>

Now, I want "$ampMatch" in the example above to be the "URL Portion:" value for any xenforo page. Can someone tell me how to do that?
 
Now, I want "$ampMatch" in the example above to be the "URL Portion:" value for any xenforo page. Can someone tell me how to do that?
Taking a look at template pagenode_container ...
Code:
<link rel="canonical" href="{xen:link 'canonical:pages', $page}" />
... I'd expect it would would be ...
Code:
<link rel="amphtml" href="{xen:link 'canonical:pages', $page}">

You'd probably want to put it inside this template, rather than page_container.
 
thanks - but the trick is that the AMP pages themselves are going to a different subdirectory... /amp/. So in my example,

My original page (full xenforo template) is here: www.example.com/pages/article-name/

...where "article-name" is the "URL Portion" assigned in the page node editor in admincp.

Per google instructions, my equivalent AMP page is roughly here: www.example.com/amp/article-name.html

I'm using xen:helper dump to try to find the value but not getting there...
 
Last edited:
OK, I used pagenode_container... and instead of using the URL Portion variable (preferred, but I can't find it), I used the following:
Code:
<link rel="amphtml" href="https://www.example.com/amp/{$page.node_id}.html">
So this points to the *ID* for the article, not the preferred name... but at least it renders/works. So in my amp directory, I just saved the file as 17.html (for example). Problem is... this line needs to be ABOVE the /head... which is why I think it needs to be in PAGE_CONTAINER with the conditional in my original example.

I'll keep at it but if anyone is in the know, please advise!
 
Add this to the pagenode_container template:
Code:
<xen:container var="$pagenode_id">{$page.node_id}</xen:container>


That will make the page node ID available in the head section of the PAGE_CONTAINER template.

You call it by using the var name, which is $pagenode_id.
 
was experimenting with xen:container, but forgot the brackets. Thanks! It's all working exactly as it's supposed to... now to troubleshoot why I don't seem to be getting AMP page via mobile.... :-/
 
Ok - after some reading, it seems it will take Google a few days to detect the amp tag. So now I just need to do this 100 or so more times, and I'm all set :rolleyes:

So to summarize:

Pre-requisites: you have created some articles by way of Page Nodes in xenforo, and you want them to be AMP-friendly.

Step 1: create an /amp directory somewhere on your server.

Step 2: create an amp version of one of your articles by following all the steps (including console validation) at "Create Your First AMP Page," here: https://www.ampproject.org/docs/get_started/create

Step 3: save that file using the ID for that page node. So if the page node ID for your article is 77, save it as 77.html, in the /amp directory you created.

Step 4: add the following to pagenode_container template:
Code:
<xen:container var="$pagenode_id">{$page.node_id}</xen:container>

Step 5: add the following to PAGE_CONTAINER template:
Code:
<xen:if is="{$contentTemplate} == 'pagenode_container'">
<link rel="amphtml" href="https://www.example.com/url/to/amp/{$pagenode_id}.html">
</xen:if>

All done! Repeat for every article. Google will crawl your original articles and find the AMP tag and so in a few days you should see your amp pages in Google Search Console.
 
Last edited:
BTW - alternative to Step 5:
Code:
<xen:if is="{$contentTemplate} == 'pagenode_container'">
<xen:if is="{$pagenode_id} == '77'">
<link rel="amphtml" href="https://www.example.com/url/to/amp/{$pagenode_id}.html">
</xen:if>
</xen:if>
This is good if you have a lot of articles to get through, but don't want to send google down an errant path until you're done. This treatment is good if you just want to experiment with a page or two, before converting all. Of course '77' is whatever your converted page ID is. Once you finish populating your /amp directory with all the converted files, use the treatment in the other Step 5, in the post above.
 
Yes, I'm aware... [bd] does great work, I use widget framework in fact... just wanted to do this myself, just for my article pages. ¯\_(ツ)_/¯
 
I'm not sure that a) it supports pages (only threads?) and more importantly if true, b) it's still supported?? I was looking this morning... it's [bd] cache, right? I don't see AMP support listed anymore... did he rollback the 2016 update?
 
I'm not sure that a) it supports pages (only threads?) and more importantly if true, b) it's still supported?? I was looking this morning... it's [bd] cache, right? I don't see AMP support listed anymore... did he rollback the 2016 update?

You pay £5 a month for support on external site, but still don't get answers so I cancelled my support subscription.
 
Last edited:
That's a thread example. Does it support page nodes?

Also - I'm curious if you're using the latest version publicly available. I used to see amp support listed for bd cache but I'm not seeing it now. Wondering if bd rolled back.
 
Top Bottom