WordPress Hacks Everyone Knows Except You
From time to time as I browse the web, I find myself reading a fellow (WordPress) blogger’s site and I say to myself, “How did they do that in WordPress?” So I have compiled a list of some of the simple (but cool) WordPress hacks that seem like everyone else knows how to do except for you.
Display Total Blog Posts
This will display the total number of blog posts within your site in plain text.
<?php echo $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'"); ?>
Sort Posts Randomly
Place this before the loop in a page template and it will display the posts in your site randomly.
<?php $limit = get_option('posts_per_page'); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts('orderby=rand&showposts=' . $limit=5 . '&paged=' . $paged); $wp_query->is_archive = true; $wp_query->is_home = false; ?>
Link to Current Month Archive
This displays the path to the Month archive.
<?php echo get_month_link(get_post_time('Y'), get_post_time('m')); ?>
You can also show the current Month by using this…
<?php the_date('F', '', ''); ?>
Link to Current Year Archive
This displays the path to the year archive.
<?php echo get_year_link($arc_year); ?>
You can also show the current year by using this…
<?php the_time('Y') ?>
Force Read More Link on Page
This forces the read more link to work on WordPress pages. Put it in a custom query like so…
<?php if (have_posts()) : ?> <?php $more = 0; // force the read more link ?>?> <?php query_posts("showposts=1"); ?>
Bonus…
Plain Text Rating for Plugin: WP-PostRatings
If you have the WP-PostRatings plugin, this code will give you a plain text output of the average rating using a WorPress custom field.
<?php echo $image = get_post_meta($post->ID, 'ratings_average', $single = true); ?>





1 Comment
pravelno written:)
Post a Comment