Hacks and Hints TechieVarta

Icon

Another Techie Varta

Archive for the ‘WordPress’ Category


Backing up Wordpress MU Site

Monday, February 9th, 2009

Several of us don’t have need for and enthu for an elaborated backup system. Here is a small script that will backups the WPMU site including database and the file system and e-mails it to provided e-mail address. For small site this works perfectly. You can also use it to e-mail the backups to Gmail or msn mail. For automatic backup you can add this script to crontable of your host.

#!/bin/bash
DB=mu
WPMU_ROOT=/srv/www/mu-blogs

dirname=mu-backup-`date +”%m-%d-%y”`
cd /tmp
tmpdir=${dirname}

email=foo at bar . com

/bin/cp -R $WPMU_ROOT $tmpdir
/usr/bin/mysqldump mu > $tmpdir/db_backup.sql

/usr/bin/tar cfz $tmpdir.tgz $tmpdir

echo “Backup of WPMU $dirname” | /usr/bin/mail $email -s “WPMU Backup $dirname” -a $tmpdir.tgz
rm -rf $tmpdir*

Wordpress MU: Latest Posts on a single Page

Sunday, February 1st, 2009

One of the thing I had to decide is the main blog page on my new WordPress Mu site. I decided that I wanted this page to show off latest posts from all the blogs.Using Sitewide Tags was not an option since that does not have a way to import existing posts. I eventually decided to hack my own solution.

Doing this involved some PHP hacking, googling and WPMU Feed plugin. The overall design of the page now uses WPMU Feed to send site-wide post feed. This main page just uses this feed to display posts First download the WPMU Feed plugin and install it. I host feed plugin to http://techievarta.com/feed/.

I cloned my theme to create another copy used by the main site. Than I changed index.php to use the feed. A typical index.php looks like the following:


if there are posts

      show posts;

else

    show error;

endif

The changes required removing else part. So the new index.php looks like”:


if there are posts

     show posts;

endif

<-- Catch the feed and display --->

To catch the feed and display, the code (which is based of feed.php of wordpress installation) looks like the following:


 if ( $rss = fetch_rss( 'http://<site>/feed/',20 ) ) {
       echo '<ul>';
       if ( $num_items !== -1 ) {
          $rss->items = array_slice( $rss->items, 0, $num_items );
       }

       foreach ( (array) $rss->items as $item ) {
          printf('<a href="%1$s" ><h4>%2$s</h4></a><p/>',
             clean_url( $item['link'] ),
             htmlentities( $item['title'] )
             clean_url( $item['link'] ),
             htmlentities( $item['title'] )
          );
         echo "Published ";
         echo $item['pubdate'];
         $dc = $item['dc'];
         if( !empty($dc)){
           echo ' by ';
           echo attribute_escape(  $dc['creator']  );
         }
         echo '<p/>';
         echo attribute_escape(  $item['description']  );
         echo '<p/><br/>';
     }
     echo '</ul>';
 }

Replace <site> with your site’s URL and 20 with number of the contents you want.

Happy Blogging!

Installing Wordpress Mu

Sunday, February 1st, 2009

I recently consolidated several of my blogs to a single WordPress Mu blog site. This allowed me to have a streamlined single user and site administration across all my blogs. Wordpress Mu which stands for WordPress Multi User, is implemented as an extension to our beloved WordPress suite and can run most of the WordPress plugins and themes although there are differences.

Installation

  1. Download latest WordPress Mu from the dowload site.
  2. Unzip WordPress Mu to a place where your web server can find it.
  3. Configure the web server and point it to the Mu site. For Apache the configuration looks like:
  4. 
    <VirtualHost>
     DocumentRoot /srv/www/mu-blogs
     ServerName example.com
     ServerAlias *.example.com
     ServerAdmin root@localhost
      AllowOverride FileInfo Options
     # AllowOverride All
      Order allow,deny
      Allow from all
     CustomLog /var/log/apache2/mublogs-access_log combined
    </VirtualHost>
    

    Look at ServerAlias directive. This allows blogs to have addresses of the form <blogname>.example.com.
    If you would rather use the blog names of the form:
    example.com/<blogname>, you don’t’ need to add the server alias directive.

  5. Now make sure DNS for *.example.com correctly points to your site.
  6. Point the browser to your newly created site, answer simple question and let WordPress Mu install the site and the site is up and running.

Themes

Most of the WordPress themes should work with WordPress Mu theme. For themes to be available for individual blogs, they must be enabled in the admin menu. I wanted all my blogs to use the same theme and did not want to manually edit theme setting in every blog. To achieve this, I replaced the default theme with the theme of my choice. Any future created WordPress blog will automatically inherit the default theme.

Plugins

One thing you noticed when installing plugins is that MU has two plugin directories: <wordpressroot>/wp-content/plugin and <wordpressroot>/wp/content/mu-plugin. Any plugin placed in the <wordpressroot>/wp-content/plugin are available to every blog but still must be activated just like any normal wordpress plugins. The mu-plugin directory is special. Any plugin placed in this directory is automatically activated and all the blogs automatically get it. In addition WordPress Mu does not scan subdirectories under mu-plugin directory. The plugin’s php must be directly placed in the mu-plugin directory.

Happy Blogging!

Drupal: Impressions and Plugins

Saturday, November 3rd, 2007

Readers of this site know that this site runs WordPress for theblogs. Today I want to talk about what I run for my web site. I use great Web Site management software called Drupal. Both WordPress and Drupal are similar in several aspects. Like WordPress, this software is written in PHP and can use MySql as the backend. Both the software are extensible using modules and have a wide variety of modules providing various extensions. Both software allow themes and have a wide variety of themes available.

However, there are several key differences. Drupal is full WebSite management software which also has a blog management feature. WordPress on the other hand is a blog only software and does a great job at it. I could have used Drupal for blog however, I found WordPress before I found Drupal and I was already running WordPress before I built my main site. I am extremely happy with WordPress and do not see a reason for change. I have not experimented with Drupal’s blog feature to know more.

To use Drupal, you should install several plugins.

Essential Drupal Plugins

Site Management Related Modules

  • Category: This software allows you to hierarchically structure your site in tree-like structure. It automatically builds menu as needed.
  • Path Auto: This module automatically creates your URL alias based on page titles and various rules. this can significantly increase search engine ranking.
  • Global Redirect: If path aliases are enabled, the pages on your site are generally accessible using two different paths: default Drupal path and alaised path. This module changes that such that the default Drupal URL results in sending a redirect to the aliased page rather then serving the page. This makes sure that your site is not unnecessarily put in sandbox by Google.

Search Engines Related Plugins

  • Google Analytic: This module provides support for Google Analytics
  • GSiteMap: This module provides on demand Google sitemap generation.

Content Creation Related Plugins

  • TinyMCE: This plugin brings in rich WYSIWYG editor inside Drupal for content creation.
  • Image: : This module allows users to manage Images inside Drupal.
  • Upload Image: This module allows users to upload images on the Drupal website.
  • Weather: I wanted to display weather on my Drupal site. I tried this module and found it to be not very useful. I eventually ended up creating a custom modules. After trying HTML code from Weather.Com and AccuWeather.com, I ended up using AccuWeather.com’s weather related HTML in my custom module.

What I did not like about Drupal?

The Drupal software menu system is non-intuitive. “Site-Building” what does that mean? Modules are enabled in “Site Building” and configured in “Site Configuration”. I wished there was a way to configure the modules as a button as soon as they were enabled. With software like Drupal, you land up with 10s of module. I wish there was a way to organize modules in categories.

The way user authorization is separated from actual module configuration is another thing I don’t like. It is nice that you can see authorization level at a single place, but equally nice will be a way to configure authorization level whenever a module is configured. I suggest that we provide a method to configure authorization both in module level and in user management section.

Drupal and WordPress on the same Site

The great advantage of Open Source Software is that the users have choice. I can run software from different sources and use their strongest parts to come up with a very useful end result. I and based on my reading from the web many others, believe that Drupal is great site management tool and WordPress blogging infrastructure is superior to that of Drupal’s . It is rather easy to run Drupal and WordPress on the same server however it is very difficult to run them in integrated fashion. It will be wonderful to develop a WordPress Module for Drupal and have WordPress site inherit Drupal’s theme or even have its own theme. But, that way they can share the same users.

Another area where the integration will be useful is in sitemap generation. It will be good if there was a way to have Drupal’s sitmap include WordPress sitemap. I had to do some php hacking to get that working.

Wordpress essential plugins

Wednesday, October 31st, 2007

As the readers of this site know, I use WordPress as the blog management software. One of the great things about WordPress is its capability to use plugins. The WordPress websites includes 100s of plugins. This is the great thing about the open source software. It gives you choice. You editor tested several different plugins before came up to the list of plugins for this site and will like to share it with you. Here is the list:

  • Next Gen Gallery: If you are going to host several pics on your site, you need this plugin. It allows easy organization of your album and allows you to select one of the several effects for your pics.
  • WordPress Video Plugin: If you like including YouTube, Google video, etc. on your sites, you want this plugin, unless of course you want to start coding in HTML which I don’t necessarily enjoy.
  • Enhanced Links: The default presentation of links in WordPress is pathetic specially if you want any significant number of links on your site. This plugin makes job of managing links significant easier.
  • TinyMce Advanced: The visual editor for WordPress is called TinyMCE. This plugin enables several new toolbar buttons for your site.
  • WP Cache: As the name suggests, this plugin significantly improves performance of your WP site.
  • Google Sitemap Generator: This plugin generate sitemap.xml for your site and informs all major search engines about it.
  • All in one SEO Pack: This pack tries to optimize your site for major search engines.
  • Ultimate Google Analytics: This provides an easy way to use Google Analytics with WordPress sites.
  • WordPress.com Stats: This plugin provides another useful way to mine users of your site.

Wishlist

I wish there was a plugin which rewrote the URL to something clearer.  Something like clear url for Drupal.