27 mar 2012

Odczyt kategorii posta

$arr_cat=get_the_category($post->ID);

Przykładowe zastosowanie:

if(is_single()):
Kategorie
$cat=''; $arr_cat=get_the_category($post->;ID);
for($i=0,$c=count($arr_cat);$i<$c;$i++) { if($c>1 && $arr_cat[$i]->cat_ID==8) continue; $cat.=','.$arr_cat[$i]->cat_ID;
  };
  $cat=substr($cat, 1);

  $recent = new WP_Query("cat=".$cat."&showposts=10");
  while($recent->have_posts()) : $recent->the_post();
  ...
  endwhile;
  endif;
27 mar 2012

Losowe wybranie postów z wybranych kategorii

Losowe wybranie postów z wybranych kategorii, opcja rand

<?php $recent = new WP_Query("cat=1,2,3&showposts=10&orderby=rand"); while($recent->have_posts()) :
$recent->the_post();?>
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
<?php endwhile; ?>
27 mar 2012

Odczyt wartość pola option na podstawie selectedIndex

Odczyt wartość pola option na podstawie selectedIndex i wstawienie do pola hidden

<select name="stanowisko_sel" onchange="this.form.stanowisko.value = 
this.options[this.selectedIndex].text">
  <option value="1">Kierowca</option>
  <option value="1">Budowlaniec</option>
</select>
<input maxlength="50" name="stanowisko" size="50" type="hidden" />