Posts Tagged Programming

Get Your Post Viral On Twitter

Ok that sounds like every other claim that you have ever read doesn’t it. This simple step will get all your posts reproduced on Twitter. Well of course there are a few steps before any of this will work. Firstly, you actually have to have a Twitter account. Secondly, you need to build a following.

Ok once you have done that, how do you get people to retweet your blog posts? First step to that is, make them interesting, sounds elementary but its true. The second step is to ask people to do so. How can you do that from your blog - easy, use this code snippet in your single.php file - as always, create a backup first before you start playing around with the code.

<?php if (strpos(“twitter.com”,$_SERVER[HTTP_REFERER])==0) {
echo “Thank you for following the link from Twitter! If you enjoy this post, don’t hesitate to retweet!”;
} ?>

This is a great way to make sure your Twitter based reader is acknowledged and that they hopefully will retweet your post. Personalization always helps. Adding a link at the end of your post that allows your readers to repost your blog to Twitter is a great addition as well.

Reblog this post [with Zemanta]

, ,

Separate Your Comments

Giving your readers the opportunity to see comments separate from pingbacks/trackbacks makes your comments section much more readable and more useful for your readers.

The following is a Wordpress coding tip - so before you do this, make sure you back up your comments.php as we will be editing it.

In your comments.php file find the following code:

<?php foreach ($comments as $comment) : ?>

Insert this after it:

<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type == 'comment') { ?>

Then find the following piece of code:

<?php endforeach; /* end for each comment */ ?>

and insert this before it

<?php } else { $trackback = true; } /* End of is_comment statement */ ?>

Finally find this section of code:

<?php else : // this is displayed if there are no comments so far ?>

And insert this before it:

<?php if ($trackback == true) { ?>
  <h3>Trackbacks</h3>
  <ol>
  <?php foreach ($comments as $comment) : ?>
  <?php $comment_type = get_comment_type(); ?>
  <?php if($comment_type != 'comment') { ?>
  <li><?php comment_author_link() ?></li>
  <?php } ?>
  <?php endforeach; ?>
  </ol>
<?php } ?>

That’s it, now your readers can clearly see which are comments and which are pingbacks/trackbacks.

Reblog this post [with Zemanta]

, ,

List Your Upcoming Posts

A sure way to bring readers back to your blog is to tell them what is coming up for release. This is an especially useful feature if you use the post scheduling feature in WordPress. While there are probably plugins that will do this for you, all you actually need is this code snippet. You can just copy and paste it into one of your theme files where you want the list to appear - e.g. the sidebar.

WARNING: Do not do this if you are not comfortable altering the files in your theme. Make sure you make a back up of the file that you are going to change before making the change.

<div id=“crystal_ball”>
<div id=“crystal_ball_header”><p>Future events</p></div>
<?php query_posts(’showposts=10&post_status=future’); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div >
<p class><b><?php the_title(); ?></b><?php edit_post_link(‘e’,‘ (’,‘)’); ?><br />
<span class=“datetime”><?php the_time(‘j. F Y’); ?></span></p>
</div>
<?php endwhile; else: ?><p>No future events scheduled.</p><?php endif; ?>
</div>

This willl produce a list of posts that are marked Future. If you want to show less or more than 10 upcoming posts just change the number in the line “ <?php query_posts(’showposts=10&post_status=future’); ?> ” to the number of posts you want to display.

Its as easy as that.

Reblog this post [with Zemanta]

, ,

WordPress Hack - 404 Page messages

At the beginning of last month I wrote a post about a plugin that would show readers related posts, even if they came to your site via a 404 page not found error. We had some great comments about that, what struck me was that almost everyone thought that the plugin would be really useful, if only they could remember to install it.

So with that in mind I thought I would share with you how to achieve a similar result for your 404 pages without the plugin.  Disclaimer - before doing this, back up your files. Ok, now that you have done that or decided that this is going to be too hard for you, relax, take a breath and realize just how simple this is.

In Wordpress admin, under appearance select editor. This will take you to the editor screen, on the right hand side you should see a list of template files. Find the one called 404 Template and click it.  In the editor you will now see the code that controls the appearance of your 404 error page. The code you are looking for will look something like this:

<div id=”blog_content”>
<h3>Sorry, no posts matched your criteria.</h3>
<p>Please try searching again here…</p>
<div class=”search404 clear”>
<?php include(TEMPLATEPATH.”/searchform.php”);?>
</div>
<p><strong>Or, take a look at Archives and Categories</strong></p>

<div class=”category”>
<h2 class=”error_title”><?php _e(’Category’); ?></h2>
<ul>
<?php wp_list_categories(’orderby=name&title_li’); ?>
</ul>
</div>

<div class=”archives”>
<h2 class=”error_title”>
<?php _e(’Archives’); ?>
</h2>
<ul>
<?php wp_get_archives(’type=monthly’); ?>
</ul>
</div>
</div>

This particular one shows the archive list, however, you can change it to show whatever you want, for example you might want to show your most popular posts. You can do that by just manually linking to them:

<ul>
<li><a href=”#”>post 1</a></li>
<li><a href=”#”>post 2</a></li>
<li><a href=”#”>post 3</a></li>
</ul>

Pretty straightforward really, now plugin. A few minutes of thought and there you have it, a much friendlier error page.

Reblog this post [with Zemanta]

, , ,