Showing posts with label WordPress. Show all posts
Showing posts with label WordPress. Show all posts

Display Most Recent Tweet in WordPress

Posted by ADMIN On 5:10 AM 0 comments
Twitter is getting very famous among bloggers. Many bloggers are now displaying their most recent tweet on their blog. If you want to display your most recent tweet on your blog simply place this code where you want to display it in your WordPress theme.

    <?php
    $username = "TwitterUsername"; // Your twitter username.
    $prefix = ""; // Prefix – some text you want displayed before your latest tweet.
    $suffix = ""; // Suffix – some text you want display after your latest tweet.
    $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1";

    function parse_feed($feed) {
    $stepOne = explode("<content type=\"html\">", $feed);
    $stepTwo = explode("</content>", $stepOne[1]);
    $tweet = $stepTwo[0];
    $tweet = str_replace("&lt;", "<", $tweet);
    $tweet = str_replace("&gt;", ">", $tweet);
    return $tweet;
    }
Many Blogs are now having guest posts on their site. Some of these guest authors are one-time only authors, so there is no point in creating a separate profile for them just so you can display their name in the post. The smarter way to do this is by using the following code.

Open you single.php, or page.php in your template and add the following code where you display the author name:

    <?php $author = get_post_meta($post->ID, "guest-author", true);
    if ($author != "") {
    echo $author;
    } else {
    the_author();
    } ?>
Have you seen sites that display most recent comments in their sidebar with user gravatars. Well this can be done easily with these codes. Simply paste the following code anywhere you want to display the most recent comments.

    <?php
    $query = "SELECT * from $wpdb->comments WHERE comment_approved= '1'
    ORDER BY comment_date DESC LIMIT 0 ,5";
    $comments = $wpdb->get_results($query);

    if ($comments) {
    echo '<ul>';
    foreach ($comments as $comment) {
    $url = '<a href="'. get_permalink($comment->comment_post_ID).'#comment-'.$comment->comment_ID .'" title="'.$comment->comment_author .' | '.get_the_title($comment->comment_post_ID).'">';
    echo '<li>';
    echo '<div class="img">';
    echo $url;
    echo get_avatar( $comment->comment_author_email, $img_w);
    echo '</a></div>';
WordPress has fields for fields for author contacts, but it has not been updated in ages. So by default you do not have an ability to add author’s twitter or facebook. With this hack you can add this information on their profile page.

First open your functions.php and paste the following code:

    <?php
    function my_new_contactmethods( $contactmethods ) {
    // Add Twitter
    $contactmethods['twitter'] = 'Twitter';
    //add Facebook
    $contactmethods['facebook'] = 'Facebook';

    return $contactmethods;
    }
    add_filter('user_contactmethods','my_new_contactmethods',10,1);
    ?>

Modify Excerpt Length and More Tags

Posted by ADMIN On 4:59 AM 0 comments
WordPress lets you display Excerpts, but up until version 2.9 you could not control the excerpt length. With the following code, you can increase the length from default 55 words to as many words as you like. Open your functions.php file and add the follwowing codes in there:

    // Changing excerpt length
    function new_excerpt_length($length) {
    return 100;
    }
    add_filter('excerpt_length', 'new_excerpt_length');
Did you see sites with a magazine style theme who are displaying posts from a specific category. Sometimes only the most recent post. Well you can do this too easily.

    <?php
    query_posts('showposts=1&cat=3');
    while(have_posts()) : the_post();
    ?>
    <ul>
    <li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>

    <ul><li><?php the_content(); ?></li>
    </ul>
    </li>
    </ul>
    <?php endwhile; ?>
Assuming that you have already created a custom page template and/or already have The Loop ready, paste the following code before the loop.

    <?php
    /* Get all sticky posts */
    $sticky = get_option( 'sticky_posts' );

    /* Sort the stickies with the newest ones at the top */
    rsort( $sticky );

    /* Get the 5 newest stickies (change 5 for a different number) */
    $sticky = array_slice( $sticky, 0, 5 );

    /* Query sticky posts */
    query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );
    ?>

This hack comes becomes very useful when you are running a contest because you might
be posting information such as clues or hints that you don’t want to stay up for ever.
of manually removing the article, you can just make it expire automatically. It also works
if you have a product that you are offering a discount on. You posted it on your blog,
but you don’t want that discount to stay on your blog after its over. So you can remove it
automatically with this code.

All you need to do is replace your WordPress Loop with this code:

<?php
    if (have_posts()) :
    while (have_posts()) : the_post(); ?>
    $expirationtime = get_post_custom_values('expiration');
    if (is_array($expirationtime)) {
    $expirestring = implode($expirationtime);
    }
Most blog designs get boring if they have a huge header picture and it is static.
This is when this tutorial comes in to make your header images dynamic because
it rotates on each visit. You can select as many images as you want to rotate
randomly. It brings life to a blog.

First you need to name your images in this format:

    * headerimage_1.gif
    * headerimage_2.gif
    * headerimage_3.gif

Display Twitter Follower Count as Text

Posted by ADMIN On 4:38 AM 0 comments
There are users who absolutely hate buttons like Feedburner buttons or Twittercounter buttons. Are you one of them? Do you want to display your twitter count as text, so it blends in to your new custom design? Well then this hack is just for you.

First you would need to create a file twitter.php and paste the following code in there:

    <?php
    $tw = get_option("twitterfollowerscount");
    if ($tw['lastcheck'] < ( mktime() – 3600 ) )
    {
    $xml=file_get_contents('http://twitter.com/users/show.xml?screen_name=wpbeginner');
    if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) {
Have you ever been to a site that is not using Feedburner button and is still showing subscriber count?
Well they are probably using the trick we are about to share. Most designers use this trick to have
custom styling and avoid the annoying feedburner button.

Simply copy and paste this code anywhere you like most likely sidebar.php

    <?php
    //get cool feedburner count
    $whaturl="http://api.feedburner.com/awareness/1.0/GetFeedData?uri=your feedburner id";

    //Initialize the Curl session
    $ch = curl_init();

    //Set curl to return the data instead of printing it to the browser.
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    //Set the URL
    curl_setopt($ch, CURLOPT_URL, $whaturl);

    //Execute the fetch
    $data = curl_exec($ch);

    //Close the connection

Display any Number of Posts in a Loop

Posted by ADMIN On 4:32 AM 0 comments
Did you ever want to display a different number of posts on different pages. For example
on your category pages, you want to display 10 posts which you can control from your
Admin panel, but another page you want to show only 5 posts. Well this tutorial is just for you.

Open a Template file where you want to display an x number of recent posts:

    // if everything is in place and ready, let’s start the loop

    // to display ‘n’ number of posts, we need to execute the loop ‘n’ number of times
    // so we define a numerical variable called ‘$count’ and set its value to zero
    // with each iteration of the loop, the value of ‘$count’ will increase by one
    // after the value of ‘$count’ reaches the specified number, the loop will stop
    // *USER: change the ‘n’ to the number of posts that you would like to display
Have you seen other bloggers who display their other blog’s feed on their site.
You want to do it too for extra promotion and traffic. Well here is the tutorial for you.
Simply paste the following code in anywhere in your theme:

    <?php include_once(ABSPATH.WPINC.'/feed.php');
    $rss = fetch_feed('http://feeds.feedburner.com/wpbeginner');
    $maxitems = $rss->get_item_quantity(5);
    $rss_items = $rss->get_items(0, $maxitems);
    ?>
    <ul>
    <?php if ($maxitems == 0) echo '<li>No items.</li>';
    else
    // Loop through each feed item and display each item as a hyperlink.
    foreach ( $rss_items as $item ) : ?>
    <li>
Have you ever been to a site and saw this cool feature? They have a link in their top
navigation to something like Stumbe! or Read Random Articles, or some other creative text.
When you click on that link, it takes you to a page that displays one random page. Each time
you refresh, you are delivered with a new post. Well this trick is just for you then.

You would need to follow the trick #1 in this article to create a custom page template.
And simply paste this code in there....

Google Translator

Search Box

Blog Archive

User Status

Free counters!

About Me

ADMIN
Pakistan
View my complete profile

Recent Posts

Recent Comments