2013-06-24 34 views
0

基本上我試圖做一個簡單的簡碼,其中用戶可以顯示一個固定大小的圖像,無論大小。例如,[圖庫]圖片[/圖庫]它會顯示這樣的試圖開發一個簡單的簡碼

http://i255.photobucket.com/albums/hh140/testament1234/thumb_zps5820cef3.png

我試着想出我自己的代碼,但看起來像我的代碼是錯誤的。我還不熟悉PHP或wordpress編碼。我知道這樣的事情可以用插件來完成,但我寧願學習如何編寫

function image_gallery($atts, $content=null) { 
extract(shortcode_atts(array(
'width' => 400, 
'height' => 200, 
), $atts)); 
return '<div class="gallery"></div>'; 
} 
add_shortcode('gall', 'image_gallery'); 

樣式通過style.css文件被提供

回答

0
function image_gallery($atts, $content=null) { 
    extract(shortcode_atts(array(
     'width' => 400, 
     'height' => 200, 
     'image' => '' 
    ), $atts)); 

    return '<div class="gallery"><img src="'.$image.'" width="'.$width.'" height="'.$height.'" /></div>'; 
} 
add_shortcode('gall', 'image_gallery'); 

激活插件

在您的文章或頁面添加此簡碼[gall image =「path_to_your_image」]