WordPress-Snippets

WP_Query

<?php 
$args = array(
    'post_type' => 'post',
    'posts_per_page' => 3
);

$query = new WP_Query( $args );

if ( $query->have_posts() ) :  
    while ( $query->have_posts() ) : $query->the_post(); ?>  
    
        <div class="box">
            <h3><?php the_title(); ?></h3>
        </div>
        
    <?php endwhile; 
    wp_reset_postdata(); 
endif; ?>

Auszug

echo wp_trim_words( get_the_excerpt(), 35, '...' );

Pfad zum Theme

<?php echo get_template_directory_uri(); ?>

Thumbnail mit Timthumb

<img src="<?php echo get_template_directory_uri(); ?>/inc/timthumb.php?src=<?php echo get_the_post_thumbnail_url(); ?>&w=600">

Categoryname im Loop ausgeben

$cats = get_the_category();
$cat_name = $cats[0]->name;