WordPress.org

Ready to get started?Download WordPress

Forums

podPress
[resolved] Add code to template instead of using shortcode in post (7 posts)

  1. tessina
    Member
    Posted 3 years ago #

    Is there a way to add some php code to call the podcast in the single.php theme template, instead of using the [display_podcast] shortcode when making the post?

  2. ntm
    Member
    Plugin Author

    Posted 3 years ago #

    podPress uses e.g. the the_content filter hook to look through the post content for such a place holder to replace it with the podPress code. If a post content does not contain a place holder then podPress attaches a place holder accordingly to the settings at the beginning or end of the content before it replaces the place holder with the code.

    So, all thing are set up work with such place holder. But you could take a look at the podpress_theme.php file it contains the function which assembles the code podPress inserts instead of the place holder. This function gets all the necessary data ($podPressTemplateData) from the insert_content() function of the podPress_class (podpress_class.php).

    But it might be easier to apply a filter to this part of the content which should contain the podPress code. You could add

    apply_filters('my_filter', $the_content_which_should_contain_the_podPress_code );

    to the template file at the place you want it to (see apply_filters). This is a new filter hook. If you have done that you can add all kinds of filters to that hook.

    Like the podPress filter which is used usually for the post content (the_content). For instance:

    Global $podPress;
    add_filter('my_filter', array(&$podPress, 'insert_content'));

    It should be okay if you place that second snippet in the functions.php of your theme.

    I hope that this helps you a little bit. But without knowing your goal it is not easy to give better hints.

    Regards,
    Tim

  3. tessina
    Member
    Posted 3 years ago #

    Hi Tim, thanks for your prompt response. I'm not very versed in PHP, or wordpress coding in general, so forgive me if I don't explain myself clearly enough.

    As it is right now, my authors need to add the podcast details when creating a post, plus add the shortcode into the formatting. Because most of them are not good at technical tasks, they often forget to add in the shortcode to display the podcast in the post editor.

    So I'm hoping to just add display_podcast to the single.php theme file, so they don't have to add the shortcode manually into each post they write.
    I tried:

    <?php echo do_shortcode('[display_podcast]') ?>

    but it didnt seem to work. Any ideas?

  4. tessina
    Member
    Posted 3 years ago #

    alchymyth, these are not duplicate, each thread is referencing 2 different podcasting plugins?

  5. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    looked similar enough, to me :-(
    i am going to unlock the other thread.

  6. ntm
    Member
    Plugin Author

    Posted 3 years ago #

    @tessina:
    podPress adds the podcast details and e.g. the player automatically before or after the content of a post. It is not necessary to use the shortcode.

    You can use the shortcode to determine the position of the podcast episode details if these elements should somewhere in the content e.g. among the describing text.

    But if you want to place the podPress elements not in, before or after the content then you can use this idea with the filter.
    For instance:
    Add this

    remove_filter('the_content', array(&$podPress, 'insert_content'));

    to the single.php before The Loop after get_header() to remove the podPress element from the content.
    Add this

    if ( TRUE == isset($podPress) ) {
    	echo apply_filters('my_filter_name', '[display_podcast]' );
    }

    at the place in the single.php where the podPress elements should appear.
    Furthermore you need to add this

    add_filter('my_filter_name', array(&$podPress, 'insert_content'));

    e.g. to the functions.php of your theme.

    You could also put the output of the filter into a variable and echo or print it later:

    if ( TRUE == isset($podPress) ) {
    	$podpress_elements = apply_filters('my_filter_name', '[display_podcast]' );
    }

    Regards,
    Tim

  7. tessina
    Member
    Posted 3 years ago #

    Hey Tim, thanks for walking me through the process.
    I managed to get it working after echoing the $podpress_elements variable :D

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags