Support » Fixing WordPress » Assign Template Tag to PHP Variable?

  • Hi,

    I’m trying to assign WordPress template tags to PHP variables, while in the WP loop, so that I can build a larger variable that contains HTML output. However, when I assign the_title() or the_permalink() to a PHP variable, WordPress outputs the value and leaves the variable empty.

    Here’s my code, can anyone tell me what I’m doing wrong?

    if ($parentcatid == '32') :
    			$rdtoc_query = new WP_Query('showposts=15&cat='.$storycatid);
    			if ($rdtoc_query->have_posts()) :
    				$toc = "<div style=\"background: #eee; width: 270px; float: left; margin: 0 10px; padding: 10px; position: relative;\">\n";
    				$toc .= "<h3>".$parentcat."</h3>\n";
    				$toc .= "<p><em>".$storycatname."</em></p>\n";
    				$toc .= "<ul>\n";
    				while ($rdtoc_query->have_posts()) : $rdtoc_query->the_post();
    					$permalink = the_permalink();
    					$linkattribute = the_title_attribute();
    					$linktitle = "Permanent Link to ".$linkattribute;
    					$title = the_title();
    					$toc .= "<li><a href=\"".$permalink." rel=\"bookmark\" title=\"".$linktitle."\">".$title."</a></li>\n";
    				$toc .= "</ul>\n";
    				$toc .= "</div>\n";

    Thank you for any help!

  • The topic ‘Assign Template Tag to PHP Variable?’ is closed to new replies.