How to display latest wordpress blog posts to non-wordpress site?

23 02 2011

You can easily display your latest wordpress blog posts to your non-wordpress site. For this, first you need to add the below line at the top of your php script-

<?php
require(./path/wp-blog-header.php');
?>

When the above line is added to your php script, it will turn your script into wordpress page, which means, you will be able to use any WordPress template tags in your script. Now we will see how can we retrieve few recent posts from our wordpress blog.

$recent_posts = wp_get_recent_posts(5);

wp_get_recent_posts() function will retrieve latest posts from your blog as an array, by default 10 posts are retrieved. To get any other number of posts, just pass the parameter as – wp_get_recent_posts(5) to get latest 5 posts. Now we will loop through the array to get each individual posts with title and url-

foreach($recent_posts as  $post){
    echo '<a href="' . get_permalink($post["ID"]) . '" title="Look '.$post["post_title"].'" >' .   $post["post_title"].'</a>';
}

Thats all you need to do. So here is the full source code-

<?php
require('./path/wp-blog-header.php');
?>
<ul>
  <li>
    <h2>Recent Posts</h2>
    <ul>
    <?php
      $recent_posts = wp_get_recent_posts(5);
      foreach($recent_posts as $post){
        echo '<li><a href="' . get_permalink($post["ID"]) . '" title="Look '.$post["post_title"].'" >' .   $post["post_title"].'</a> </li> ';
      } ?>
    </ul>
  </li>
</ul>
Advertisements




How to install phpMyAdmin on Ubuntu?

22 11 2010

You can install and configure phpMyAdmin easily. Start with the following command to install phpMyAdmin –
sudo apt-get install phpmyadmin

After installation is completed, just open apache2.conf file –
sudo gedit /etc/apache2/apache2.conf

and add the following line to the file –
Include /etc/phpmyadmin/apache.conf

Now save the file and restart apache –
sudo /etc/init.d/apache2 restart

Thats all!





How to start/stop mysql server on Ubuntu?

13 10 2010

Its really simple, just open the terminal and give the command below to start mysql server –
sudo /etc/init.d/mysql start

To restart mysql server, use the command –
sudo /etc/init.d/mysql restart

You can stop mysql server by simply the command –
sudo /etc/init.d/mysql stop

If your mysql server isn’t running and you attempt to connect to the mysql server, you may get a warning like this –

Warning: mysql_connect() [function.mysql-connect]: [2002] No such file or directory (trying to connect via unix:///var/run/mysqld/mysqld.sock) in /home/atik/www/***.php on line ***

In that case, just start the mysql server.