<?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>Funroe &#187; PHP</title>
	<atom:link href="http://funroe.net/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://funroe.net</link>
	<description>Jess Planck, Creating Stuff</description>
	<lastBuildDate>Sun, 25 Jul 2010 22:50:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0-RC2-15182</generator>
		<item>
		<title>Revisiting My Really boring HTML &amp; XML tag function for PHP</title>
		<link>http://funroe.net/2009/04/28/revisiting-my-really-boring-html-xml-tag-function-for-php/</link>
		<comments>http://funroe.net/2009/04/28/revisiting-my-really-boring-html-xml-tag-function-for-php/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 20:22:58 +0000</pubDate>
		<dc:creator>jess</dc:creator>
				<category><![CDATA[Funroe]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Stuff that should not be here]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://funroe.net/?p=493</guid>
		<description><![CDATA[I&#8217;ve made some changes to the utility function I use for HTML and XML tag output. PHP is already a useful template language, but sometimes I run into places where I need to manipulate tags or output large amounts of HTML or XML tagged information. I looked everywhere for a simple function and ended up [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve made some changes to the utility function I use for HTML and XML tag output. PHP is already a useful template language, but sometimes I run into places where I need to manipulate tags or output large amounts of HTML or XML tagged information. I looked everywhere for a simple function and ended up writing this boring function myself.<span id="more-493"></span></p>
<p>This version uses this technique exclusively as a function. If you want to see the earlier similar function used in a PHP class see <a href="http://funroe.net/2008/11/03/really-boring-html-xml-tag-class-function-for-php/trackback">Really boring HTML &amp; XML tag class function for PHP</a>. <strong>You would have to edit the original example to match these changes, but if you want to use a PHP class then I suspect you know what you are doing.</strong></p>
<p>The major change is moving from <strong>sprintf</strong> to concatenated strings. I also had to change the <strong>content</strong> array key to <strong>tag_content </strong>because content is an HTML attribute (doh!). With that change I added array keys tag_content_before and tag_content_after so you can add more stuff. So picky folks can \n\n\t\t\t\t their i-want-pretty-source-code-hearts out or add comments and other junk. I also simplified the reserved array key names checks.</p>
<p>Remember I don&#8217;t consider myself a programming god, just an artist that writes code. I know there are plenty of great HTML PHP libraries and other coding toys, but this just a simply coded function to met my needs.</p>
<pre class="brush: php;">&amp;lt;?php
// Boring general purpose html and xml tag generation function
function the_html_tag( $html = array() ) {

    $attributes = '';
    $composite = '';
    $spacer = '';
    $reserved = array(
        'tag', 'tag_type', 'attributes', 'tag_content', 'tag_content_before', 'tag_content_after', 'return'
    );

    foreach ( $html as $name =&amp;gt; $option ) {
        if ( in_array( $name, $reserved ) ) continue;
        $attributes .= $name . '=&amp;quot;' . $option . '&amp;quot; ';
    }

    if ( $html['attributes'] != '' ) $attributes = $html['attributes'] . ' ' . $attributes;

    if ( $attributes != '' ) {
        $attributes = rtrim( $attributes );
        $spacer = ' ';
    }

    switch ( $html['tag_type'] ) {
        case 'single':
            $composite = $html['tag_content_before'] . $html['tag_content'] . '&amp;lt;' . $html['tag'] . $spacer . $attributes . '/&amp;gt;' . $html['tag_content_after'];
            break;
        case 'open':
            $composite = $html['tag_content_before'] . '&amp;lt;' . $html['tag'] . $spacer . $attributes . '&amp;gt;' . $html['tag_content'] . $html['tag_content_after'];
            break;
        case 'close':
            $composite = $html['tag_content_before'] . $html['tag_content'] . '&amp;lt;/' . $html['tag'] . '&amp;gt;' . $html['tag_content_after'];
            break;
        case 'attributes':
            $composite = $attributes;
            break;
        default:
            $composite = $html['tag_content_before'] . '&amp;lt;' . $html['tag'] . $spacer . $attributes . '&amp;gt;' . $html['tag_content'] . '&amp;lt;/' . $html['tag'] . '&amp;gt;' . $html['tag_content_after'];
            break;
    }

    if ( $html['return'] == true ) return $composite ;

    echo $composite;
}
?&amp;gt;</pre>
<p>Basically you call <strong>the_html_tag( $array_here )</strong> function with an array. The array has a few special keys used to control the function output:</p>
<ul>
<li><strong>$array['tag']</strong> &#8211; is the HTML or XML tag you want to create.</li>
<li><strong>$array['tag_type']</strong> &#8211; is how the tag will be composed. You can set it to one of these predefined options:
<ul>
<li><strong>single</strong> &#8211; composes the tag_content_before then the tag_content and a self-closing tag  (like IMG) with the attributes followed by the tag_content_after.</li>
<li><strong>open</strong> &#8211; will compose the tag_content_before then an opening tag with attributes followed by tag_content and finally tag_content_after.</li>
<li><strong>close</strong> &#8211; will output tag_content_before then the tag_content with a closing tag (no attributes) and followed by tag_content_after</li>
<li><strong>attributes</strong> &#8211; will output just the attributes with no tag or tag_content key values&#8230; yum!</li>
<li><strong>With no tag_type </strong>the default behavior  composes the tag_content_before then the tag with the attributes wrapped around tag_content with a closing tag followed by the tag_content_after.</li>
</ul>
</li>
<li><strong>$array['tag_content']</strong> &#8211; is the normal content that will be enclosed in the tag, but the string content will be placed differently depending on the tag_type above.</li>
<li><strong>$array['tag_content_before']</strong> &#8211; is an extra string content value typically used in an area before tag_content depending on the tag_type value.</li>
<li><strong>$array['tag_content_after']</strong> &#8211; is another extra string content value typically used in an area after tag_content depending on the tag_type value.</li>
<li><strong>$array['attributes']</strong> = is an extra key that will push the string value into the tag attributes area before the attributes that will be generated by the non-reserved keys ( see the last note ).</li>
<li><strong>$array['return']</strong> &#8211; will either echo when set as false or return the composed string when set as true. By default it is set as false so the function will echo it&#8217;s final output.</li>
<li><strong>All other key and value pairs set in the array</strong> will be used as attributes in the form of key name equals value. So $array['onclick'] = &#8216;fail();&#8217; would return onclick=&#8221;fail();&#8221; for any tag_type that uses attributes.</li>
</ul>
<p>Of course the main question might be: <strong>&#8220;Why bother when you can just write out some HTML with your PHP code?&#8221;</strong> Fine, you can do that and deal with double-quote single-quote escape madness. The examples below should be a clue for my usage of this boring, simple function.</p>
<p>Here is how I would use it to create a function for creating a simple H1:</p>
<pre class="brush: php;">&amp;lt;?php
function boring_h1( $headline, $headline_classes ) {
    the_html_tag( array(
    'tag' =&amp;gt; 'h1',
    'tag_content' =&amp;gt; $headline,
    'id' =&amp;gt; 'main-title',
    'class' =&amp;gt; $headline_classes,
    'tag_content_after' =&amp;gt; '&amp;lt;!-- #main-title --&amp;gt;'
    ) );
}
?&amp;gt;

&amp;lt;?php boring_h1( 'Look A Headline', 'title-big title-red' ); ?&amp;gt;</pre>
<p>This would produce HTML that looks like:</p>
<pre class="brush: xml;">&amp;lt;h1 id=&amp;quot;main-title&amp;quot; class=&amp;quot;title-big title-red&amp;quot;&amp;gt;Look A Headline&amp;lt;/h1&amp;gt;&amp;lt;!-- #main-title --&amp;gt;</pre>
<p>Now a more complex example is being used in my <a href="http://factory.funroe.net/projects/funbox-theme/">weirdo WordPress Theme Framework experimentation</a>. For that project I wanted to move to a CSS class based layout (not ID) and allow some modifications to the class attributes of various layout elements using WordPress filters. I could write a whole article about my reasons for doing this, but that would be even more boring.</p>
<p>The code example below shows a fraction of how this works, but you can also view the source of this website and see the technique in action. These are two additional functions. The first is an additional utility function using the_html_tag() with filters, and the second is just used to simplify the template function used in the theme.</p>
<pre class="brush: php;">&amp;lt;?php
// Funbox element Classes takes element and array and spits out a class= with some dynamic filtering.
function funbox_theme_layout_element_attributes( $element = '' , $element_classes = array(), $return = false ) {
    if ( $element == '' ) return;

    $element = sanitize_title_with_dashes( $element );
    $element_classes[] = $element . '-';

    $layout_element_defaults = array(
        'tag_type' =&amp;gt; 'attributes',
        'id' =&amp;gt; $element,
        'return' =&amp;gt; $return
    );

    // So the filter is consistent. No dashes sorry!
    $element = str_replace( '-', '_', $element );
    $element_classes = apply_filters( 'funbox_theme_' . $element . '_class',  $element_classes );

    $layout_element_defaults['class'] = implode( ' ', $element_classes );

    $layout_element_defaults = apply_filters( 'funbox_theme_' . $element . '_attributes',  $layout_element_defaults );  

    the_html_tag( $layout_element_defaults );
}

// Funbox Wrapper Class
function funbox_theme_layout_wrapper_attributes() {
    funbox_theme_layout_element_attributes( 'wrapper' , array( 'hfeed' ) );
}
?&amp;gt;</pre>
<p>In a WordPress Theme I would use this template code:</p>
<pre class="brush: php;">&amp;lt;div &amp;lt;?php funbox_theme_layout_wrapper_attributes() ?&amp;gt;&amp;gt;</pre>
<p>That template code would produce this type of output:</p>
<pre class="brush: xml;">&amp;lt;div id=&amp;quot;wrapper&amp;quot; class=&amp;quot;hfeed wrapper-&amp;quot;&amp;gt;</pre>
<p>Have fun! :P</p>
]]></content:encoded>
			<wfw:commentRss>http://funroe.net/2009/04/28/revisiting-my-really-boring-html-xml-tag-function-for-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress and Twitter Tools with Synected</title>
		<link>http://funroe.net/2009/04/19/wordpress-twitter-tools-with-s/</link>
		<comments>http://funroe.net/2009/04/19/wordpress-twitter-tools-with-s/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 05:10:57 +0000</pubDate>
		<dc:creator>jess</dc:creator>
				<category><![CDATA[Funroe]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugins]]></category>

		<guid isPermaLink="false">http://funroe.net/?p=508</guid>
		<description><![CDATA[Hi there! If you came here from a Twitter post, then you actually participated in testing these screwball modifications. I thought I would try a couple of modifications to a couple of WordPress Plugins to add some personalization to the way posts are sent to Twitter. These modifications require the Twitter Tools WordPress Plugin and [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Hi there! If you came here from a Twitter post, then you actually participated in testing these screwball modifications.</strong></em></p>
<p>I thought I would try a couple of modifications to a couple of WordPress Plugins to add some personalization to the way posts are sent to Twitter. <strong>These modifications require the <a href="http://alexking.org/projects/wordpress">Twitter Tools WordPress Plugin</a> and the <a href="http://www.blurbia.com/plugins/synected/">Synected WordPress Plugin</a> </strong>to be installed and activated on your <a href="http://wordpress.org/download/">WordPress 2.7</a> website. You may have to make some additional modifications if your website configuration is different from mine.<span id="more-508"></span></p>
<p><strong>Both of these modifications are added to this website theme&#8217;s functions.php file.</strong> You could also create a custom WordPress Plugin that could achieve the same results.</p>
<p><a href="http://alexking.org/projects/wordpress">Alex King&#8217;s Twitter Tools</a> is a Plugin that allows posting and archiving to and from the Twitter micro-blogging service. Posting an article to Twitter from your WordPress website is fairly easy, but I really wanted something more personal than &#8220;New Blog Post:&#8221;, so I added the following code to modify the tweet_prefix and tweet_format $aktt object variables. <strong>You have modify both values for this modification to work.</strong></p>
<p><strong>It is important to note that Twitter Tools uses the tweet_prefix value to limit the duplication of Twitter posts</strong> when it retrieves content from Twitter, and I haven&#8217;t tested it that far yet. Ask me in a week or so. I added the 20 value just to be sure this would have a $aktt object to modify.</p>
<pre class="brush: php;">// Modify Twitter Tools tweet format
function funroe_mod_twitter_tools() {
    global $aktt;
    $aktt-&amp;gt;tweet_prefix = ':P Funroe';
    $aktt-&amp;gt;tweet_format = $aktt-&amp;gt;tweet_prefix.': %s %s';
}
add_action('init', 'funroe_mod_twitter_tools', 20 );</pre>
<p>The next personalization I performed involves shortening the URL that Twitter Tools posts to Twitter. Twitter can sometimes use a service like tinyurl.com, bit.ly, or is.gd to make the URL shorter for the 140 character limitation on Twitter. Unfortunately this relies on another third party website and the URL doesn&#8217;t contain anything about your website.</p>
<p>I came across the <a href="http://www.blurbia.com/plugins/synected/">Synected WordPress Plugin by Tyler Shick and Jeff Smith</a> which is designed to offer a URL shortening system for your WordPress powered website. Although the Plugin is in beta, it was easy to install and configure. I added this code to my theme&#8217;s functions.php file to use a Twitter Tool Plugin filter to create custom a shortened URL that would be posted to Twitter.</p>
<pre class="brush: php;">// Add hook for Twitter Tools URL shortening filter using Synected WP Plugin
function funroe_synected_url( $tt_url ) {
    $tt_synected = Synected::singleton();
    $tt_synected-&amp;gt;create_url( $tt_url );
    return $tt_synected-&amp;gt;short_url;
}
add_filter('tweet_blog_post_url','funroe_synected_url');</pre>
<p>Now with both of the modifications added I can gain a more personalized integration when I post articles to my Twitter account using Twitter Tools. A typical Twitter entry should look like:</p>
<blockquote><p>:P Funroe: The Article Title http://funroe.net/x/something</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://funroe.net/2009/04/19/wordpress-twitter-tools-with-s/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Really boring HTML &amp; XML tag class function for PHP</title>
		<link>http://funroe.net/2008/11/03/really-boring-html-xml-tag-class-function-for-php/</link>
		<comments>http://funroe.net/2008/11/03/really-boring-html-xml-tag-class-function-for-php/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 21:33:35 +0000</pubDate>
		<dc:creator>jess</dc:creator>
				<category><![CDATA[Funroe]]></category>
		<category><![CDATA[Note]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://funroe.net/?p=232</guid>
		<description><![CDATA[That&#8217;s right. It&#8217;s simple boring and reusable. I used it for the complex HTML need to make the WP Super Edit WordPress administration options. It&#8217;s actually a function, but I use it inside a PHP class when I know I&#8217;m going to be either doing nasty HTML echo&#8217;s or returning complex HTML formatted variables. It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>That&#8217;s right. It&#8217;s simple boring and reusable. I used it for the complex HTML need to make the <a href="http://factory.funroe.net/projects/wp-super-edit/">WP Super Edit</a> WordPress administration options. It&#8217;s actually a function, but I use it inside a PHP class when I know I&#8217;m going to be either doing nasty HTML echo&#8217;s or returning complex HTML formatted variables. It&#8217;s not a template system or anything like that, I just needed something without the massive dependencies and overhead of a full fledged HTML / Dom / Pear class.</p>
<p>I&#8217;ve put it into a simple class for this example, and you can download the text file in case my site mangles the code: <a href="http://funroe.net/wp-content/files/2008/11/boring_tag_class_function.txt"><strong>Real Boring HTML &amp; XML Class PHP Text File</strong></a></p>
<p>Oh yea, and since a tag is a tag, then this can also do simple XML.</p>
<pre class="brush: php;">class boring_tag_creator {

     /**
     * Display or return html or xml tag with attributes.
     * @param array $tag_options options and content to display
     * @return mixed
     */
     function the_tag( $tag_options = array() ) {

         $attributes = '';
         $composite = '';

         foreach ( $tag_options as $name =&amp;gt; $option ) {
             if ( $name == 'tag' ) continue;
             if ( $name == 'content' ) continue;
             if ( $name == 'return' ) continue;
             if ( $name == 'tag_type' ) continue;
             $tag_attributes .= sprintf( ' %s=&amp;quot;%s&amp;quot;', $name, $option );
         }

         switch ( $tag_options['tag_type'] ) {
             case 'single':
                 $format = '%3$s &amp;lt;%1$s%2$s /&amp;gt;' ;
                 break;
             case 'single-after':
                 $format = '&amp;lt;%1$s%2$s /&amp;gt; %3$s' ;
                 break;
             case 'open':
                 $format = '&amp;lt;%1$s%2$s&amp;gt;%3$s';
                 break;
             case 'close':
                 $format = '%3$s&amp;lt;!--%1$s--&amp;gt;';
                 break;
             default:
                 $format = '&amp;lt;%1$s%2$s&amp;gt;%3$s&amp;lt;!--%1$s--&amp;gt;';
                 break;
         }

         $composite = sprintf( $format, $tag_options['tag'], $tag_attributes, $tag_options['content'] );

         if ( $tag_options['return'] == true ) return $composite ;

         echo $composite;
     }

     /**
     * Boring Header and paragraph either echoed or returned...
     */
     function boring_html( $header, $content, $return = false ) {

         $the_h2 = array(
             'tag' =&amp;gt; 'h2',
             'content' =&amp;gt; $header
         );

         $the_content = array(
             'tag' =&amp;gt; 'p',
             'id' =&amp;gt; 'boring_content_id',
             'style' =&amp;gt; 'border: 1px solid red',
             'class' =&amp;gt; 'boring_content_class',
             'content' =&amp;gt; $content
         );

         if ( $return ) {
             $the_h2[ 'return' ] = true;
             $the_content[ 'return' ] = true;
             return $this-&amp;gt;the_tag( $the_h2 ) . $this-&amp;gt;the_tag( $the_content );
         } else {
             $this-&amp;gt;the_tag( $the_h2 );
             $this-&amp;gt;the_tag( $the_content );
         }

     } 

}

$boring = new boring_tag_creator;

$boring-&amp;gt;boring_html( 'The Title', 'Some words about this for the content.' );

$boring_html_variable = $boring-&amp;gt;boring_html( 'Another Title', 'More words about this other thing for the content.', true );

echo $boring_html_variable;</pre>
<p>The class function <strong>the_tag</strong> takes an array. In that array there are only three special keys.</p>
<ul>
<li><strong>tag</strong> (the html or xml tag)</li>
<li><strong>content</strong> (the content that goes somewhere with in or near the tag see tag_type)</li>
<li><strong>return</strong> ( To return everything as a string set as <strong>true</strong>, or to echo set as <strong>false</strong> which is the default  )</li>
<li><strong>tag_type</strong> ( controls how the tag is composed )
<ul>
<li><strong>single</strong> ( put the content in front and self close the tag )</li>
<li><strong>single-after</strong> ( put the content behind and self close the tag )</li>
<li><strong>open</strong> ( create an open tag and put content after )</li>
<li><strong>close</strong> ( close the tag )</li>
<li><strong>default</strong> ( opened the tag, put the content, close the tag )</li>
</ul>
</li>
</ul>
<p><strong>Whatever else you put as part of the array becomes an attribute for the tag.</strong> Simple, boring, and might be useful. Like I said, boring, but this has been useful for me to construct some complex HTML and XML structures.</p>
]]></content:encoded>
			<wfw:commentRss>http://funroe.net/2008/11/03/really-boring-html-xml-tag-class-function-for-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WordPress Page with Loops and PHP Cloning</title>
		<link>http://funroe.net/2008/11/01/wordpress-page-with-loops-and-php-cloning/</link>
		<comments>http://funroe.net/2008/11/01/wordpress-page-with-loops-and-php-cloning/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 18:00:51 +0000</pubDate>
		<dc:creator>jess</dc:creator>
				<category><![CDATA[Funroe]]></category>
		<category><![CDATA[Note]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://funroe.net/?p=223</guid>
		<description><![CDATA[This is a follow up of a quick note I sent to the wp-hackers list about multiple loops and page templates. I thought I would expand on the subject a little bit. WordPress uses the Loop to process and display posts. It sounds like a simple enough process, but there is alot that happens before, [...]]]></description>
			<content:encoded><![CDATA[<p>This is a follow up of a quick note I sent to the wp-hackers list about multiple loops and page templates. I thought I would expand on the subject a little bit.</p>
<p>WordPress uses <a href="http://codex.wordpress.org/The_Loop">the Loop</a> to process and display posts. It sounds like a simple enough process, but there is alot that happens before, after, and during the Loop; Objects get created, global variables get set, and special functions get executed. It gnashes, it gnaws until it finally gets the job done interacting with your theme.</p>
<p>I had an old Sandbox based theme with a page template that performed a specialized WordPress query based on a custom field called page_category. This  page template was designed to show the orginal page content followed by a secion of posts using the category set by the page_category custom field. To make matters more complicated the original page template was built on a PHP4 server and my test server is PHP5.</p>
<p>There are several methods to perform multiple loops. I&#8217;m going to illustrate two that I worked with for this problem there are others and my original research comes from  <a href="http://codex.wordpress.org/The_Loop">the Loop</a> documentation in the WordPress Codex. I am going to paste in the entire source for both page templates, so be aware that they are based on a <a href="http://code.google.com/p/sandbox-theme/">Sandbox theme</a>, so they still contain depencies on some Sandbox functions.</p>
<h3>Custom WP_Query</h3>
<p>The first supplied by <a href="http://markjaquith.com/">Mark Jaquith</a> in answer to my original post to wp-hackers uses a custom WP_Query object. It works great if you want to grab some of the post and it&#8217;s related data, but I needed a little more. The only thing that does not work is the comments_popup_link function, so it won&#8217;t show the number of comments. Everything else seems to work fine. Also note that I set the $more variable inside the while loop to properly show read more links for the individual posts. Setting it outside the loop does not work. This could be customized to make it do what I want, but I am lazy by nature.</p>
<pre class="brush: php;">&lt;?php
/*
Template Name: Page with Posts from Category
*/

/*
Usage:

Custom Field Name:
	page_category

Custom Field Values:
	category name

*/
?&gt;
&lt;?php get_header() ?&gt;

	&lt;div id=&quot;container&quot;&gt;
		&lt;div id=&quot;content&quot;&gt;

&lt;?php the_post() ?&gt;
			&lt;div id=&quot;post-&lt;?php the_ID(); ?&gt;&quot; class=&quot;&lt;?php sandbox_post_class() ?&gt;&quot;&gt;
				&lt;h2 class=&quot;entry-title&quot;&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt;
				&lt;div class=&quot;entry-content&quot;&gt;
&lt;?php the_content() ?&gt;

&lt;?php wp_link_pages(&quot;\t\t\t\t\t&lt;div class='page-link'&gt;&quot;.__('Pages: ', 'sandbox'), &quot;&lt;/div&gt;\n&quot;, 'number'); ?&gt;

&lt;?php edit_post_link(__('Edit', 'sandbox'),'&lt;span class=&quot;edit-link&quot;&gt;','&lt;/span&gt;') ?&gt;

				&lt;/div&gt;
			&lt;/div&gt;&lt;!-- .post --&gt;

&lt;?php
if ( ( $page_category_name = get_post_custom_values( 'page_category' ) ) ) {

	$custom_loop = new WP_Query( array(
		'category_name' =&gt; $page_category_name[0],
		'showposts' =&gt; get_option('posts_per_page')
		));

?&gt;
			&lt;div id=&quot;page-posts&quot;&gt;

	&lt;?php while ( $custom_loop-&gt;have_posts() ) : $custom_loop-&gt;the_post() ?&gt;

&lt;?php
	global $more;
	// set $more to 0 in order to only get the first part of the post
	$more = 0;
?&gt;
				&lt;div id=&quot;post-&lt;?php the_ID() ?&gt;&quot; class=&quot;&lt;?php sandbox_post_class() ?&gt;&quot;&gt;
					&lt;h3 class=&quot;entry-title&quot;&gt;&lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot; title=&quot;&lt;?php printf(__('Permalink to %s', 'sandbox'), wp_specialchars(get_the_title(), 1)) ?&gt;&quot; rel=&quot;bookmark&quot;&gt;&lt;?php the_title() ?&gt;&lt;/a&gt;&lt;/h3&gt;
					&lt;div class=&quot;entry-date&quot;&gt;&lt;abbr class=&quot;published&quot; title=&quot;&lt;?php the_time('Y-m-d\TH:i:sO'); ?&gt;&quot;&gt;&lt;?php unset($previousday); printf(__('%1$s &amp;#8211; %2$s', 'sandbox'), the_date('', '', '', false), get_the_time()) ?&gt;&lt;/abbr&gt;&lt;/div&gt;
					&lt;div class=&quot;entry-content&quot;&gt;
	&lt;?php the_content(''.__('Read More &lt;span class=&quot;meta-nav&quot;&gt;&amp;raquo;&lt;/span&gt;', 'sandbox').''); ?&gt;

					&lt;?php wp_link_pages('before=&lt;div class=&quot;page-link&quot;&gt;' .__('Pages:', 'sandbox') . '&amp;after=&lt;/div&gt;') ?&gt;
					&lt;/div&gt;
					&lt;div class=&quot;entry-meta&quot;&gt;
						&lt;span class=&quot;author vcard&quot;&gt;&lt;?php printf(__('By %s', 'sandbox'), '&lt;a class=&quot;url fn n&quot; href=&quot;'.get_author_link(false, $authordata-&gt;ID, $authordata-&gt;user_nicename).'&quot; title=&quot;' . sprintf(__('View all posts by %s', 'sandbox'), $authordata-&gt;display_name) . '&quot;&gt;'.get_the_author().'&lt;/a&gt;') ?&gt;&lt;/span&gt;
						&lt;span class=&quot;meta-sep&quot;&gt;|&lt;/span&gt;
						&lt;span class=&quot;cat-links&quot;&gt;&lt;?php printf(__('Posted in %s', 'sandbox'), get_the_category_list(', ')) ?&gt;&lt;/span&gt;
						&lt;span class=&quot;meta-sep&quot;&gt;|&lt;/span&gt;
						&lt;?php the_tags(__('&lt;span class=&quot;tag-links&quot;&gt;Tagged ', 'sandbox'), &quot;, &quot;, &quot;&lt;/span&gt;\n\t\t\t\t\t&lt;span class=\&quot;meta-sep\&quot;&gt;|&lt;/span&gt;\n&quot;) ?&gt;
	&lt;?php edit_post_link(__('Edit', 'sandbox'), &quot;\t\t\t\t\t&lt;span class=\&quot;edit-link\&quot;&gt;&quot;, &quot;&lt;/span&gt;\n\t\t\t\t\t&lt;span class=\&quot;meta-sep\&quot;&gt;|&lt;/span&gt;\n&quot;); ?&gt;
						&lt;span class=&quot;comments-link&quot;&gt;&lt;?php comments_popup_link(__('Comments (0)', 'sandbox'), __('Comments (1)', 'sandbox'), __('Comments (%)', 'sandbox')) ?&gt;&lt;/span&gt;
					&lt;/div&gt;
				&lt;/div&gt;&lt;!-- .post --&gt;

	&lt;?php endwhile ?&gt;

			&lt;/div&gt;

&lt;?php
} // end if ( ( $page_category_option = get_post_custom_values( 'page_category' ) ) )
?&gt;

		&lt;/div&gt;&lt;!-- #content --&gt;
	&lt;/div&gt;&lt;!-- #container --&gt;

&lt;?php get_sidebar() ?&gt;
&lt;?php get_footer() ?&gt;</pre>
<h3>The Loop and Cloned Objects</h3>
<p>This is an example of saving or cloning the original post data, running a new query, and resetting the original objects. Remember this site is in production on an old PHP4 server (not my fault) and the test server is PHP5. WordPress is PHP4 compatible, and PHP4 just recently became unsupported. Someday WordPress will move to PHP5 and that will no doubt cause major changes in how the Loop funcitons. Remember the WordPress Loop does a lot of work, so for this solution I need those global variables to be reset.</p>
<p>The first part is a simple helper function I totaly ripped off from <a href="http://drupal.org/">Drupal</a> to help with making copies of the WordPress Objects. I called it wp_clone and put it the functions.php file for this particular theme.</p>
<pre class="brush: php;">/*
Helper function to clone objects for php4 and php5
*/
function wp_clone($object) {
  return version_compare(phpversion(), '5.0') &amp;lt; 0 ? $object : clone($object);
}&lt;/pre&gt;
The theme template is similar to the earlier one, but I am taking a copy of the original $post and $wp_query objects and restoring them.

&lt;pre lang=&quot;php&quot;&gt;
&lt;?php
/*
Template Name: Page with Posts from Category
*/

/*
Usage:

Custom Field Name:
	page_category

Custom Field Values:
	category name

*/
?&gt;
&lt;?php get_header() ?&gt;

	&lt;div id=&quot;container&quot;&gt;
		&lt;div id=&quot;content&quot;&gt;

&lt;?php the_post() ?&gt;
			&lt;div id=&quot;post-&lt;?php the_ID(); ?&gt;&quot; class=&quot;&lt;?php sandbox_post_class() ?&gt;&quot;&gt;
				&lt;h2 class=&quot;entry-title&quot;&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt;
				&lt;div class=&quot;entry-content&quot;&gt;
&lt;?php the_content() ?&gt;

&lt;?php wp_link_pages(&quot;\t\t\t\t\t&lt;div class='page-link'&gt;&quot;.__('Pages: ', 'sandbox'), &quot;&lt;/div&gt;\n&quot;, 'number'); ?&gt;

&lt;?php edit_post_link(__('Edit', 'sandbox'),'&lt;span class=&quot;edit-link&quot;&gt;','&lt;/span&gt;') ?&gt;

				&lt;/div&gt;
			&lt;/div&gt;&lt;!-- .post --&gt;

&lt;?php
if ( ( $page_category_name = get_post_custom_values( 'page_category' ) ) ) {

	// duplicate post for later recovery

	$temp_wp_query = wp_clone( $wp_query );
	$temp_post = wp_clone( $post );

	global $more;
	// set $more to 0 in order to only get the first part of the post
	$more = 0;

	query_posts( 'category_name=' . $page_category_name[0] . '&amp;showposts=' . get_option('posts_per_page') );

?&gt;
			&lt;div id=&quot;page-posts&quot;&gt;

	&lt;?php while ( have_posts() ) :  the_post() ?&gt;
				&lt;div id=&quot;post-&lt;?php the_ID() ?&gt;&quot; class=&quot;&lt;?php sandbox_post_class() ?&gt;&quot;&gt;
					&lt;h3 class=&quot;entry-title&quot;&gt;&lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot; title=&quot;&lt;?php printf(__('Permalink to %s', 'sandbox'), wp_specialchars(get_the_title(), 1)) ?&gt;&quot; rel=&quot;bookmark&quot;&gt;&lt;?php the_title() ?&gt;&lt;/a&gt;&lt;/h3&gt;
					&lt;div class=&quot;entry-date&quot;&gt;&lt;abbr class=&quot;published&quot; title=&quot;&lt;?php the_time('Y-m-d\TH:i:sO'); ?&gt;&quot;&gt;&lt;?php unset($previousday); printf(__('%1$s &amp;#8211; %2$s', 'sandbox'), the_date('', '', '', false), get_the_time()) ?&gt;&lt;/abbr&gt;&lt;/div&gt;
					&lt;div class=&quot;entry-content&quot;&gt;
	&lt;?php the_content(''.__('Read More &lt;span class=&quot;meta-nav&quot;&gt;&amp;raquo;&lt;/span&gt;', 'sandbox').''); ?&gt;

					&lt;?php wp_link_pages('before=&lt;div class=&quot;page-link&quot;&gt;' .__('Pages:', 'sandbox') . '&amp;after=&lt;/div&gt;') ?&gt;
					&lt;/div&gt;
					&lt;div class=&quot;entry-meta&quot;&gt;
						&lt;span class=&quot;author vcard&quot;&gt;&lt;?php printf(__('By %s', 'sandbox'), '&lt;a class=&quot;url fn n&quot; href=&quot;'.get_author_link(false, $authordata-&gt;ID, $authordata-&gt;user_nicename).'&quot; title=&quot;' . sprintf(__('View all posts by %s', 'sandbox'), $authordata-&gt;display_name) . '&quot;&gt;'.get_the_author().'&lt;/a&gt;') ?&gt;&lt;/span&gt;
						&lt;span class=&quot;meta-sep&quot;&gt;|&lt;/span&gt;
						&lt;span class=&quot;cat-links&quot;&gt;&lt;?php printf(__('Posted in %s', 'sandbox'), get_the_category_list(', ')) ?&gt;&lt;/span&gt;
						&lt;span class=&quot;meta-sep&quot;&gt;|&lt;/span&gt;
						&lt;?php the_tags(__('&lt;span class=&quot;tag-links&quot;&gt;Tagged ', 'sandbox'), &quot;, &quot;, &quot;&lt;/span&gt;\n\t\t\t\t\t&lt;span class=\&quot;meta-sep\&quot;&gt;|&lt;/span&gt;\n&quot;) ?&gt;
	&lt;?php edit_post_link(__('Edit', 'sandbox'), &quot;\t\t\t\t\t&lt;span class=\&quot;edit-link\&quot;&gt;&quot;, &quot;&lt;/span&gt;\n\t\t\t\t\t&lt;span class=\&quot;meta-sep\&quot;&gt;|&lt;/span&gt;\n&quot;); ?&gt;
						&lt;span class=&quot;comments-link&quot;&gt;&lt;?php comments_popup_link(__('Comments (0)', 'sandbox'), __('Comments (1)', 'sandbox'), __('Comments (%)', 'sandbox')) ?&gt;&lt;/span&gt;
					&lt;/div&gt;
				&lt;/div&gt;&lt;!-- .post --&gt;

	&lt;?php endwhile ?&gt;

			&lt;/div&gt;

&lt;?php

	$post = wp_clone( $temp_post );
	$wp_query = wp_clone( $temp_wp_query );

} // end if ( ( $page_category_option = get_post_custom_values( 'page_category' ) ) )
?&gt;

		&lt;/div&gt;&lt;!-- #content --&gt;
	&lt;/div&gt;&lt;!-- #container --&gt;

&lt;?php get_sidebar() ?&gt;
&lt;?php get_footer() ?&gt;
</pre>
<p>The cloning method is more of a hack. It would be more appropriate to make a custom query and set functions or write special functions to get the data you need. Of course I am pressed for time, so I will be relying on the cheap and lazy clone method for a little while longer.</p>
]]></content:encoded>
			<wfw:commentRss>http://funroe.net/2008/11/01/wordpress-page-with-loops-and-php-cloning/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
