simple php problem

Discussion in 'BlackHat Lounge' started by Rasacz, May 16, 2012.

  1. Rasacz

    Rasacz Power Member

    Joined:
    Oct 27, 2009
    Messages:
    510
    Likes Received:
    194
    Location:
    Poland
    Hi!
    Im beginner at php coding (i can just edit simple codes) so im using wordpress and artisteer.
    Unfortunately i still have to do some editing... and i've got part of code i don't understand.
    So could you guys help me chaning 16 may to actual date?
    Code:
    if (!function_exists('art_get_metadata_icons')){	function art_get_metadata_icons($icons = '', $class=''){
    		global $post;
    		if (!is_string($icons) || strlen($icons) == 0) return;
    		$icons = explode(",", str_replace(' ', '', $icons));
    		if (!is_array($icons) || count($icons) == 0) return;
    		$result = array();
    		for($i = 0; $i < count($icons); $i++){
    			$icon = $icons[$i];
    			switch($icon){
    				case 'date':
    					$result[] = sprintf( __('<span class="%1$s">Published at 16 may, 2012</span> ', THEME_NS),
    									'date',
    									sprintf( '<span class="entry-date"><abbr class="published" title="%1$s">%2$s"</abbr></span>',
    										esc_attr( get_the_time() ),
    										get_the_date()
    									)
    								);
    				break;
    Thanks!
     
  2. ADHD-Dude

    ADHD-Dude Power Member

    Joined:
    Apr 17, 2010
    Messages:
    592
    Likes Received:
    119
    get_the_date() will get the date, try to remove 16 may, 2012 and replace THEME_NS with get_the_date()
     
    • Thanks Thanks x 1
  3. Rasacz

    Rasacz Power Member

    Joined:
    Oct 27, 2009
    Messages:
    510
    Likes Received:
    194
    Location:
    Poland
    Doesn't work :(
     
  4. Rasacz

    Rasacz Power Member

    Joined:
    Oct 27, 2009
    Messages:
    510
    Likes Received:
    194
    Location:
    Poland
    Anyone?
     
  5. Abstroose

    Abstroose Elite Member

    Joined:
    Nov 20, 2008
    Messages:
    2,097
    Likes Received:
    3,498
    Occupation:
    Thai Boxer
    Location:
    UK
    Try this:

    Code:
    $today = get_the_date();
    if (!function_exists('art_get_metadata_icons')){	function art_get_metadata_icons($icons = '', $class=''){
    		global $post;
    		if (!is_string($icons) || strlen($icons) == 0) return;
    		$icons = explode(",", str_replace(' ', '', $icons));
    		if (!is_array($icons) || count($icons) == 0) return;
    		$result = array();
    		for($i = 0; $i < count($icons); $i++){
    			$icon = $icons[$i];
    			switch($icon){
    				case 'date':
    					$result[] = sprintf( __('<span class="%1$s">Published at '.$today.'</span> ', THEME_NS),
    									'date',
    									sprintf( '<span class="entry-date"><abbr class="published" title="%1$s">%2$s"</abbr></span>',
    										esc_attr( get_the_time() ),
    										get_the_date()
    									)
    								);
    				break;
    
     
  6. derpbuz

    derpbuz Registered Member

    Joined:
    Mar 29, 2012
    Messages:
    89
    Likes Received:
    17
    you would like to change 16 May, so wouldn't it be replacing 16 May 2012 to

    get_the_date(), by using the %s in sprintf?

    Check our the syntax of sprintf then you will get the code. I don't think you have to change the THEME_NS.