2010-12-15 24 views
1

<?php echo do_shortcode('[gallery id="25"]'); ?>リミット私が使用しているコードのギャラリーアイテムWordPressの出力

の数が、私は2つの項目の代わりに、すべての項目に限定する方法が必要です。私は、ギャラリーshortcodeでそれを行うネイティブな方法はないと知っていますが、私は使用することができるプラグインや代替方法がありますか?

+0

使用してみてください[次世代ギャラリー](http://wordpress.org/extend/plugins/nextgenような何かを行うことができます-gallery /)を使用し、[そのAPI](http://nextgen-gallery.com/custom-fields/) – pootzko

答えて

0

あなたは、テンプレートののfunctions.php内ギャラリーショート機能を書き換え、この

remove_shortcode('gallery'); 
add_shortcode('gallery', 'parse_gallery_shortcode'); 
function parse_gallery_shortcode($atts) { 

global $post; 

extract(shortcode_atts(array(
'order'  => 'ASC', 
'orderby' => 'menu_order ID', 
    'id' => $post->ID, 
    'itemtag' => 'dl', 
    'icontag' => 'dt', 
    'captiontag' => 'dd', 
    'columns' => 3, 
    'ids' => '', 
    'size' => 'medium', 
    'link' => 'file' 
), $atts)); 

$ids = explode(',', $atts[ids]); 
$i = 0; 
foreach($ids as $id) { 
    $i++; 
    if ($i > 2) { break; } 
    // or replace 2 with how many images you want 
$image = get_post($id); 
$img = wp_get_attachment_image_src($image->ID, 'post-onephoto'); 
$largeimg = wp_get_attachment_image_src($image->ID, 'large'); 
// this is where you output your images the way you want it 
$return .= '<a href="'.$largeimg[0].'"><img width="400" height="400" src="'.$img[0].'" /></a>'; 
} 

return $return; 
} 
関連する問題