With Tracy Levesque / @liljimmi
Slides: slides.thetracyl.com/wcnyc2014
functions.php
register_nav_menus( array(
'footer-nav' => 'Footer Menu',
) );
Check out the WordPress Codex register nav menus
<?php wp_nav_menu( array(
'theme_location' => 'footer-nav',
'fallback_cb' => 'false',
) );
?>
Check out the WordPress Codex wp nav menu
functions.php
register_sidebar(array(
'name' => __( 'Header Widget Area' ),
'id' => 'headerwidget',
'description' => __( 'The header widget area.' ),
'before_widget' => '<div id="%1$s" class="headerwidget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="headerwidgettitle">',
'after_title' => '</h4>',
));
Check out the WordPress Codex register sidebar
<?php dynamic_sidebar( 'headerwidget' ); ?>
Check out the WordPress Codex dynamic sidebar
functions.php
add_image_size( 'my-img', 400, 400 ); // soft proportional crop mode
add_image_size( 'other-img', 200, 300, true ); // hard crop mode
add_image_size( 'third-img', 220, 220, array( 'left', 'top' ) ); // hard crop left top
Check out the WordPress Codex add image size
In a single post/page template
<?php the_post_thumbnail('my-img'); ?>
In a loop
<?php echo get_the_post_thumbnail($post->ID, 'my-img'); ?>
Check out the WordPress Codex add image size
<!-- // The Query -->
<?php $myloop = new WP_Query( $args ); ?>
<ul>
<!-- // Loop starts -->
<?php while ($myloop->have_posts()) : $myloop->the_post(); ?>
<li>
<h2><?php the_title(); ?></h2>
<p><?php the_content(); ?></p>
</li>
<!-- // Loop ends -->
<?php endwhile; ?>
</ul>
Check out the WordPress Codex WP_Query
Use wp_reset_postdata();
<!-- // The Query -->
<?php $myloop = new WP_Query( $args ); ?>
<ul>
<!-- // Loop starts -->
<?php while ($myloop->have_posts()) : $myloop->the_post(); ?>
<li>
<h2><?php the_title(); ?></h2>
<p><?php the_content(); ?></p>
</li>
<!-- // Loop ends -->
<?php endwhile; ?>
<?php wp_reset_postdata(); // restores the main loop ?>
</ul>
$args
<!-- // The Query -->
<?php $myloop = new WP_Query( array(
'author_name' => 'tracy',
'cat' => 'cooking',
'tag' => 'chocolate'
'posts_per_page' => '5',
'orderby' => 'date',
'order' => 'DESC'
) ); ?>
<?php
// Check for transient. If none, then execute WP_Query
if ( false === ( $lastpostsloop = get_transient( 'home_lastposts_loop' ) ) ) {
$lastpostsloop = new WP_Query( $args ));
// Put the results in a transient. Expire after 12 hours.
set_transient( 'home_lastposts_loop', $lastpostsloop, 12 * HOUR_IN_SECONDS );
} ?>
<!-- // The Loop -->
<?php while ($lastpostsloop->have_posts()) : $lastpostsloop->the_post(); ?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<!-- // The end of The Loop -->
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
Check out the WordPress Codex Transients API
Check out my blog post Start using Sass
Go to Learn Version Control with Git
A step-by-step course for the complete beginner
Slides: slides.thetracyl.com/wcnyc2014