Posty publikované mezi daty
Chcete-li zobrazit posty vytvořené v určitém časové rozmezí, použijte následující smyčku:
<!--?php function filter_where($where = '') { $where .= " AND post_date -->= '2012-04-18' AND post_date <= '2012-05-01'"; return $where; } add_filter('posts_where', 'filter_where'); query_posts($query_string); while (have_posts()) : the_post(); the_content(); endwhile; ?> |
Posty s náhledem prvního obrázku v článku
Nejdříve si do souboru function.php vložíme funkci, která nám vrátí link na první obrázek v článku:
function catch_that_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('//i', $post->post_content, $matches); $first_img = $matches [1] [0]; if(empty($first_img)){ //Defines a default image $first_img = "/images/default.jpg"; } return $first_img; } |
Následně můžeme naší fci volat ve smyčce:
<!--?php if (have_posts()) : while (have_posts()) : the_post(); ?--> <a class="img-loop" title="<?php the_title(); ?>" href="<?php the_permalink();?>"> <img src="http://www.remake.cz/blog/wp-content/uploads/images/<?php echo catch_that_image() ?>" alt="<?php the_title(); ?>" /> </a> endwhile; endif; ?> |