Follow

How to Customise the Edition Atom Feed

An edition feed is basically a list of pages contained in the edition, and is requested every time a client downloads it. An edition atom feed is specified in the OPDS feeds. A published OPDS feed only shows published posts, while a draft OPDS feed shows all posts.

In the Package OPDS feed it looks like:

<link type="application/pugpigpkg+xml" href="/editionfeed/[EID]/pugpig_package_list.manifest" rel="http://opds-spec.org/acquisition"/>
<link type="application/pugpigpkg+xml" href="/editionfeed/[EID]/pugpig_package_list.manifest" rel="alternate"/>

In the Atom OPDS feed it looks like:

<link type="application/atom+xml" href="/editionfeed/[EID]/pugpig_atom_contents.manifest" rel="http://opds-spec.org/acquisition"/>
<link type="application/atom+xml" href="/editionfeed/[EID]/pugpig_atom_contents.manifest" rel="alternate"/>

We use the ATOM syndication format (an alternative to RSS) to build our edition feeds. You can view the generated ATOM feed for each edition by clicking the ATOM feed link in the Editions view. This is a XML feed. It is .manifest as WordPress does not allow custom .xml to generated.

For more detailed information on the Atom Document Type see Atom Document Type

List of filters

Sometimes we will need to modify parts of the atom feed, and to do that we can use the following filters in our extension modules.

To change the title

add_filter('pugpig_feed_post_title', 'your_extension_pugpig_feed_post_title', 10, 2);
function your_extension_pugpig_feed_post_title($output, $post) {
  if ($post->post_type == 'pugpig_ad_bundle') return "Ad Bundle";
 
  return $output;
}

To change level

add_filter('pugpig_feed_post_level', 'general_extension_pugpig_feed_post_level', 10, 2);
function general_extension_pugpig_feed_post_level($level, $post) {
  return $level + 1;
}

Change the summary

add_filter('pugpig_feed_post_summary', 'your_extension_pugpig_feed_post_summary', 10, 2);
function your_extension_pugpig_feed_post_summary($output, $post) {
  // Add a generic summary to ad bundles 
  $summary = "Interactive content for your pleasure";
  if ($post->post_type == 'pugpig_ad_bundle') return $summary;
 
  return $output;
}

Change the author

add_filter('pugpig_feed_post_author', 'your_extension_pugpig_feed_post_author', 10, 2);
function your_extension_pugpig_feed_post_author($author, $post) {
  // Strip out authors that should not be shown
  if (in_array($author, array("Pugpig Custom : Scientific American", "maddie"))) {
    return "Scientific American";
  }
 
  return $author;
}

Change the categories. By default it uses the slugs. Use this, for example, if you want to use the category name.

add_filter('pugpig_feed_post_categories', 'general_extension_pugpig_feed_post_categories', 10, 2);
function general_extension_pugpig_feed_post_categories($category, $post) {
    $first_category = pugpig_get_first_category($post);
    if (!empty($first_category)) {
      if ($first_category->name == "More Science")
        return array("Even More Science");
      else
        return array($first_category->name);
    }
 
    return array();
}

Add additional custom categories

add_filter('pugpig_feed_post_custom_categories', 'your_extension_pugpig_feed_post_custom_categories', 10, 2);
function your_extension_pugpig_feed_post_custom_categories($category, $post) {
    $slug = pugpig_get_first_category_slug($post);
    if (startsWith($slug, "climate")) {
      $category['subtype'] = 'Ecology';
    }
    if (startsWith($slug, "tech")) {
      $category['subtype'] = 'Future';
    }
 
    return $category;
}

Here's another useful example for custom categories:

add_filter ('pugpig_feed_post_custom_categories', 'your_extension_pugpig_feed_post_custom_categories', 10, 2);
function your_extension_pugpig_feed_post_custom_categories($category, $post) {
 
    $post_id = $post->ID;
 
    $section = get_post_meta($post_id, "tls_section", true);
 
    return array("section" => $section);
}

Add links for specific files (for example an edition level podcast).

add_filter('pugpig_add_link_items', 'your_extension_add_link', 10, 2);
function your_extension_add_link($links, $post) {
  $slug = pugpig_get_first_category_slug($post);
  if ($slug == "biology") {
    $permalink = get_permalink($post->ID);
 
    $links[] =  array(
      'rel'   => 'bookmark',
      'type'  => 'text/html',
      'title' => 'My Magazine',
      'href'  => pugpig_strip_domain($permalink) 
    );
  }
 
  return $links;
}

Modify the returned page sharing link

add_filter('pugpig_page_sharing_link', 'your_extension_page_sharing_link', 10, 2);
function your_extension_page_sharing_link($link, $post) {
 
  $url = parse_url($link);
  $updated_url = str_replace($url['host'], "www.example.com", $link);
 
  return $updated_url;
}

Sometimes you might want to return the post's syndication link:

add_filter('pugpig_page_sharing_link', 'your_extension_page_sharing_link', 10, 2);
function your_extension_page_sharing_link($link, $post) {
 
  $syndication_permalink = get_post_meta($post->ID, "syndication_permalink", true);
 
  if (!empty($syndication_permalink)) {
    return $syndication_permalink;
  }
 
  return $link;
}
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Powered by Zendesk