WordPress integration to personal site

Well again I came back to my tech world. Last few days I was too busy for my office’s project so that I couldn’t get time to write anything here. Whatever, now wanna share something new that I have learned recently. Actually I was one of my clients’ project where I had to integrate a wordpress blog to a website.

Integrating blog in site is not that much difficult, even I would love to say that it’s pretty much easy. And It just calling some functions of wordpress engine. Let say, you have a site at domain: http://raibd.net and a blog at sub-domain: http://rainbd.net/blog. Now you want to fetch some blog posts and integrate to site.

To get wordpress posts in your site, you will have to add following code at start of the page.

<?php
define('WP_USE_THEMES', false);
require('./blog/wp-blog-header.php');
?>

To fetch your blog posts, please add following line. Here is one catch that you can pass parameters either as array or combining parameters with an ampersand (&) for filtering your blog posts. Suppose you want to fetch 5 posts under category News which cat id is 3.

<? $args  = array(
               'cat'   => 8,
               'showposts' => 5
                );
query_posts($args); ?>
Or
<?php query_posts('cat=3&showposts=5'); ?>

Now if you want print all posts by loop. Type following code

<?php while (have_posts()): the_post(); ?>
<div class="post">
   <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
   <p><?php the_post_thumbnail(); ?>
      <?php the_excerpt(); ?></p>
    <span class="meta"><a href="<?php the_permalink(); ?>">Read more...</a></span>
</div>
<?php endwhile; ?>

Let me explain a bit what I did at above code. I am printing all posts as HTML and each title of posts are hyperlinked with main post. And I used a wordpress function: the_post_thumbnail() for printing the feature picture of posts. And the_permalink() function give the url of main blog post. To set the thumbnail picture’s size, you can add the function set_post_thumbnail_size( $width, $height, $crop).

To know about more functions of wordpress, please go through http://codex.wordpress.org/

 

Eftakhairul Islam

Hi, I'm Eftakhairul Islam, a passionate Software Engineer, Hacker and Open Source Enthusiast. I enjoy writing about technical things, work in a couple of startup as a technical advisor and in my spare time, I contribute a lot of open source projects.

 

7 thoughts on “WordPress integration to personal site

    1. Sadaf, if you do understand the self hosted and wordpress.com hosted difference and on your self hosted domain, if you want wordpress.com all plugins — what you’re looking for, try this plugins http://wordpress.org/extend/plugins/jetpack/. WordPress packed all their official plugins within single bundle to make it convenient for self hosted users. Keep wordpressing 🙂

Leave a Reply to MD. SADAF NOOR Cancel reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Read previous post:
My Talk at phpXperts Seminar 2011

phpXperts community is the largest software developer community in Bangladesh. As part of it, every year we organize phpXperts Seminar....

Close