Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Forum: Fixing WordPress
    In reply to: Custom shortcode's
    Thread Starter Perphide

    (@perphide)

    Also there are two thing I currently can’t get working:
    1. Use an attribute called r and use it only when it is filled in by the user (I did find I can set the default value to null so it doesn’t do anything, but I did not find a way to check if the user did use the r attribute.

    2. This code makes shortcode like [b1] [b2] while at first I wanted this to be possible (especially the multiple uses of the same atribute:
    [m b=123 b=456 b=789]

    Side note: In the code above I have used ATTR instead of ATTS, maybe that is way a lot of testing late at night failed… however this is now fixed and $atts[0] still doesn’t work… so code above still my current actual code with the misspelling corrected.

    Forum: Fixing WordPress
    In reply to: Custom shortcode's
    Thread Starter Perphide

    (@perphide)

    It works this way…
    I am just wondering if this is the correct (and only) way…

    That is because I think it is weird to check for $content and then use $shortcode.

    I fixed this issue last night, but I am not sure if it is the correct way, see this topic: here

    The reason is: I am checking if $content is null, and then I use $shortcode… seems stupid, but it is the only way that I got it working…

    Forum: Fixing WordPress
    In reply to: Custom shortcode's
    Thread Starter Perphide

    (@perphide)

    It seemed this option above eventually worked, but it could not handle multiple uses of the same type (b/t/k). I now have a temporary fix to shorten my previous 204 lines of almost identical code:

    function tiles_func( $attr = null, $content = null, $shortcode = null ){
    	if (!is_null( $content )) {
    	return '<img class="alignnone" src="'. get_bloginfo('template_directory') .'/images/mahjong%20tiles/' . $shortcode . '.png" alt="" width="35" height="41" />';
    	}
    }

    And for the shortcuts this did the trick to reduce the massive amount of code:

    for( $i = 1; $i <= 9; $i++ ) {
    	add_shortcode( 'b'. $i .'', 'tiles_func' );
    	add_shortcode( 'k'. $i .'', 'tiles_func' );
    	add_shortcode( 't'. $i .'', 'tiles_func' );
    };

    I hope someone else finds this useful, since I spent about 14 hours on this subject today and didn’t quite get the result I wanted.

    I also can’t get $attr[0] to echo… how did you solve this?
    I just want the name of the used shortcode in a variable, that’s all.

Viewing 5 replies - 1 through 5 (of 5 total)