• Resolved Chuckie

    (@ajtruckle)


    Hi!

    I have read the documentation and know that I can use the following shortcode syntax to obtain the download count for a given item:

    [sdm_show_download_info id="123" download_info="download_count"]

    I have three downloads so I can have three shortcode references. No problem with that.

    My issue is that I need to come up with a new shortcode code that basically does this:

    WorkOutDownloadAsPercentage(download id)
        total_msa = get-download-total-for-msa
        total_pts = get-download-total-for-pts
        total_vrr = get-download-total-for-vrr
        total = total_msa + total_pts + total_vrr;
        percent_msa = (100 / total) * total_msa
        percent_pts = (100 / total) * total_pts
        percent_vrr = (100 / total) * total_vrr
    
       if(download id is msa)
           return percent_msa
       else if(download id is pts)
           return percent_pts
       else if(download id is vrr)
          return percent_vrr
    
        return 0

    Some thing like the above in to a shortcode, so I can call:

    [sdm_get_download_as_percent id=xxx]

    I appreciate this can’t be part of your plugin and just custom snippet at my end.

    Thanks for help.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor mbrsolution

    (@mbrsolution)

    Hi, I have submitted a message to the developers to investigate further your request.

    Thank you

    Thread Starter Chuckie

    (@ajtruckle)

    Thank you.

    Plugin Author mra13

    (@mra13)

    You will need to create a custom shortcode for this in a custom little plugin (or addon). It will probably turn out to be a 2-3 hour custom coding job. So I am not sure how I can provide help for this for free.

    Thread Starter Chuckie

    (@ajtruckle)

    Hi

    All I want to know is how I can call one of your short codes (above) and store it’s value to a variable. Is it by using do_shortcode(…)?

    Thread Starter Chuckie

    (@ajtruckle)

    Worked it out ??

    Thread Starter Chuckie

    (@ajtruckle)

    My code:

    function xxx_download_percentage($attr)
    {
    	$id_aaa = aaa;
    	$id_bbb = bbb;
    	$id_ccc = ccc;
    	
    	$args = shortcode_atts( array(
                'download_id' => 'aaa'
            ), $attr );
    	
        $aaa_DownloadCount = do_shortcode('[sdm_show_download_info id="aaa" download_info="download_count"]');
        $bbb_DownloadCount = do_shortcode('[sdm_show_download_info id="bbb" download_info="download_count"]');
        $ccc_DownloadCount = do_shortcode('[sdm_show_download_info id="ccc" download_info="download_count"]');
    	
        $total_DownloadCount = $aaa_DownloadCount + $bbb_DownloadCount + $ccc_DownloadCount;
    	
    	if($args['download_id'] == $id_aaa)
    	{
    		$aaa_Percent = (100 / $total_DownloadCount) * $aaa_DownloadCount;
    		return round($aaa_Percent, 0, PHP_ROUND_HALF_UP);
    	}
    	elseif($args['download_id'] == $id_bbb)
    	{
    		$bbb_Percent = (100 / $total_DownloadCount) * $bbb_DownloadCount;
    		return round($bbb_Percent, 0, PHP_ROUND_HALF_UP);
    	}
    	elseif($args['download_id'] == $id_ccc)
    	{
    		$ccc_Percent = (100 / $total_DownloadCount) * $ccc_DownloadCount;
    		return round($ccc_Percent, 0, PHP_ROUND_HALF_UP);
    	}
    	
        return 0;
    }
    add_shortcode( 'zz_download_percent', 'xxx_download_percentage' );

    Where aaa, bbb and ccc are specific Download ID values.

    Then you can use it:

    [zz_download_percent download_id="aaa"]

    • This reply was modified 4 years, 4 months ago by Chuckie.
    Plugin Contributor mbrsolution

    (@mbrsolution)

    Hi, thank you for sharing your code. I am sure your code will help other trying to achieve the same as you.

    Kind regards

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Using php with your plugin’ is closed to new replies.