Author Topic: echo iTunes Author in page template  (Read 1558 times)

amax2222

  • Full Member
  • **
  • Posts: 10
echo iTunes Author in page template
« on: May 31, 2012, 09:23:32 am »
Hi, I would like to know how I can echo the iTunes Author / iTunes Summary of the podcast into my page template? Thank you

angelo

  • CIO, RawVoice
  • Administrator
  • Hero Member
  • *****
  • Posts: 4483
Re: echo iTunes Author in page template
« Reply #1 on: May 31, 2012, 11:37:35 am »
You could hard code that into your template, after all, it is your template for your podcast.

amax2222

  • Full Member
  • **
  • Posts: 10
Re: echo iTunes Author in page template
« Reply #2 on: June 01, 2012, 05:05:12 am »
surely the iTunes info relating to the podcast is stored in the post, custom fields, or database that I can retrieve via a query? What query would I use?

angelo

  • CIO, RawVoice
  • Administrator
  • Hero Member
  • *****
  • Posts: 4483
Re: echo iTunes Author in page template
« Reply #3 on: June 01, 2012, 09:17:02 am »
Oh, sorry I misunderstood.

WordPress get_option() function is what you want to call, and for the main PowerPress settings (Not category or channel settings) you would use 'powerpress_general' as the first argument. The returned value is an associative array, the key name for the iTunes Subscription URL is 'itunes_url'. Here's an example.

Code: [Select]
<?php
...
$PowerPressGeneral get_option(&#39;powerpress_general&#39;);
echo htmlspecialchars($PowerPressGeneral[&#39;itunes_url&#39;]);
...
?>

I did not check the code above for errors, but that's the general idea. You would want to check the value first before echoing it in case PowerPress settings were never saved. something like if( !empty($PowerPressGeneral['itunes_url']) ) echo htmlspecialchars(...

amax2222

  • Full Member
  • **
  • Posts: 10
Re: echo iTunes Author in page template
« Reply #4 on: June 08, 2012, 07:19:22 am »
Hi Angelo, thanks for the reply. This returns a blank. If I do a print_r on the $PowerPressGeneral, I get a list of arrays with sub arrays, yet I still cannot retrieve any data via this variable. Just to clarify I'm trying to echo the iTunes Author linked to a specific podcast, which I have entered in the blubrry meta box area. Thank you.

amax2222

  • Full Member
  • **
  • Posts: 10
Re: echo iTunes Author in page template
« Reply #5 on: June 08, 2012, 08:30:49 am »
ok this is how I got the variables out,

   // Get the enclosure data
   $enclosureData = get_post_meta($post->ID, 'enclosure', true);

      list($EnclosureURL, $EnclosureSize, $EnclosureType, $EnclosureStuff) = split("\n", $enclosureData);
      $EnclosureURL = trim($EnclosureURL);
      
      $EnclosureStuff = unserialize($EnclosureStuff);
      
      $author = $EnclosureStuff['author'];
      $subtitle = $EnclosureStuff['subtitle'];
      $duration = $EnclosureStuff['duration'];
      $keywords = $EnclosureStuff['keywords'];

angelo

  • CIO, RawVoice
  • Administrator
  • Hero Member
  • *****
  • Posts: 4483
Re: echo iTunes Author in page template
« Reply #6 on: June 08, 2012, 10:26:25 am »
You figured it out before I got a chance to reply.

There's a helper function in PowerPress that returns all this in a nice array as well. You may also need to use another powerpress helper function to format the duration value, as in the database it's stored as seconds, not the readable HH:MM:SS.

amax2222

  • Full Member
  • **
  • Posts: 10
Re: echo iTunes Author in page template
« Reply #7 on: July 06, 2012, 09:19:00 am »
Hi Angelo, I have discovered that my code works fine for the default feed but not for custom channels, please can you advise me of the required helpers. thank you

angelo

  • CIO, RawVoice
  • Administrator
  • Hero Member
  • *****
  • Posts: 4483
Re: echo iTunes Author in page template
« Reply #8 on: July 06, 2012, 09:43:16 am »
Rather than call get_post_meta($post->ID, 'enclosure', true); I would recommend using the PowerPress function: powerpress_get_enclosure_data(), it returns an associative array with the following keys: id (post id), feed (feed slug name), url (media URL), duration (in seconds), size, type, width, height (for video) plus all other attributes if configured such as keywords, summary, subtitle, etc...

Using powerpress_get_enclosure_data() has a number of advantages. First, if the user configures stats, the redirect will be added to the URL. It will also populate the size and type if they are empty based on the file extension.

powerpress_get_enclosure_data() it takes 2 arguments: $post_id, $feed_slug

Post ID is obvious. The Feed slug is the same slug value as the feed. e.g. the default podcasts feed slug is 'podcast'. So to get that podcast data you call powerpress_get_enclosure_data($post->ID, 'podcast');

powerpress_get_enclosure_data($post->ID, 'podcast'); is the equivalent to $enclosureData = get_post_meta($post->ID, 'enclosure', true); + all that other code you have to split the value and pull out the duration and keywords.

So if you created a channel with the slug name 'pdf and you want the itunes keywords, you could do the following...

Code: [Select]
$EpisodeData = powerpress_get_enclosure_data($post->ID, 'pdf');
if( !empty( $EpisodeData['keywords']) )
 echo trim( implode(', ', $EpisodeData['keywords']), ', ');

You can get a list of all the channel slug names by doing the following...
Code: [Select]
$PowerPressSetings = get_option('powerpress');
$Channels = array('podcast'=>'Default Podcast Feed');
if( !empty($PowerPressSetings['custom_feeds']) )
  $Channels = array_merge($Channels,  $PowerPressSetings['custom_feeds']);

while( list($channel_slug, $channel_title) = each($Channels) )
{
   // Do something here...
}

You're getting pretty deep into this! If you're making a theme that will be available on wordpress.org, let me know and we'll link to it in the plugin's readme.txt as well as on the PowerPress wordpress.org page.

amax2222

  • Full Member
  • **
  • Posts: 10
Re: echo iTunes Author in page template
« Reply #9 on: July 31, 2012, 05:37:46 am »
Angelo that works a treat!! Many thanks, will post a link once we done.