Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Ukrycie pola, jeśli nie wypełnione
senior.pol
post
Post #1





Grupa: Zarejestrowani
Postów: 158
Pomógł: 0
Dołączył: 10.08.2011

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


Witam,
Używam wordpressa z wtyczką Advance Custom Fields i chcę dodać jedną regułę - ukrywać pole "rabat" - 11$s, jeśli nie zostało wypełnione.
  1. <div <?php post_class("loop ".$item_style." ".$color_set." ". $portfolio_format)?> id="portfolio-<?php the_ID(); ?>">
  2. <?php
  3.  
  4. ....
  5.  
  6. //output
  7. if( $item_style == "style-1" ){
  8.  
  9. printf('
  10. <figure class="image-thumbnail">
  11. <a href="%2$s" target="%3$s" title="%4$s">%1$s</a>
  12. </figure>
  13.  
  14. <section class="text">
  15. %5$s
  16. %6$s
  17. %7$s
  18. %8$s
  19. </section>
  20. ', $thumbnail_image_output, $permalink, $target, $title, $title_output, $term_list, $desc_output, $read_more );
  21.  
  22. }else{
  23.  
  24. printf('
  25.  
  26. <figure class="image-thumbnail">
  27. %1$s
  28. <div class="rabat">
  29. &minus;%11$s&#x25;
  30. </div>
  31. <div class="description">
  32. <table cellspacing="0" style="border-collapse: collapse; border: none;">
  33. <tr>
  34. <td><span class="icon-line-anchor icon"> %8$s</span></td>
  35. <td><span class="icon-new-user-1 icon"> max %9$s</span></td>
  36. <td><span class="icon-line-cart icon"> od %10$s PLN</span></td>
  37. </tr>
  38. </table>
  39. </div>
  40. </figure>
  41. <div class="overlay">
  42. <a href="%2$s" target="%3$s" title="%4$s"></a>
  43.  
  44. <section class="text">
  45. %5$s
  46. %6$s
  47. %7$s
  48. </section>
  49.  
  50. </div>
  51.  
  52. ', $thumbnail_image_output, $permalink, $target, $title, $title_output, $term_list, $desc_output, get_field('port'), get_field('zaloga'), get_field('cena'), get_field('rabat'));
  53. }
  54.  
  55. ?>
  56.  
  57. </div>


Z PHP jestem noga sadsmiley02.gif

Ktoś może mi pomóc?

Da radę coś z tym zrobić?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 8)
guilty82
post
Post #2





Grupa: Zarejestrowani
Postów: 176
Pomógł: 31
Dołączył: 26.03.2007

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


Nie uzywam printf i nie wiem czy jest jakies eleganckie rozwiazanie, ale sadze ze to powinno dzialac.
  1. //...
  2. }else{
  3.  
  4. $rabat = get_field('rabat') ? '<div class="rabat">&minus;%11$s&#x25;</div>' : null;
  5.  
  6. //w prinf() ostatni argument zmien get_field('rabat') na $rabat
Go to the top of the page
+Quote Post
senior.pol
post
Post #3





Grupa: Zarejestrowani
Postów: 158
Pomógł: 0
Dołączył: 10.08.2011

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


Cytat(guilty82 @ 5.03.2017, 19:33:14 ) *
Nie uzywam printf i nie wiem czy jest jakies eleganckie rozwiazanie, ale sadze ze to powinno dzialac.
  1. //...
  2. }else{
  3.  
  4. $rabat = get_field('rabat') ? '<div class="rabat">&minus;%11$s&#x25;</div>' : null;
  5.  
  6. //w prinf() ostatni argument zmien get_field('rabat') na $rabat

  1. }else{
  2.  
  3. $rabat = get_field('rabat') ? '<div class="rabat">&minus;%11$s&#x25;</div>' : null;
  4.  
  5.  
  6. <figure class="image-thumbnail">
  7. %1$s
  8. <div class="description">
  9. <table cellspacing="0" style="border-collapse: collapse; border: none;">
  10. <tr>
  11. <td><span class="icon-line-anchor icon"> %8$s</span></td>
  12. <td><span class="icon-new-user-1 icon"> max %9$s</span></td>
  13. <td><span class="icon-line-cart icon"> od %10$s PLN</span></td>
  14. </tr>
  15. </table>
  16. </div>
  17. </figure>
  18. <div class="overlay">
  19. <a href="%2$s" target="%3$s" title="%4$s"></a>
  20.  
  21. <section class="text">
  22. %5$s
  23. %6$s
  24. %7$s
  25. </section>
  26.  
  27. </div>
  28.  
  29. ', $thumbnail_image_output, $permalink, $target, $title, $title_output, $term_list, $desc_output, get_field('port'), get_field('zaloga'), get_field('cena'), $rabat);
  30. }

Niestety nie działa sad.gif
Go to the top of the page
+Quote Post
guilty82
post
Post #4





Grupa: Zarejestrowani
Postów: 176
Pomógł: 31
Dołączył: 26.03.2007

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


Moze dlatego, ze w printf masz '%1$s' zamiast '%11$s'?
Go to the top of the page
+Quote Post
senior.pol
post
Post #5





Grupa: Zarejestrowani
Postów: 158
Pomógł: 0
Dołączył: 10.08.2011

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


Cytat(guilty82 @ 6.03.2017, 12:14:39 ) *
Moze dlatego, ze w printf masz '%1$s' zamiast '%11$s'?

'%1$s' to zdjęcie,
a gdy dodam do printf '%11$s' to nie pobiera wartości pola
Go to the top of the page
+Quote Post
guilty82
post
Post #6





Grupa: Zarejestrowani
Postów: 176
Pomógł: 31
Dołączył: 26.03.2007

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


Moj blad. Zamiast
  1. $rabat = get_field('rabat') ? '<div class="rabat">&minus;%11$s&#x25;</div>' : null;

Moze byc raczej cos takiego.
  1. $rabat = get_field('rabat') ? '&minus;' . get_field('rabat') . '&#x25;' : null;

A w prinf:
  1. <div class="rabat">%11$s</div>
Go to the top of the page
+Quote Post
senior.pol
post
Post #7





Grupa: Zarejestrowani
Postów: 158
Pomógł: 0
Dołączył: 10.08.2011

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


Cytat(guilty82 @ 6.03.2017, 13:50:54 ) *
Moj blad. Zamiast
  1. $rabat = get_field('rabat') ? '<div class="rabat">&minus;%11$s&#x25;</div>' : null;

Moze byc raczej cos takiego.
  1. $rabat = get_field('rabat') ? '&minus;' . get_field('rabat') . '&#x25;' : null;

A w prinf:
  1. <div class="rabat">%11$s</div>

Dzięki specool.gif

Ten post edytował senior.pol 6.03.2017, 15:17:12
Go to the top of the page
+Quote Post
guilty82
post
Post #8





Grupa: Zarejestrowani
Postów: 176
Pomógł: 31
Dołączył: 26.03.2007

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


W takim razie musimy, poniekad wrocic do pierwotnej wersji.

  1. $rabat = get_field('rabat') ? '<div class="rabat">&minus;' . get_field('rabat') . '&#x25;</div>' : null;


a z printf zostaje tylko '%11$s' (bez diva)
Go to the top of the page
+Quote Post
senior.pol
post
Post #9





Grupa: Zarejestrowani
Postów: 158
Pomógł: 0
Dołączył: 10.08.2011

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


Cytat(guilty82 @ 6.03.2017, 15:16:56 ) *
W takim razie musimy, poniekad wrocic do pierwotnej wersji.

  1. $rabat = get_field('rabat') ? '<div class="rabat">&minus;' . get_field('rabat') . '&#x25;</div>' : null;


a z printf zostaje tylko '%11$s' (bez diva)

Skorzystałem z funkcji css empty i wszystko fajnie śmiga, dzięki thumbsupsmileyanim.gif
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 19.08.2025 - 10:44