Hey Fellas!
Thanks for popping by …
ExpressingIT has started expressing else where … visit ” developer.expressionz.in“
Hey Fellas!
Thanks for popping by …
ExpressingIT has started expressing else where … visit ” developer.expressionz.in“
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.
<?php while (have_posts()): the_post(); ?>
<div class=”index_item_title”><?php the_title(); ?></div>
<?php the_excerpt(); ?>
<br/><span><a href=”<?php the_permalink(); ?>”>Read more…</a></span>
<?php endwhile; ?>
</div>
Step3 : There is no Step 3 … Thats it … you are done!
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);
Sometimes to keep the pageweight down … we have split our scripts into fragments…These javascript fragments can be loaded as and when required ( on an event or on click of a link or button etc.).
Loading Javascripts dynamically is simple and pretty straight forward as below…
<script type=“text/javascript”>
function loadNewScript(source){
var s = document.createElement(’script’);
s.setAttribute(‘type’,'text/javascript’);
s.setAttribute(’src’, source);
document.body.appendChild(s);
}
</script>and you can have the following call link anywhere in the body , or you can have this script “onLoad” of the document itself…
<a href=“javascript:loadNewScript(‘myDynamicScript.js’);”>Load Dynamic Script</a>
or
<body onload=”loadNewScript(‘myDynamicScript.js’);”>
With a variety of Carousels out there , many for Mootools as well, I still decided to write my own Carousel Class, for some good reasons
1. Wanted a paging feature ( to be able to jump a particular slide/step in the carousel).
2. Wanted freedom with placement of the LEFT and RIGHT buttons/links , where ever I please.
3. More control over the Slide Steps.
I did manage to create a new Carousel , with the above features …as below … Feel free to suggest any modifications you would require!!!
My Example looks like this…[View Demo]

You can easily add the paging to your carousel, simply by setting the paging flag, which is last parater passed while creating the instance of the MooCarousel to true( want paging) or false( donot wanting paging).
var carousel1 = new MooCarousel(‘carousel1_wrapper’,'carousel1_items_container’, ‘carousel1_moveleft’, ‘carousel1_moveright’, c_ns,c_sss, true); //ns= number of slides , sss = slide step size
And ofcourse you can change the look-n-feel of these paging achors as you please by modifying their CSS.
.carousel_paging {text-align:right; margin:5px 10px 0 0;}
.carousel_paging .current, .carousel_paging .page{ outline:none; width:15px; height:15px; line-height:15px; text-align:center; display:block; float:left; background:#D8D8EB; margin:0 1px 0 0; text-decoration:none;}.carousel_paging a:hover, .carousel_paging .current{background:#4D4D9B; color:#ffffff;}
Well! there is a small issue though, The paging anchors if set, then it will get generated always after the Carousel component. I wanted to make it dynamic as well, but then just to keep the Script for blowing out of proportions, I decided to skip it.
But you know a little Javascript , you could easily modify the paging generation code in the MooCarousel class to please your needs.
You can change the PLACEMENT, IMAGES or any displat property of the Left and Right Buttons simply by playing around with the CSS. to be able to change the placements of the Left and Right buttoms was the actual reason for me to right my our Carousel Class.
Since this MooCarousel Class, accepts the id’s of these buttons, you can actually place these buttons anywhere on the page, if you please… it does not have to be in the element hierarchy, as in my example.
var carousel1 = new MooCarousel(‘carousel1_wrapper’, ‘carousel1_items_container’,‘carousel1_moveleft’, ‘carousel1_moveright’,c_ns,c_sss,true);
CSS
.carousel_container_l, .carousel_container_r{margin:50px 0 0 0 ; position: relative;width: 23px;height:20px; float:left; cursor:pointer; }.carousel_container_r{background-position: 0 -38px; }
.carousel_container_l{background-position: 0 -58px; }
WHAT DO I MEAN MY CUSTOMISING SLIDE STEPS?
Most Carousels slide the full with of the visible window. So say you had four items (like in my sample above), it will slide all the four items. With this Carousel Component, You pass the number of slides and the step size of your choice.
var carousel1 = new MooCarousel(‘carousel1_wrapper’, ‘carousel1_items_container’, ‘carousel1_moveleft’, ‘carousel1_moveright’, c_ns,c_sss, true);
c_ns= number of slides , c_sss = slide step size
Also, in my example1 I have calcuted the slide step size, based on logic where , I know number of items , width on each item and the margins that have given after each item in my CSS.
/*For Carousal 1 */
var c1_w = 92; // Carousal Item Width
var c1_n = 10; // Total Number of Comparision Carousal Items
var c1_pp = 4 // Number of Comparision Carousal Items perpage
var c1_marginFactor = 51;
var c1_sss = c1_w * c1_pp ; //sss = slide step size
var c1_ns = parseInt(((c1_w * c1_n)/c1_sss) + .5); //ns= number of slides
c1_sss += c1_marginFactor ; //sss = slide step size , 51 for margins
Requirements: Mootools 1.2
In Firefox… sometimes you might have noticed that the cursor starts blinking on the screen. It might happen when you click on any element on the page , a division or an image etc. This Blinking Cursor in the browser window is actually an ACCESSIBILITY Feature of FireFox called ‘caret browsing’. This features allows/enables users to select text on the page with the keyboard ( Which we normally tend to do with the use of our mouse).
Well! if you donot want this feature … simple press “F7” to toggle it to false and vice-versa ( if you want it ON). You could also type “about:config” in the address bar (type in “caret” in the filter box) and simply double click to change the option “accessibility.browsewithcaret” from “true” (turn caret browsing ON) to “false” ( turn caret browsing OFF)
Before we had to deal with CSS to create our page layouts, aligning some content inside a table cell seemed just child’s play. Simply set the “align” or “valign” property of the table to have the alignment of your choice, piece of cake!
With CSS layouts, though we have “vertical-align” property for the elements, it doesn’t seem to be as simple as the “align” or “valign” properties. To be more specifiic the “vertical-align” never seems to solve any of your problems, especially if are write a piece of cross-browser CSS.
Without the use of HTML Tables, THE PROBLEM of centering on object, be it an image or some text within a containing division, has probably been every UI/CSS developers nightmare at some point. This problem further extrapolates your worries of aligning, if the object to be centered is dynamic in nature, i.e. when its height is variable(unknown height).
Though there is no known straight forward solution that would work across the range of browsers we have to deal with, the solution that I have tried to arrive at does seem to work in the few browsers that I have tried it in ( IE6, IE 7, FF).
SOLUTION:
In browsers like Mozilla, Opera and Safari, The strange behaving “vertical-align” property can be brought to its senses, simply by setting the “display” property of the containing division to “table-cell” (display: table-cell).
The problem still remains with IE family of browsers, who, yet do not seem to understand what to with the “table-cell” property and ignorant as they are, they just ignore it. The solution given below, though simple, ads a few more DOM elements to your HTML to make things happen.
The CSS and HTML looks like this
.outer_container {
display: table;
text-align:center;
height: 140px;
width:140px;
position: relative;
overflow: hidden;
float:left;
margin:0px 10px 0px 0px;
}
.obj_container {
display: table-cell;
vertical-align: middle;
#position: absolute;
#top: 50%;
#left:50%;
}
.obj{
#position: relative;
#top: -50%;
#left:-50%;
margin:0px auto 0px auto;
}HTML: -
<div class=”outer_container” >
<div class=”obj_container” >
<div class=”obj”> <img src=”image1.jpg”/><br/> views :3456 </div>
</div>
</div>
The result looks like this:-

view the demo here | Download here
TOP Align CSS
.obj_container_top {
display: table-cell;
vertical-align: top;
#position: absolute;
#top: 0%;
#left:50%;
}
.obj_top{
#position: relative;
#top: 0%;
#left:-50%;
margin:5px auto 0px auto;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:10px;
color:#cccccc;
}HTML: -
<div class=”outer_container” >
<div class=”obj_container_top” >
<div class=”obj_top” > <img src=”image1.jpg”/><br/> views :1234 </div>
</div>
</div>
The result looks like this:-

BOTTOM Align CSS
.obj_container_bottom {
display: table-cell;
vertical-align: bottom;
#position: absolute;
#bottom: 0%;
#left:50%;
}
.obj_bottom {
#position: relative;
#bottom: 0%;
#left:-50%;
margin:5px auto 0px auto;
}
HTML: -
<div class=”outer_container” >
<div class=”obj_container_bottom” >
<div class=”obj_bottom” > <img src=”image1.jpg”/><br/>views :1234 </div>
</div>
</div>
The result looks like this:-

view the demo here | Download here
Seems like ages, since I was trying to find a reasonable solution to this alignment problem. But now with this solution, I feel at little peace.
With a hope that someday
Download the CSS and HTML of the above solution here (for understandability, the CSS is not been optimized)
PS: And by the way, those are thumbnails of some pictures I have clicked…
CSS for Non-IE Browsers : Its no news to CSS developers that , CSS Child Selectors like the example below, doesnt seem to work in IE.
e.g. div > span { some css } , that means “when a span element is a child ( and NOT a grandchild or great grand child etc.) of a division element” .
But we used this CON to our advantage. Historically, the child selector has been used to hide CSS commands from IE. Simply by placing html>body in front of any CSS command IE will ignore it:
html>body .foo {CSS commands go here;}
This works because <body> is always a child of <html> – it can of course never be a grandchild or great-grandchild of <html>.
Now that IE7 understands the child selector, you have to insert an empty comment tag in directly after the greater than sign. IE7 will then not understand this selector (who knows why!?) and will therefore totally ignore this CSS command:
html>/**/body .foo {CSS commands go here;}
If haven’t already seen these before, have a read through the following as well