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; ?>
2 mar 2012

Pobranie informacji o blogu funkcja bloginfo

Pobranie informacji o blogu funkcja bloginfo

echo bloginfo('url');
echo bloginfo('name');
echo '<img decoding="async" src="'.bloginfo('template_url').'"/images/top.gif" alt="Top" />';

Dostępne wartości parametru funkcji:

name
description
admin_email

url
wpurl

stylesheet_directory
stylesheet_url
template_directory
template_url

atom_url
rss2_url
rss_url
pingback_url
rdf_url

comments_atom_url
comments_rss2_url

charset
html_type
language
text_direction
version