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/