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/
kintu, vaia, ekhanae wordpress er login, like, follow feature gula dekhchi na keno? [or am i confusing it with wordpress.com :S]
In this post, i just wanted to show how to fetch blog posts and then show them to a site. . If you are looking for wordpress features, you should google it
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 🙂
Thanks Sakib bhaiya 🙂 I guess, it will help Sadaf..
Thanks Rain Vhai .. Once again a nice share. …
Thanks for this useful information, has saved me a lot of time!
Will be using this on my personal site where I want to start my own blog.
Thanks again!
You welcome Vanhoutte 🙂