WordPress.org

Forums

SoundCloud Is Gold
[resolved] SIG In The Theme / Outside The Post (4 posts)

  1. digiman9999
    Member
    Posted 1 year ago #

    Hi All,

    I've been struggling for hours now trying to get the SIG plug used in content-single.php of twentyeleven.

    <?php
    $ref = get_post_meta($post->ID, 'soundcloud1', true);
    echo do_shortcode('[soundcloud id=$ref artwork=false playerType=html5]'); ?>

    As you can see, the Soundcloud ID is stored in a custom field, so it can be recalled multiple times throughout the site. With this code, the player shows, but the track does not. It seems the $ref is not working, and I don't know how to get it to. Any thoughts?

    Regards
    Digiman

    http://wordpress.org/extend/plugins/soundcloud-is-gold/

  2. realtm
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Digiman,

    maybe try putting your shortcode in a string and then use it in do_shortcode:

    $myShortcode = "[soundcloud id=".get_post_meta($post->ID, 'soundcloud1', true)." artwork=false playerType=html5]"
    echo do_shortcode($myShortcode);

    Have you checked what you get from "get_post_meta($post->ID, 'soundcloud1', true)"? I think it's an array and you have to use it like this:

    echo do_shortcode('[soundcloud id=$ref[0] artwork=false playerType=html5]'); ?>

    You can use var_dump($ref) to check, but you might already know that :)

    What are you trying to achieve by the way? Are you trying to place a player outside of content()?

    If it's that; what I did for my website is that I'm adding the player though the soundcloud-is-gold button but in my "content-single.php" I use a regular expression to find the SIG shortcode, remove it from the content and then add it outside in the desired place. This way it's easy to update a page.

  3. digiman9999
    Member
    Posted 1 year ago #

    Hi realtm,

    Many thanks for your comment, your PHP skills are much better than mine and worked a treat. It's use is to use WP custom fields to store a Soundcloud ID. This can then be called to include a track either on a single post, or as a compilation of all tracks from all posts, like a jukebox elsewhere on the site. For those looking to do this themselves, here's the final code included in content-single.php, only displaying the Soundcloud box if a track ID is present:

    <?php if (get_post_meta($post->ID,'soundcloud1',true))
    {
    $myShortcode = "[soundcloud id=".get_post_meta($post->ID, 'soundcloud1', true)." artwork=false playerType=html5]";
    echo do_shortcode($myShortcode);
    }
    ?>

    Awesome, cheers

  4. realtm
    Member
    Plugin Author

    Posted 1 year ago #

    Great, I'm glad I could help and thank you for sharing your solution.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic