WordPress.org

Ready to get started?Download WordPress

Forums

Assign Template Tag to PHP Variable? (1 post)

  1. fredhead
    Member
    Posted 6 years ago #

    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";
    				endwhile;
    				$toc .= "</ul>\n";
    				$toc .= "</div>\n";
    			endif;
    		endif;

    Thank you for any help!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.