Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Ukrycie pola, jeśli nie wypełnione
Forum PHP.pl > Forum > PHP
senior.pol
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ć?
guilty82
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
senior.pol
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
guilty82
Moze dlatego, ze w printf masz '%1$s' zamiast '%11$s'?
senior.pol
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
guilty82
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>
senior.pol
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
guilty82
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)
senior.pol
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
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.