add related articles inside content of an instant articles fb

1.7k views Asked by At

I need to add some related posts in the content of an instant articles. I use this WordPress plugin:

https://github.com/Automattic/facebook-instant-articles-wp

My posts have:

<ul class="related-article">
  <li>
     <a href="http://example.com/"></a>
  </li>
</ul>

I add this in my transformer rules

{
      "class": "RelatedArticlesRule",
      "selector": ".related-article"

},
{
      "class": "RelatedItemRule",
      "selector": ".related-article li",
      "properties": {
        "related.url": {
          "type": "string",
          "selector": "a",
          "attribute": "href"
        }
      }
}

But in trasformer markup the related ul not exists. I need something like that:

<ul class="op-related-article">
  <li>
     <a href="http://example.com/"></a>
  </li>
</ul>
1

There are 1 answers

4
Paweł Mikołajczuk On BEST ANSWER

looks like related articles items are checked only inside RelatedArticlesRule so your selector is wrong.

This should work:

{
  "class": "RelatedArticlesRule",
  "selector": "ul.related-article",
  "properties" : {
    "related.title" : {
        "type" : "string",
        "selector" : "ul.related-article",
        "attribute": "title"
     }
  }
},
{
  "class": "RelatedItemRule",
  "selector": "li",
  "properties": {
    "related.url": {
      "type": "string",
      "selector": "a",
      "attribute": "href"
    }
  }
}