Warning: Creating default object from empty value in /home/expressionz/developer.expressionz.in/blogs/wp-content/plugins/download-monitor/classes/download_taxonomies.class.php on line 156

Warning: Creating default object from empty value in /home/expressionz/developer.expressionz.in/blogs/wp-content/plugins/download-monitor/classes/download_taxonomies.class.php on line 156

Warning: Creating default object from empty value in /home/expressionz/developer.expressionz.in/blogs/wp-content/plugins/download-monitor/classes/download_taxonomies.class.php on line 156
PHP | Expressing IT

Posts Tagged ‘ PHP ’

How to include PHP code inside a Smarty Template

Tuesday, February 24th, 2009 By Nikhil

I thought this one will be a doodle to find in google, as many you us UI and script writers would need to do this on a day to day basis, that is include a bit of peice of PHP code snippet(.php) into a Smarty Template (.tpl).  I realized that easier/popular  your query, even more difficult to find the exact answer…   a million search results but most of them reffered to “file” includes in Smarty … which has the following syntax

    {include file=”include/header.php”}

This actually inlcuded the file fine but as text , What I wanted was the result of  included file .(Note the above is used include template inside a template file). Finally with a bit persiverance …. I stumbled across a slighty modified syntax, which was the answer to my requirement … so here it is… if you havn’t found  one already


{include_php file=”include/header.php” }


get ExpressingIT News by Email Subscribe to ExpressingIT by Email or  Follow Me on Twitter


How to include a WordPress Blog in another site

Monday, February 2nd, 2009 By Nikhil

This question crossed my mind a few times before, when I was working on sites earlier too, which used WordPress to show blogs or new kind of content in some part of the site/portal.Being a novice in PHP and around WordPress, I kept procastinating it, thinking ” this isnt my peice of cake”. Finally! this requirement came upto my nose, when started diggin around a bit for solution.
I was surprised to find that it really was easier than I actually thought it was, to display a list of headlines or the latest post on any other page outside of the WordPress-powered section, just using a little bit of PHP and the WordPress API.

Here is what to do :-
For reasons of explanation, assume that your site is http://www.inchembur.com/ and you have the news section for this site on http://news.inchembur.com/ ( which is running WordPress). Now the requirement is to show the latest post from http://news.inchembur.com/ on the home page of the main site ,i.e. http://www.inchembur.com/index.php

Step1: In your index.php add the following peice of code , Include the WordPress API file. You can add this to the top of the page you want your post to appear on.

<?php
define(‘WP_USE_THEMES’, false); // Disbable use of WordPress Theme
require (‘/var/news.inchembur.com/wp-blog-header.php’); // Include WordPress API
query_posts(‘showposts=1′); // Get Latest Post
?>

In the above peice of include , we are getting only the single most recent post. if you want to try more variations feel free to dig into, query_posts() documentation .

Step 2: Now, In the part of the Index/Home page where you want to show the latest WordPress post from http://news.inchembur.com , use the following code. Needless to say, feel free to ad your styling divisions, spans and classes as per your design needs.

Step3 : There is no Step 3 … Thats it … you are done!


OfCourse, You can try a few variations as per your requirements ( as I mentioned earlier, refer to query_posts() documentation ) . Heres some taster …

How show a specific post/page as opposed to the latest post:-
This can easily achived by altering the arguments to query_posts() to include the page ID or page slug

query_posts(‘page_id=7′);
query_posts(‘pagename=about’);

or You can control the number of posts:
query_posts(showposts=3);


get ExpressingIT News by Email Subscribe to ExpressingIT by Email or  Follow Me on Twitter


 Subscribe to ExpressingIT RSS
get ExpressingIT News by Email Subscribe to ExpressingIT by Email
 Follow Me on Twitter