Skip to content

Instantly share code, notes, and snippets.

@kevinruscoe
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinruscoe/a8926ea126c15e0e0cf5 to your computer and use it in GitHub Desktop.
Save kevinruscoe/a8926ea126c15e0e0cf5 to your computer and use it in GitHub Desktop.
WordPress Cheats

Blog Details

<p>
  <small>Posted by <strong><?php the_author() ?></strong> on <?php the_time('jS F Y') ?>, under <?php the_category(',') ?></small>
</p>

Only show 300 chars of blog

<?php echo substr(strip_tags(get_the_content()), 0, 300); ?>...<a href="<?php the_permalink() ?>">read more &raquo;</a>

Archive titles (using template archive.php)

<h1>
    <?php
        if ( is_day() ) :
            printf( 'Daily Archives: %s', get_the_date() );
        elseif ( is_month() ) :
            printf( 'Monthly Archives: %s', get_the_date('F Y') );
        elseif ( is_year() ) :
            printf( 'Yearly Archives: %s', get_the_date( 'Y' ) );
        else :
            print( 'Archives' );
        endif;
    ?>
</h1>	

Archive titles (using template category.php)

<h1>
    <?php printf('Category Archives: %s', single_cat_title( '', false ) ); ?>
</h1>	

General Sidebar

<div class='widget latest-blogs-widget'>
    <h2>Latest Blogs</h2>
    <ul>
        <?php $the_query = new WP_Query( 'showposts=5' ); ?>
        <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
            <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
        <?php endwhile;?>
    </ul>
</div>
<div class="widget blogs-by-month-widget">
    <h2>Blogs by Month</h2>
    <ul>
        <?php wp_get_archives(array('type' => 'monthly','show_post_count' => true, 'echo' => 1, 'order' => 'DESC')) ?>
    </ul>
</div>
<div class="widget categories-widget">
    <h2>Categories</h2>
    <ul>
        <?php echo wp_list_categories('title_li=') ?>
    </ul>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment