Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Foreach, tylko raz
draqo
post
Post #1





Grupa: Zarejestrowani
Postów: 29
Pomógł: 0
Dołączył: 15.04.2006

Ostrzeżenie: (0%)
-----


Jak zrobić aby ta pętla wykonywała się tylko raz:

  1. <?php
  2. if (is_single()) {
  3.  
  4. $custom_fields = get_post_custom($post->ID);
  5. $my_custom_field = $custom_fields['zdjecie'];
  6.  
  7. foreach ( $my_custom_field as $key => $value )
  8. echo "<a href=" . $value . " rel=lightbox[".$post->ID."]><img width=100 height=100 src=" . $value . "></a> ";
  9. }
  10.  
  11. ?>


Ok, poradziłem sobie z tym. Teraz mam pytanie jak zrobić zmienna $my_custom_field nie ma zadnej wartości, żeby nie wywalało błędu.

Ten post edytował draqo 17.07.2011, 11:57:56
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
Fifi209
post
Post #2





Grupa: Zarejestrowani
Postów: 4 655
Pomógł: 556
Dołączył: 17.03.2009
Skąd: Katowice

Ostrzeżenie: (0%)
-----


  1. if (is_array($zmienna)) {
  2. // pętla
  3. }
Go to the top of the page
+Quote Post
Rid
post
Post #3





Grupa: Zarejestrowani
Postów: 715
Pomógł: 47
Dołączył: 5.12.2010

Ostrzeżenie: (0%)
-----


  1. $my_custom_field = $custom_fields['zdjecie'];
  2. if (($my_custom_field!=null)||($my_custom_field!="")){
  3. foreach ( $my_custom_field as $key => $value )
  4. echo "<a href=" . $value . " rel=lightbox[".$post->ID."]><img width=100 height=100 src=" . $value . "></a> ";
  5. }
  6. }

Może to pomoże.

Ten post edytował Rid 17.07.2011, 12:42:21
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 10:00