35 | Front Page Comments on your WordPress Blog

Posted by alchymyth | Tips & Tricks,Wordpress | Monday 2 August 2010

You want to show the comments to the posts on the front page of your blog?

You want to allow visitors to your blog to leave a comment on the latest post without having to click on the comments link or the post title?

You think this should be straight forward and easy to do?

But far from it…

First step is to locate the template file that shows your front page: in most cases,
this is index.php (but it could also be home.php, or any page template that was set to be shown on the front).

Second step is to add comments_template( ”, true ); within the loop, after the_content(), and maybe after any postmetadata.

However, this is not enough, because the wordpress template tag comments_template() has some check build-in, to make sure that comments are normally only be displayed either on a single article or page.

Find this in /wp-includes/comment-template.php line 858:
if ( !(is_single() || is_page() || $withcomments) || empty($post) )
return;

The code provides the use of a global variable $withcomments that can be set to boolean true (or 1) to allow the display of comments.

Putting it all together, here is what to add into your font page template where you want the comments and comments form to show:
<?php global $withcomments; $withcomments = true;
comments_template( '', true ); ?>

For those, who find the structure of the new wp3 default theme TwentyTen difficult to work with, here a direct pointer:
you will find the code to edit in loop.php after line 135:
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php global $withcomments; $withcomments = true;
comments_template( '', true ); ?>

34 | Image Rotator for the Header of Twentyten

Posted by alchymyth | Tips & Tricks,Wordpress | Saturday 24 July 2010

The wp3 default theme TwentyTen comes with a choice of header images, which can be selected from the dashboard.
To rotate these images to show randomly in the header, we can make use of the global array variable which stores all the default header image information: $_wp_default_headers.
The rest is easy: we build a function, which we later save in functions.php of TwentyTen, to pick a random image out of the available images:
function rotate_default_headers() {
global … » read more »

33 | Automatically Shorten the Manual Excerpt

Posted by alchymyth | Tips & Tricks,Wordpress | Saturday 10 July 2010

When you are building or modifying a wordpress theme, you have the choice of either using ‘the_content()’ to show the full article, or ‘the_excerpt()’ to show a shorter version.
By default, the latter limits the output to the first 55 words of the post, and automatcally strips formatting and images.
To make things more flexible, the editor also allows you to add a manual excerpt that will have preference before the automatically generated one.
There is no default … » read more »

32 | My Favourite Power Tool

Posted by michael | PowerTools | Monday 28 June 2010
my BOSCH CSB 800 2RE power drill

I am talking a lot about power tools in a virtual sense, but actually i just love real power tools.
below is an image of my trusted friend: a BOSCH CSB 800 2RE percussion drill, made in germany, 800 watt power, with three mechanical gears and electronic speed control.
i have this tool for over twenty years now, and it has helped me a lot with my diy and handyman projects – from mixing mortar, fixing plaster … » read more »

31 | Adsense in Content of Posts and Pages for wp3

Posted by alchymyth | Tips & Tricks,Wordpress | Wednesday 23 June 2010

A flexible way to add google adsense into posts and pages in your wordpress blog.
This appraoch uses shortcodes which are an underused technique of increasing the functionality of themes.
Through the formatting options in the shortcode, the text can flow around the adsense blocks similar as it would happen with inserted images.
Options for the alignment are ‘left’, ‘center’, ‘right’ – anything else will be treated as ‘none’.
The code that needs to be added to functions.php of … » read more »

30 | TwentyTen – make header image link to ‘home’

Posted by alchymyth | Wordpress | Sunday 20 June 2010

WordPress3 is out, and with it the new default theme TwentyTen.
Having the whole header image linking to the home page is one of the most common things of a theme, however this is not the standard behaviour of TwentyTen.
It is easy to remedy:
(edits are to be made in header.php of TwentyTen)
<div id="site-description"><?php bloginfo( 'description' ); ?></div>
<a href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
<?php
// Check if this … » read more »

Page 1 of 612345»...Last »