• Hi,

    I’m trying to create a shortcode, that could contain a value that would be dynamic.

    For instance, I want to create a shortcode so a user can download a zip file. but I want to be able to specify the name of the zip file each time. Like this:
    [zip “filename.zip”]
    (I don’t know if my syntax is correct or not?)

    The idea would be that the shortcode “zip” would launch a php code, that contains an “a href” to a folder, and the value “filename/zip” would be the file to fetch at that “a href”.

    More precisely, here is the code I am using (I use POST SNIPPETS plugin to create the shortcodes):

    if($api->haveSubscriptions($api->getCategoryProducts(46)){
    print “<a href=http://www.website.com/folder/filename.zip>download zip”;
    }else if($api->getUser()){
    print “user doesn’t have access”;
    }else{
    print “Guest”;
    }

    In the code above, I want to replace “/filename.zip” with a dymanic value that would be defined into the shortcode.
    [zip “filename.zip”]

    Is this possible>

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    You can try something like:

    [zip file="filename"]

    Thread Starter martinperreault

    (@martinperreault)

    Actually, I found the solution:

    // [zip file=”file-value”]
    add_shortcode( ‘zip’, ‘zip_func’ );
    function zip_func( $atts ) {

    // zip function to return file dynamic ID
    $a = shortcode_atts( array(
    ‘file’ => ‘sample.zip’,
    ), $atts );

    if($api->haveSubscriptions($api->getCategoryProducts(46))){
    return ‘You’re a Subscriber: **a href=”http://www.website.com/files/&#8217; . $a[‘file’] . ‘”**download’;

    }else if($api->getUser()){
    return ‘not subscribed’;

    }else{
    return ‘Guest’;
    }

    }

    (replace ** with < and >)

    Then the admin needs to add the following shortcode:
    [zip file”filename.zip”>

    If admin only enters [zip] , the the default filename “sample.zip” will be the target file.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Need help: how to create a shortcode containing a dynamic value’ is closed to new replies.