<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Thoughts on Design &#187; Coding</title>
	<atom:link href="http://www.jamischarles.com/blog/tag/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jamischarles.com/blog</link>
	<description>Thoughts on Web Design and Front-end Coding. Served up Monthly by Jamis Charles</description>
	<lastBuildDate>Fri, 03 Jul 2009 00:24:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to getElementsByClassName in JavaScript and manipulating those</title>
		<link>http://www.jamischarles.com/blog/how-to-execute-a-function-in-javascript-without-calling-it/</link>
		<comments>http://www.jamischarles.com/blog/how-to-execute-a-function-in-javascript-without-calling-it/#comments</comments>
		<pubDate>Mon, 26 Nov 2007 13:19:06 +0000</pubDate>
		<dc:creator>jamis</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.bluebreeze.net/blog/?p=24</guid>
		<description><![CDATA[What if you wanted all of your elements on the page that have the same class=&#8221;" to behave the exact same way. Well, with a little JavaScript, this is possible, thanks to Netlobo.com: Note: You must add the following onload event to your body tag: &#60; body onload=&#8221;loadClassNames()&#8221;&#62; &#60;script language="javascript" type="text/javascript"&#62; //function that allows us [...]]]></description>
			<content:encoded><![CDATA[<p>What if you wanted all of your elements on the page that have the same class=&#8221;" to behave the exact same way. Well, with a little JavaScript, this is possible, thanks to <a href="http://www.netlobo.com/javascript_getelementsbyclassname.html">Netlobo.com</a>:</p>
<p>Note: You must add the following onload event to your body tag: &lt; body onload=&#8221;loadClassNames()&#8221;&gt;</p>
<pre class="js">
&lt;script language="javascript" type="text/javascript"&gt;

//function that allows us to get the elements by a class name,

document.getElementsByClassName = function(clsName){

	var retVal = new Array();
	var elements = document.getElementsByTagName("*");

	for(var i = 0;i &lt; elements.length;i++){
		if(elements[i].className.indexOf(" ") &gt;= 0){
			var classes = elements[i].className.split(" ");

			for(var j = 0;j &lt; classes.length;j++){
				if(classes[j] == clsName){
					retVal.push(elements[i]);
				}
			}

		}else if(elements[i].className == clsName){
			retVal.push(elements[i]);
		}
	}
	return retVal;
}

function loadClassNames(){
	//this method only works for event handlers

	var classNames= document.getElementsByClassName('test2');

	for (var i = 0; i &lt; classNames.length; i++){
		classNames[i].onmouseover = function(){
			alert(this.id);
		}

	}
}

&lt;/script&gt;</pre>
<p>The first function simply adds the capability of getting an element by class name, which is not inherently possible with JavaScript. Now, what the 2nd function does, is the following. If you add loadClassNames() as an &#8220;onload&#8221; function to the body tag, when the page loads, the function will get all of the elements with a class name of &#8216;test2&#8242;, and assign a new &#8220;mouseover&#8221; event. In this case, it will create a popup that displays the id of the element.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamischarles.com/blog/how-to-execute-a-function-in-javascript-without-calling-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find x and y position of an element using JavaScript</title>
		<link>http://www.jamischarles.com/blog/find-x-and-y-position-of-an-element-using-javascript/</link>
		<comments>http://www.jamischarles.com/blog/find-x-and-y-position-of-an-element-using-javascript/#comments</comments>
		<pubDate>Thu, 01 Nov 2007 16:50:15 +0000</pubDate>
		<dc:creator>jamis</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.bluebreeze.net/blog/?p=27</guid>
		<description><![CDATA[Ever needed to find the x or y coordinates of an element on a page? Well, thanks to this script from quirksmode it&#8217;s possible.   function findPos(obj) { var curleft = curtop = 0; if (obj.offsetParent) { curleft = obj.offsetLeft curtop = obj.offsetTop while (obj = obj.offsetParent) { curleft += obj.offsetLeft curtop += obj.offsetTop } [...]]]></description>
			<content:encoded><![CDATA[<p>Ever needed to find the x or y coordinates of an element on a page? Well, thanks to this script from <a href="http://www.quirksmode.org/js/findpos.html">quirksmode</a> it&#8217;s possible.</p>
<p> </p>
<pre class="js">function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}</pre>
<pre class="js">var elemToFind = document.getElementById('div1');

var elemCoords = findPos(elemToFind);</pre>
<p>So now, elemCoords holds both the x and the y. Since findPos() returns an array, to access the x or y by itself do the following:</p>
<pre class="js">// elemCoords[0] or elemCoords[1] for the x and y values, respectively
alert(elemCoords[0]);</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.jamischarles.com/blog/find-x-and-y-position-of-an-element-using-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to write a CSS rule that will affect every element:</title>
		<link>http://www.jamischarles.com/blog/how-to-write-a-css-rule-that-will-affect-every-element/</link>
		<comments>http://www.jamischarles.com/blog/how-to-write-a-css-rule-that-will-affect-every-element/#comments</comments>
		<pubDate>Thu, 25 Oct 2007 16:28:52 +0000</pubDate>
		<dc:creator>jamis</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.bluebreeze.net/blog/?p=25</guid>
		<description><![CDATA[Sometimes there&#8217;s a need to reset all of the margins on a page, or you simply want something specifically applied to each element without having to count on inheritances to do the job. The solution: &#8220;*&#8221; or &#8220;universal selector&#8221;. This seems familiar from other languages right? Well, it should be. It simply means &#8220;everything&#8221; in [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes there&#8217;s a need to reset all of the margins on a page, or you simply want something specifically applied to each element without having to count on inheritances to do the job. The solution: &#8220;*&#8221; or &#8220;universal selector&#8221;. This seems familiar from other languages right? Well, it should be. It simply means &#8220;everything&#8221; in a selected area.</p>
<p>The following will apply a gray background to every element on a page.</p>
<pre class="css">* {
    background-color: #eee;
}</pre>
<p>What if you want to get more specific?<br />
With this code, everything within the div with the id=&#8221;wrapper&#8221; will have a gray background.</p>
<pre class="css">div#wrapper * {
    background-color: #eee;
}</pre>
<p>Obviously any properties can be used here. Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamischarles.com/blog/how-to-write-a-css-rule-that-will-affect-every-element/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to add 5 full WordPress posts on an external html page</title>
		<link>http://www.jamischarles.com/blog/how-to-add-5-full-wordpress-posts-on-an-external-html-page/</link>
		<comments>http://www.jamischarles.com/blog/how-to-add-5-full-wordpress-posts-on-an-external-html-page/#comments</comments>
		<pubDate>Sat, 25 Aug 2007 13:26:53 +0000</pubDate>
		<dc:creator>jamis</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.bluebreeze.net/blog/?p=18</guid>
		<description><![CDATA[Upon popular request I&#8217;ve decided to add another tutorial, similar to the previous one, on how to add several full blog posts on an external page. Well, here it is, and I&#8217;ll try to explain everything clearly. Say you have a homepage that is not run by WordPress, and you just have your blog in [...]]]></description>
			<content:encoded><![CDATA[<p>Upon popular request I&#8217;ve decided to add another tutorial, similar to the <a href="http://www.bluebreeze.net/blog/?p=11">previous one</a>, on how to add several full blog posts on an external page.</p>
<p>Well, here it is, and I&#8217;ll try to explain everything clearly.</p>
<p>Say you have a homepage that is not run by WordPress, and you just have your blog in the /blog/ directory or something like that. Yet you STILL want to display <span style="text-decoration: line-through;">an excerpt</span> 5 (or any number) of your most recent full posts from your WordPress blog on your home page.</p>
<p>1) Here&#8217;s the code you will want to write in BEFORE the Doctype (so the very first of your HTML):</p>
<pre class="php">&lt;?php
//db parameters
$db_username = '###';
$db_password = '###';
$db_database = '###';

$blog_url = 'http://www.jamischarles.com/blog/'; //base folder for the blog. Make SURE there is a slash at the end

//connect to the database
mysql_connect(localhost, $db_username, $db_password);
@mysql_select_db($db_database) or die("Unable to select database");

//get data from database -- !IMPORTANT, the "LIMIT 5" means how many posts will appear. Change the 5 to any whole number.
$query = "Select * FROM wp_posts WHERE post_type='post' AND post_status='publish' ORDER BY id DESC LIMIT 5"; 

$query_result = mysql_query($query);
$num_rows = mysql_numrows($query_result);

//close database connection
mysql_close();

// html page starts after ?&gt;
?&gt;
&lt; !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;</pre>
<p>2) Now, the text in the body will be a little bit different. Continuing where we left off&#8230;<br />
Now, the problem here, is that we have dynamically generated content. That means we write a loop that goes through each table row in the database, gets the title, date, and text, then spits out on the html, and goes to the next row of the database and does the same thing again.</p>
<p>So if we use a div with same id, it&#8217;ll show that div up 5 times, each time with a different post. This is not acceptable, because it is not valid code, and could mess up the CSS. So we have to give it a class to be valid, or use tables. For this example we&#8217;ll use divs.</p>
<pre class="php">&lt;body&gt;

&lt;?php

//start a loop that starts $i at 0, and make increase until it's at the number of rows
for($i=0; $i&lt; $num_rows; $i++){ 

//assign data to variables, $i is the row number, which increases with each run of the loop
$blog_date = mysql_result($query_result, $i, "post_date");
$blog_title = mysql_result($query_result, $i, "post_title");
$blog_content = mysql_result($query_result, $i, "post_content");
//$blog_permalink = mysql_result($query_result, $i, "guid"); //use this line for p=11 format.

$blog_permalink = $blog_url . mysql_result($query_result, $i, "post_name"); //combine blog url, with permalink title. Use this for title format

//format date
$blog_date = strtotime($blog_date);
$blog_date = strftime("%b %e", $blog_date);

//the following HTML content will be generated on the page as many times as the loop runs. In this case 5.
?&gt;

&lt;/body&gt;</pre>
<pre class="xhtml">&lt;div class="post"&gt;&lt;/div&gt;

		&lt;span class="date"&gt;  &lt;?php echo $blog_date; ?&gt;:&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;hr /&gt; 

		&lt;a href="http://www.bluebreeze.net/blog"&gt;&lt;?php echo $blog_title; ?&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;

		&lt;?php echo $blog_content; ?&gt; &lt;br /&gt;&lt;br /&gt;

                &lt;a href=”&lt;?php echo $blog_permalink; ?&gt;”&gt;This Article&lt;/a&gt; &lt;br /&gt;
		&lt;a href="http://www.bluebreeze.net/blog"&gt;More Articles &lt;/a&gt;</pre>
<pre class="php">&lt;?php
} //end the for loop
?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.jamischarles.com/blog/how-to-add-5-full-wordpress-posts-on-an-external-html-page/feed/</wfw:commentRss>
		<slash:comments>78</slash:comments>
		</item>
		<item>
		<title>How to add recent WordPress post exceprts on an external html page</title>
		<link>http://www.jamischarles.com/blog/how-to-add-recent-wordpress-posts-on-an-external-html-page/</link>
		<comments>http://www.jamischarles.com/blog/how-to-add-recent-wordpress-posts-on-an-external-html-page/#comments</comments>
		<pubDate>Fri, 25 May 2007 13:42:07 +0000</pubDate>
		<dc:creator>jamis</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.bluebreeze.net/blog/?p=11</guid>
		<description><![CDATA[*** Update (Apr 4 08): I added a line of code that should strip out all HTML tags and formatting. So the resulting excerpt should only be text Related Post: How to display 5 full posts&#8230; Say you have a homepage that is not run by WordPress, and you just have your blog in the [...]]]></description>
			<content:encoded><![CDATA[<p>*** Update (Apr 4 08): I added a line of code that should strip out all HTML tags and formatting. So the resulting excerpt should only be text</p>
<p>Related Post: <a href="http://www.bluebreeze.net/blog/?p=18">How to display 5 full posts&#8230;</a></p>
<p>Say you have a homepage that is not run by WordPress, and you just have your blog in the /blog/ directory or something like that. Yet you STILL want to display an excerpt from your recent post on your home page.</p>
<p>The solution? Use PHP and MYSQL to directly fetch the content from the WordPress database without even using WordPress.</p>
<p>1) Here&#8217;s the code you will want to write in BEFORE the Doctype (so the very first of your HTML):</p>
<pre class="php">&lt;?php
//db parameters
$db_username = '###';
$db_password = '###';
$db_database = '###';

$blog_url = 'http://www.jamischarles.com/blog/'; //base folder for the blog

//connect to the database
mysql_connect(localhost, $db_username, $db_password);
@mysql_select_db($db_database) or die("Unable to select database");

//get data from database
$query = "Select * FROM wp_posts WHERE post_type='post' AND post_status='publish' ORDER BY id DESC LIMIT 1"; 

$query_result = mysql_query($query);
$num = mysql_numrows($query_result);

//close database connection
mysql_close();

//assign data to variables
$blog_date = mysql_result($query_result, 0, "post_date");
$blog_title = mysql_result($query_result, 0, "post_title");
$blog_content = mysql_result($query_result, 0, "post_content");
//$blog_permalink = mysql_result($query_result, 0, "guid"); //use this for 'p=11' format

$blog_permalink = $blog_url . mysql_result($query_result, 0, "post_name"); //combine blog url, with permalink title. Use this for title format

//format date
$blog_date = strtotime($blog_date);
$blog_date = strftime("%b %e", $blog_date);

//how many characters should be shown?
$maxchars = 135;

//strip out the html tags, such as images, etc...
$blog_content = strip_tags($blog_content);

//cut down the size of the post to 135 characters
$blog_content = substr($blog_content, 0, $maxchars);
$blog_content = $blog_content . "...";

// html page starts after ?&gt;
?&gt;
&lt; !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;</pre>
<p>2) Find the &#8220;wp-config.php&#8221; file and the first three lines or so should contain your database name, user name, and password. Enter those in your file where I have ### for the db parameters. Just copy the names as shown in below. Do NOT CHANGE the &#8220;wp-config.php file&#8221;. WordPress will stop working if you do.</p>
<pre class="php">&lt;?php
// ** MySQL settings ** //
define('DB_NAME', 'my_wordpress');    // 'my_wordpress' is the name of the database
define('DB_USER', 'my_user');     // 'my_user' is your MySQL username
define('DB_PASSWORD', 'my_password'); // 'my_password' is the password</pre>
<p>3) Rename the file you are using to .php</p>
<p>4) Find a spot in your html where you want to display your date, title, and post excerpt. For example:</p>
<pre class="xhtml"> 
&lt;div id="myId"&gt;&lt; ?php echo $blog_date; ?&gt;:

&lt; ?php echo $blog_title; ?&gt; 

&lt; ?php echo $blog_content; ?&gt;
 

&lt;a href="&lt;?php echo $blog_permalink; ?&gt;"&gt;More &lt;/a&gt;
&lt;/div&gt;</pre>
<p>The above code will display the following:</p>
<p>May 25:<br />
Show only the titles on the Archive Pages</p>
<p>Thanks to www.spiritfolk.com for this one. 1) Open up /wp-content/themes/default/archive.ph&#8230;</p>
<p>More</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamischarles.com/blog/how-to-add-recent-wordpress-posts-on-an-external-html-page/feed/</wfw:commentRss>
		<slash:comments>84</slash:comments>
		</item>
	</channel>
</rss>
