Richard Castera - Explorations in Software Development
Richard Castera - Explorations in Software Development
Browsing Tag
wordpress
Resources Scripts

WordPress – List Scheduled Posts

February 28, 2010 2 Comments

If you ever wanted to show you readers posts that are scheduled to be published, here’s how to do it.

PHP
1
2
3
4
5
6
7
8
<?php
$result = new WP_Query('post_status=future&order=DESC&showposts=5');
if ($result->have_posts()) {
    while ($result->have_posts()) : $result->the_post(); ?>
        <?php the_title(); ?>
    <?php endwhile;
}
?>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

WordPress – Disable Auto Save

February 24, 2010 1 Comment

WordPress’s Auto-Save feature is a really nice but there are some drawbacks… this feature increases your database usage. So for those of you that are on really bad shared hosting accounts or just want to turn it off, here’s a quick way of doing it.

Open and insert the following line in your wp-config.php file.

PHP
1
define('WP_POST_REVISIONS', false);

Another method is to remove all of the entries from the database from time to time. You can do tun this query to do it:

PHP
1
DELETE FROM wp_posts WHERE post_type = "revision";
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Migrate WordPress to a new Server or Directory

May 26, 2009 9 Comments

If you decide to change the URL or link location of your WordPress Blog due to a new domain or moving to a sub-directory, here are some simple steps that should be done to ensure proper migration without breaking links.

To update WordPress options with the new blog location, use the following SQL command:

MySQL
1
2
3
4
5
6
7
8
SET @oldsite='http://www.olddomain.com';
SET @newsite='http://www.newdomain.com';
UPDATE wp_options SET option_value = REPLACE(option_value, @oldsite, @newsite) WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = REPLACE (post_content, @oldsite, @newsite);
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, @oldsite, @newsite);
UPDATE wp_comments SET comment_content = REPLACE (comment_content, @oldsite, @newsite);
UPDATE wp_comments SET comment_author_url = REPLACE (comment_author_url, @oldsite, @newsite);
UPDATE wp_posts SET guid = REPLACE (guid, @oldsite, @newsite) WHERE post_type = 'attachment';
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

WordPress – List your most popular Posts

May 14, 2009 15 Comments

This function below creates a list of links of the top commented posts on your WordPress blog. It builds this list based on the posts that have the most comments. Place it in your footer or sidebar item!

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
function listPopularPosts() {
    global $wpdb;
    $strBuidler = '';
    
    $result = $wpdb->get_results("SELECT comment_count, ID, post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5");
    
    foreach ($result as $post) {
    setup_postdata($post);
    $postId = $post->ID;
    $title = $post->post_title;
    $commentCount = $post->comment_count;
        
    if ($commentCount != 0) {
        $strBuidler .= '<li>';
        $strBuidler .= '<a href="' . get_permalink($postId) . '" title="' . $title . '">' . $title . '</a> ';
        $strBuidler .= '(' . $commentCount . ')';
        $strBuidler .= '</li>';
    }
    }  
    
    return $strBuidler;
}
?>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

WordPress – Embed Adsense in your posts

May 7, 2009 5 Comments

Adding Google Adsense to your blog’s post is easy. No need to download and add another plugin to your WordPress installation. Just follow these easy instructions! First, you have to add the following code to your theme’s functions.php file.

PHP
1
2
3
4
5
6
7
8
9
10
11
12
<?php
function showAds() {
    return '<script type="text/javascript">
    google_ad_client = "pub-2102064382433354";
    google_ad_slot = "5772977330";
    google_ad_width = 468;
    google_ad_height = 60;
   </script>
   <script type="text/javascript" src="https://pagead2.googlesyndication.com/pagead/show_ads.js"></script>';
}
add_shortcode('myadsense', 'showAds');
?>

Saved the functions.php file and upload it. Now you can embed an Adsense unit into your posts easily by pasting the following code in the editor, in html mode:

XHTML
1
[myadsense]
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

WordPress – List the most recent comments

May 3, 2009 5 Comments

Easily list the most recent comments in a sidebar or a tab. The code below will list the 10 most recent comments. You can change the number displayed by changing the value of the variable, $intCommentLimit to list more or less comments

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
function getRecentPosts() {
    global $wpdb;
    $intCommentLimit = 10;
    $strSql = "SELECT DISTINCT ID,
                      post_title,
                      post_password,
                      comment_ID,
                      comment_post_ID,
                      comment_author,
                      comment_date_gmt,
                      comment_approved,
                      comment_type,
                      comment_author_url,
                      SUBSTRING(comment_content, 1, 50) AS com_excerpt
               FROM $wpdb->comments
               LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID)
               WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $intCommentLimit";
    $comments = $wpdb->get_results($strSql);
    $strOutput = "<ul>\n";
    foreach ($comments as $comment) {
        $strOutput .= "<li>" . strip_tags($comment->comment_author)  . " Says, <br>" .
                      "<a href="\""" .="" get_permalink($comment-="">ID) . "#comment-" .
                      $comment->comment_ID . "\" title=\"on " .
                      $comment->post_title . "\">" .
                      strip_tags($comment->com_excerpt) . " ...</a></li>\n";
    }
    $strOutput .= "</ul>\n";
    return $strOutput;
}
echo(getRecentPosts());
?>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera

About me

Hello, my name is Richard Castera. I have more than 12 years of experience architecting, implementing, leading and launching large scale, high performance software products in a fast-paced agile environment.

Popular Posts

Magento – Display new products on the home page

May 20, 2009

How to Fix “Internet Explorer Cannot Open the Internet Site- Operation Aborted” Error

May 9, 2009

PHP – Convert Array to Object with stdClass

July 5, 2009

Categories

  • Home Automation
  • Resources
  • Scripts
  • SEO
  • Thoughts
  • Web Server

Tags

Apache Apple Bash CSS Drupal Free home automation htaccess Java Javascript Magento PHP raspberry pi SEO SQL thoughts Wordpress

© 2019 copyright Richard Castera // All rights reserved