How to Insert Ads within your Post Content in WordPress
If you have written huge number of posts and want to insert and ad within the post content then its not possible to edit all the posts and put the ad code individually in each post.
If you wan to insert ads within your post content in wordpress then follow the steps below.
Open single.php file located in your theme folder and look for the code that would look something like shown below:
<?php the_content(); ?>
Replace that code with the codes below:
<?php
$paragraphAfter= 1; //display after the first paragraph
$content = apply_filters('the_content', get_the_content());
$content = explode("</p>", $content);
for ($i = 0; $i <count($content); $i ) {
if ($i == $paragraphAfter) { ?>
<div>Your Text / Ads Go Here</div>
<?php }
echo $content[$i] . "</p>";
} ?>
You may change the number of paragraphs by changing $paragraph After line.
How to Create “send this to twitter” Button in WordPress
Twitter is one of the most popular social network basically its a microblogging platform where people love to share the stuff of their interest.If your posts is shared over twitter by some of your readers this may bring some new readers to your blog.
To make it easy to share your posts on twitter just create a button "send this to twitter" in your posts page.Follow the instructions below to create the button.
Simply paste the following code on your single.php file, within the loop:
<a href="http://twitter.com/home?status=Currently reading <?php the_permalink(); ?>" title="Click to send this page to Twitter!" target="_blank">Share on Twitter</a>
Now visitors can share your posts on twitter and this may bring some new readers to your blog.
How to List Scheduled Posts in WordPress
One can schedule posts in wordpress to be published on later dates or after some hours or days it may be anything depending on your need.If you are going for vacation you can schedule posts to be published when you are not available to update your blog.
You can show you visitors the scheduled posts in sidebar to do so just open sidebar.php and paste the following code:
<?php
$my_query = new WP_Query('post_status=future&order=DESC&showposts=5');
if ($my_query->have_posts()) {
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID; ?>
<li><?php the_title(); ?></li>
<?php endwhile;
}
?>
That's all you are done now this will show the scheduled posts in your sidebar.
How to Insert Adsense After First Post in WordPress
Have you ever wondered how to insert adsense after only first post in wordpress if so today we have come up with the solution for same.
Its highly asked question that how to insert adsense after first post in wordpres its very very simple.Just follow the instructions below and you are done.
Simply edit index.php file of your theme and look for the following code:
<?php endwhile; ?>
Immediately before this code, place the following code:
<?php if(!$show_ads){ ?>
Insert Code Here
<?php $show_ads = 1; } ?>
This works fine when its allowed to show only 3 Adsense ads on a page so you can show one after first post, one in sidebar and another one in header.
How to Separate Trackbacks from Comments in WordPress
By default wordpress does not shows trackbacks and comments separately but there is a hack which is used to show comments and trackbacks separately.
Its good to show comments and trackbacks separately as it makes the comments section clean and clutter free.If you want to seperate trackbacks from comments then follow the steps below.
Open and edit the comments.php file of your theme. Find the comment loop:
foreach ($comments as $comment) : ?>
// Comments are displayed here
endforeach;
Replace it with the following:
<ul>
<?php //Displays comments only
foreach ($comments as $comment) : ?>
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type == 'comment') { ?>
<li>//Comment code goes here</li>
<?php }
endforeach;
</ul>
<ul>
<?php //Displays trackbacks only
foreach ($comments as $comment) : ?>
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type != 'comment') { ?>
<li><?php comment_author_link() ?></li>
<?php }
endforeach;
</ul>
And you are done from now on the comments and trackbacks will be displayed separately.
How to Reverse Comments Order in WordPress
By default wordpess shows the comments in order of older first and the newer at last.Many bloggers want to reverse this order to show newer comments first and older comments at last.
If you also want to do the same its so easy just follow the steps below to reverse comments order in wordpress.
Just open the comments.php file located in your theme folder. Find the following line:
<?php foreach ($comments as $comment) : ?>
Now, add this line below:
<?php $comments = array_reverse($comments, true); ?>
The code should look like :
<?php $comments = array_reverse($comments, true); ?> <?php foreach ($comments as $comment) : ?> // comments loop <?php endforeach; ?>
That's all. Comments will now be displayed in reverse order.
How to Allow Contributors to Upload Files in WordPress
If you have a blog where people contribute posts then you may have noticed that contributors can't upload files in wordpress.Its the lack of their rights that wordpress does not allows contributors to upload files.
Its necessary that contributors can upload files so they can put image or video within the post and if you want to allow contributors to upload files in wordpress here is a quick hack.
Just paste the code below in functions.php file of your theme:
if ( current_user_can('contributor') && !current_user_can('upload_files') )
add_action('admin_init', 'allow_contributor_uploads');
function allow_contributor_uploads() {
$contributor = get_role('contributor');
$contributor->add_cap('upload_files');
}
You are done now contributors can upload files in wordpress.
How to Automatically Empty Trash in WordPress
Trash is the new feature in wordperss and it arrived in wordperss 2.9 whenever someone deletes a post, page, comment etc. that doesn't gets deleted permanently that is stored in trash so if the deletion is done by mistake then the deleted item can be restored.
But when you delete lots of items it becomes bulk of unusable data stored in your wordpress database.To get rid of this you can opt to choose empty trash after certain interval of time to.
Here is a small tip to automatically empty trash in wordpress follow the steps below to do the same.
Open wp-config.php file located at the root of your WordPress install and paste the following code:
define('EMPTY_TRASH_DAYS', 10 );
The parameter '10' is when to empty trash, in days, you can change it as per your need.
Facebook is the largest social network with millions of registered users if your content is shared over facebook by many facebook users that will gain good amount of traffic.
How to Display Total Number of Comments in WordPress
To display total number of comments in wordpress you will need a short snippet of PHP code which we are sharing here.
To display total number of comments in wordperss all you will need to do is open your sidebar.php file or any other file where you want to display, and paste the following code:
<?php $commcount = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'"); if (0 < $commcount) $commcount = number_format($commcount); echo "Our users have made ".$commcount." comments, care to join in?"; ?>You can style the code as per your desired need.