2017-04-12 26 views
0

私は、風景ギャラリー画像の結果を与えるforeachループを持っています。 は、基本的にはforeachループ - 別の設定のケース

<?php foreach ($images as $image) : ?> 

で始まり、その後、ギャラリーの画像の正規のdiv +アンカー+画像タグ。

<?php if ($image->description == "portrait") : ?> 

<div id="ngg-image-<?php echo $image->pid ?>" class="ngg-gallery-thumbnail-box portrait" <?php echo $image->style ?> > 


<div class="ngg-gallery-thumbnail" > 

     <a class="portrait-image" href="<?php echo $image->imageURL ?>" title=" " id="<?php echo $image->alttext ?>" rel="lightbox" <?php echo $image->thumbcode ?> >   
     <img title="<?php echo ' ' /* $image->alttext */ ?>" alt="<?php echo ' ' /* $image->alttext */ ?>" src="<?php echo $image->thumbnailURL ?>" <?php echo $image->size ?> /> 
     </a> 

<?php else: ?> 

<div id="ngg-image-<?php echo $image->pid ?>" class="ngg-gallery-thumbnail-box landscape" <?php echo $image->style ?> > 


<div class="ngg-gallery-thumbnail" > 

     <a class="landscape-image" href="<?php echo $image->imageURL ?>" title=" " id="<?php echo $image->alttext ?>" rel="lightbox" <?php echo $image->thumbcode ?> >   
     <img title="<?php echo ' ' /* $image->alttext */ ?>" alt="<?php echo ' ' /* $image->alttext */ ?>" src="<?php echo $image->thumbnailURL ?>" <?php echo $image->size ?> /> 
     </a> 


<?php endif; ?> 

私は2つのポートレート画像を並べて1つの風景画像のスペースを埋める特殊なケースが必要です。

私が考えていたことは、foreachループのブレークアウトを引き起こして1つのコンテナdiv内に2つのイメージを持つタグを管理領域に持たせてから、コンテナ+風景画像用の画像。 foreachループの場合は、ループから飛び出して別の設定で大文字小文字を区別し、通常のループ方法に戻ることは可能ですか?

+1

はもっとここに – Akintunde007

+0

内部CSSのことのように聞こえるのコードですあなたの特別なケースのためにif/thenを持ってください。あなたは "ループから飛び降りる"ことはできません。 –

+1

肖像画の数が奇数だったらどうしますか? – Lambasoft

答えて

1

あなたはこのような何かを試すことができます:あなたのCSSで次に

foreach($images as $key => $image) { 
    if($image has special tag) { // <--- PSEUDOCODE 
     echo "<div class='SPECIAL_CSS_CLASS'><img src='" . $img->path . "' /></div>"; 
    } 
} 

は自分の魔法を行います!

1

私が先に行くと、このようなものだろう:私はjQueryのでグループを作るために管理

//Function to get all the images based on a specific portrait_group 
function getImagesPortraitGroup($group, $images) { 
    $result = array(); 
    foreach ($images as $image) { 
     if (isset($image['portrait_group']) && $image['portrait_group'] == $group) { 
      $result[] = $image; 
     } 
    } 
    return $result; 
} 

//The images to show 
$images = array(
    ["url" => "http://lorempixel.com/400/200/", "caption" => "Lorem Image1", "portrait_group" => 1], 
    ["url" => "http://lorempixel.com/400/200/", "caption" => "Lorem Image2", "portrait_group" => 1], 
    ["url" => "http://lorempixel.com/800/200/", "caption" => "Lorem Image3"], 
    ["url" => "http://lorempixel.com/400/200/", "caption" => "Lorem Image4", "portrait_group" => 2], 
    ["url" => "http://lorempixel.com/400/200/", "caption" => "Lorem Image5", "portrait_group" => 2], 
); 

//Everytime we show a group, we track it by adding it to this array in order not to show it again 
$addedGroups = array(); 

//Loop through all the images 
for ($i = 0; $i < count($images); $i++) { 
    echo "<div>"; 

    //If the image has a portrait_group that is not already shown, show it 
    if (isset($images[$i]['portrait_group']) && !in_array($images[$i]['portrait_group'], $addedGroups)) { 
     $groupImages = getImagesPortraitGroup($images[$i]['portrait_group'], $images); 
     foreach ($groupImages as $image) { 
      echo "<img src='{$image['url']}' title='{$image['caption']}' >"; 
     } 
     //Save the group to the array in order not to show it again 
     $addedGroups[] = $images[$i]['portrait_group']; 
    } else { 
     echo "<img src='{$images[$i]['url']}' title='{$images[$i]['caption']}' >"; 
    } 
    echo "</div>"; 
} 
+0

ありがとうございましたが、私はギャラリー管理プログラムにあらかじめ定義された配列を持っているので、動作させることができませんでした。あなたの例のように動作させるために回ってください。 – Gas

0

を、これは

jQuery(".ngg-gallery-thumbnail-box.portrait").filter(":odd").each(function(){ 
    $content = jQuery(this).find("a"); 
    jQuery(this).prev().find(".ngg-gallery-thumbnail").append($content); 
    jQuery(this).remove(); 
});