WordPress.org

Ready to get started?Download WordPress

Forums

Seriously Simple Podcasting
[resolved] Calling audio player to another page template? (14 posts)

  1. jolaedana
    Member
    Posted 1 year ago #

    Hi there, hoping someone here can help me out.

    I am working on a custom home page template where we'd like to embed the most recent podcast's audio player below the excerpt of the post, so they can listen directly from the website's homepage without having to click through.

    I am using the following code to accomplish this so far, but have been unable to figure out how to call the audio player itself, in spite of copying and pasting the code from the single-podcast.php template file.

    <?php $query = new WP_Query( array( 'post_type'=>'podcast', 'taxonomy'=>'featured', 'posts_per_page' => 1 ) );
    while ($query->have_posts()) : $query->the_post();?>
            <article>
              <header class="article-header">
                <h1 class="h2"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
                  <?php the_title(); ?>
                  </a></h1>
                <p class="byline vcard">
                  <?php printf(__('Posted <time class="updated" datetime="%1$s" pubdate>%2$s</time> by <span class="author">%3$s</span> <span class="amp">&</span> filed under %4$s.', 'bonestheme'), get_the_time('Y-m-j'), get_the_time(get_option('date_format')), bones_get_the_author_posts_link(), get_the_category_list(', ')); ?>
                </p>
              </header>
              <!-- end article header -->
              <section class="entry-content clearfix">
                <?php the_excerpt(); ?>
         <a href="<?php echo get_post_meta(get_the_ID(), 'enclosure', true) ?>">Download Audio</a>
               Duration: <?php echo get_post_meta(get_the_ID(), 'duration', true) ?> | Size: <?php echo get_post_meta(get_the_ID(), 'filesize', true) ?>
              </section>
    
              <!-- end article section -->
            </article>

    Obviously I figure out how to call the custom meta data, but I can't seem to get any of that to become the embedded player. Is there some class or ID that the script looks for specifically? I am working on examining the plugin code in more depth, but my functional PHP is still a work in progress.

    Thanks in advance!

    http://wordpress.org/extend/plugins/seriously-simple-podcasting/

  2. Hugh Lashbrooke
    Member
    Plugin Author

    Posted 1 year ago #

    This code will load the audio player for you:

    global $ss_podcasting;
    $enclosure = $ss_podcasting->get_enclosure( get_the_ID() );
    if( $enclosure ) {
        $audio_player = $ss_podcasting->audio_player( $enclosure );
        echo $audio_player;
    }
  3. jolaedana
    Member
    Posted 1 year ago #

    Hugh, thank you so much for the quick response!

    At least I know my muddling through functions was on the right track. :) Thanks again for the code.

  4. AardvarkGirl
    Member
    Posted 1 year ago #

    My php is also a work in progress, so I humbly ask, where exactly do we use the code to load the audio player? :(

    I'm trying to see the all the players in the 'archive' template I'm working on, and not have to go to single view to see the individual player.

    I started out using this, but then I tried jolaedana's code up top. I tried sticking that code to load the audio player everywhere (LOL).

    <?php $args = array( 'post_type' => 'podcast', 'posts_per_page' => 10 );
    $loop = new WP_Query( $args );
    
    while ( $loop->have_posts() ) : $loop->the_post();
    	the_title();
    
    	echo '<div class="entry-content">';
    	the_content();
    
    	echo '</div>';
    endwhile;
    ?>
  5. jolaedana
    Member
    Posted 1 year ago #

    Hey @AardvarkGirl - my code was terrible, don't use it! lol.

    Here's what I ended up using:

    <?php global $ss_podcasting;
    $enclosure = $ss_podcasting->get_enclosure( get_the_ID() );
    if( $enclosure ) {
        $audio_player = $ss_podcasting->audio_player( $enclosure );
        echo $audio_player;
    } ?>

    Works great! You do need to have it within a loop, so for example:

    <?php $query = new WP_Query( array( 'post_type'=>'podcast', 'series'=>'featured', 'posts_per_page' => 1 ) );
    while ($query->have_posts()) : $query->the_post();
    ?>
    <?php the_title(); ?>
    <div id="audio">
    <?php global $ss_podcasting;
    $enclosure = $ss_podcasting->get_enclosure( get_the_ID() );
    if( $enclosure ) {
        $audio_player = $ss_podcasting->audio_player( $enclosure );
        echo $audio_player;
    } ?>
    </div>
    <div id="audioinfo">
    <a class="button" href="<?php echo get_post_meta(get_the_ID(), 'enclosure', true) ?>">Download Audio</a>
    <span class="audiometa">
    Duration: <?php echo get_post_meta(get_the_ID(), 'duration', true) ?> | Size: <?php echo get_post_meta(get_the_ID(), 'filesize', true) ?>
    </span>
    </div>
  6. AardvarkGirl
    Member
    Posted 1 year ago #

    I will give it a go jolaedana - and promise to pay it forward. Thanks! :)

  7. AardvarkGirl
    Member
    Posted 1 year ago #

    jolaedana -

    Is there meant to be a <?php endwhile; ?> at the end of that? It threw an error for me without it.

    Did you just drop this on a standard 'archive' template? I'm not getting the player still. I changed the series to one I created and made sure at least two post were categorized as that. I tried it without the series in it.

    This is what I'm using on that template named archive-podcast in my child 2012 theme folder:

    <?php
    /**
     * Template for podcast archive pages
     *
     * @package WordPress
     * @subpackage SeriouslySimplePodcasting
     * @author Hugh Lashbrooke
     * @since 1.0.0
     */
    
    get_header(); ?>
    
    	<section id="primary" class="site-content">
    		<div id="content" role="main">
    <?php $query = new WP_Query( array( 'post_type'=>'podcast', 'series'=>'sermons', 'posts_per_page' => 1 ) );
    while ($query->have_posts()) : $query->the_post();
    ?>
    <?php the_title(); ?>
    <div id="audio">
    <?php global $ss_podcasting;
    $enclosure = $ss_podcasting->get_enclosure( get_the_ID() );
    if( $enclosure ) {
        $audio_player = $ss_podcasting->audio_player( $enclosure );
        echo $audio_player;
    } ?>
    <?php the_content(); ?>
    </div>
    <div id="audioinfo">
    <a class="button" href="<?php echo get_post_meta(get_the_ID(), 'enclosure', true) ?>">Download Audio</a>
    <span class="audiometa">
    Duration: <?php echo get_post_meta(get_the_ID(), 'duration', true) ?> | Size: <?php echo get_post_meta(get_the_ID(), 'filesize', true) ?>
    </span>
    </div>
    <?php endwhile; ?>
    
    			<div class="podcast_clear"></div>
    		</div><!-- #content -->
    	</section><!-- #primary -->
    
    <?php get_footer(); ?>

    And I created a unique header file to make sure the page had the 'single' classes (if that is at all relevant) and tried that as well.

    I've also tried it with and without <?php the_content(); ?>

    I did try two other audio plugins BEFORE this one, and they have been deactivated and deleted from the plugin library. I have also deactivated the other 6 plugins to be sure this isn't the problem.

    Did a hard refresh and tried it in another browser. LOL. :)

    http://ratest3.com/podcast/

  8. jolaedana
    Member
    Posted 1 year ago #

    Yeah, there should be an end to the loop. Sorry, I shouldn't assume folks are up 100% on stuff! Also, sloppy copy paste. I used
    <?php endwhile; wp_reset_query(); ?>

    Because that's what worked on my template. You may need to look into what kind of loop you need to use in your template file.

    I used this on a custom page template- archive templates and single page templates work a bit differently, I think.

    You'll definitely want to customize the loop values to suit what you're calling, that's just what I used to call my Featured series of podcast files.

  9. AardvarkGirl
    Member
    Posted 1 year ago #

    Ok, I got it worked out :) THANKS!

  10. AardvarkGirl
    Member
    Posted 1 year ago #

    I have one more question for you both.

    I've got the player... and title of each episode post. When I use either the_content or the_excerpt I don't get what is in the text editor for that post ALONE, I get whats in the text editor of that post AND the meta info for the media file. Here is a screen shot

    http://ratest3.com/wp-content/uploads/2013/07/AngierPlay2.jpg

    jolaedana, When I use your code (except pulling in 6 posts vs 1) I get duplicates of the meta - one of which is with the content of the post itself.

    <?php $query = new WP_Query( array( 'post_type'=>'podcast', 'posts_per_page' => 6 ) );
    while ($query->have_posts()) : $query->the_post();
    ?>
    <?php the_title(); ?>
    <div id="audio">
    <?php global $ss_podcasting;
    $enclosure = $ss_podcasting->get_enclosure( get_the_ID() );
    if( $enclosure ) {
        $audio_player = $ss_podcasting->audio_player( $enclosure );
        echo $audio_player;
    } ?>
    <?php the_content(); ?>
    </div>
    <div id="audioinfo">
    <a class="button" href="<?php echo get_post_meta(get_the_ID(), 'enclosure', true) ?>">Download Audio</a>
    <span class="audiometa">
    Duration: <?php echo get_post_meta(get_the_ID(), 'duration', true) ?> | Size: <?php echo get_post_meta(get_the_ID(), 'filesize', true) ?>
    </span>
    </div>
    <?php endwhile; ?>
    			<div class="podcast_clear"></div>

    I get the same result whether I use the_content or the_excerpt with the code I'm using on my template file;

    <?php  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $query = new WP_Query( array( 'post_type'=>'podcast', 'paged' => $paged, 'posts_per_page' => 6,   ) );
    while ($query->have_posts()) : $query->the_post();
    ?>
    
    <div class="podcast">
    						<h2 class="audio-title"><?php the_title(); ?></h2>
                           <div class="audio-info"> <?php the_excerpt(); ?></div>
    <div id="audio">
    <?php global $ss_podcasting;
    $enclosure = $ss_podcasting->get_enclosure( get_the_ID() );
    if( $enclosure ) {
        $audio_player = $ss_podcasting->audio_player( $enclosure );
        echo $audio_player;
    } ?>
    </div><!-- audio -->
    
    <span class="audiometa">
    Duration: <?php echo get_post_meta(get_the_ID(), 'duration', true) ?> | Size: <?php echo get_post_meta(get_the_ID(), 'filesize', true) ?>
    </span>
    </div><!-- podcast -->
    <?php endwhile; ?>
                <div class="clear"></div>
    <?php posts_nav_link(); ?>

    Is there something I'm misunderstanding about using the_content/the_excerpt when using this plugin?

    I also can not insert an image in the text editor using the 'Add Media' button.

  11. Matthew Fries
    Member
    Posted 1 year ago #

    Hugh - thanks for posting the answer. Just what I needed.

  12. jolaedana
    Member
    Posted 1 year ago #

    AardvarkGirl, I am also having problems using this code to call the player anywhere that isn't in a single instance on a page template.

    Not sure how to fix it yet, I guess it must be the way it interacts (or doesn't), with the loop.

    I'm going to have to fix this, but I'm not as versed in PHP as I'd like- I'll let you know if I figure out something that works.

    Personally, when I am using this code on a single post template, I am finding that it's using the length of OTHER podcast files and only playing up to that time, even if the new file is longer. I'm also finding that the player doesn't work at all in Chrome when called on a single page, for some reason, though it works when I use the code to call the player on the home page.

    Very puzzled, still working on a solution. I may have to go back to the original templates that came with the plugin and see if I can figure out how to move the player. :/

    EDIT: Interesting. Now when I visit the pages, even when I use the default templates that came with the plugin, the player doesn't load. I may have a completely separate plugin conflict or some other theme issue.

    EDIT: Player still not showing or working on single post pages using the 2012 theme and no additional plugins with default plugin templates in Safari. Ugh. No idea what changed since I was working on Friday! Will keep looking.

  13. jolaedana
    Member
    Posted 1 year ago #

    Okay. Please disregard above. I am making progress and will post the solution back when I get it right. ;)

  14. AardvarkGirl
    Member
    Posted 1 year ago #

    I've got it posting multiple players http://ratest3.com/podcast/ I'm just not clear on the use of the_content or posting images.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.