Jump to content

Can I Assign a PHP Syntax as a Value?


kt83

Recommended Posts

You mean you want to call the recent_posts() function? Im guessing you should be able to do

 

$tpl -> AssignArray(array('recent_posts' => recent_posts()));

 

I think it's also possible by using nowdoc; Nowdoc is available as of php v5.3

You mean you want to call the recent_posts() function? Im guessing you should be able to do

 

$tpl -> AssignArray(array('recent_posts' => recent_posts()));

 

I got that to work, thanks.  But for some reason, I can not place it specifically where I want it.  On my site, I use templates so home.php pushes home.tpl.  When I place the "recent posts" line of code into the php file, the output is displayed either before or after the content of the home.tpl file automatically.  How do I stop it from doing that?

 

I've tried using {} tags to call the variable in the home.tpl but that doesn't work...

This is what my home.php file looks like:

 

<?php
$tpl = new template;
$tpl -> Load("!theme/{$GLOBALS["THEME"]}/templates/home.tpl");
$tpl -> GetObjects();


require_once("home/www/sitename/blog/wp-config.php");
        $recentPosts = recent_posts();       
        $recentComments = get_recent_comments();
$tpl -> AssignArray(array('recent.posts' => '$recentPosts'));
        $tpl -> AssignArray(array('recent.comments' => '$recentComments'))
$tpl-> CleanZones();
$tpl -> Flush();

?>

 

 

And inside my home.tpl file, I have, in two different divs, {recent.posts} and {recent.comments}

 

On the page, the recent_posts and recent_comments appear before all the content and in the div where I placed {recent.posts}, appears $recentPosts and {recent.comments} appears $recentComments.

 

I tried it without the ' ' around $recentPosts and $recentComments, but nothing came out.

 

Hope you can figure this out.  Thanks for your help!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.