0

I had been trying to make my WordPress blog Thumnails Clickable without any luck.

Here is the code I am supposed to change:

<a href="<?php the_permalink(); ?>" title="<?php the_title();?>"><?php the_post_thumbnail(); ?></a>
2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by design324095
-1

without any more detailed information, it seems to me like you are trying to put this in a post or page. First thing to know is that Wordpress will not process PHP within a post or page; at least, not without some modification. Fortunately some people have made plugins which will allow PHP within a wordpress page; here are two plugins:

METHOD 1: PHP INCLUDE

With this method, you use a server side include (SSI) in order to use PHP within a Wordpress post or page. This is by far the best method.

STEPS:
1. Download PHP Include Wordpress plugin.
2. open the administration panel of Wordpress, go to "Plugins", and upload the .zip file for PHP Include that you just downloaded.
3. activate the plugin.
4. create your file that includes your PHP code, which may include HTML as well.
5. configure PHP Include in your Administration Panel in the Wordpress "Settings" tab on the left-hand column.
6. where you want to include your SSI, place the code <?php include("your-file.php"); ?> (where "your-file.php" is your file).

Congratulations! You're done.
_____________________________________________________________________________________

METHOD 2: PHP EXEC Plugin

With this method, you can place PHP code directly in your Wordpress post or page.

STEPS:
1. create a text file on your PC named "phpexec.txt".
2. copy the code for phpexec.php (below) into the file phpexec.txt that you just created, and save it.
3. rename the file from "phpexec.txt" to "phpexec.php".
4. using a program like WinRAR or 7-Zip, create a .zip file of phpexec.php.
5. open the administration panel of Wordpress, go to "Plugins", and upload phpexec.zip
6. activate the plugin PHPexec.
7. Now place your PHP code inside the tags, <phpcode></phpcode> .
Your PHP code should now work in your Wordpress page or post!

---------------------------------

Code for phpexec.php:

<?php

/*
Plugin Name: PHP Exec
Plugin URI: http://priyadi.net/archives/2005/03/02/wordpress-php-exec-plugin/
Description: Execute PHP Code inside a post. Do NOT use this plugin if you don't trust your WP users.
Version: 1.7
Author: Priyadi Iman Nurcahyo
Author URI: http://priyadi.net/


Inspired by runphp plugin by Mark Somerville
http://mark.scottishclimbs.com/archives/2004/07/02/running-php-in-wordpress-posts/
*/



### mask code before going to the nasty balanceTags ###
function php_exec_pre($text) {
	$textarr = preg_split("/(<phpcode>.*<\\/phpcode>)/Us", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between
	$stop = count($textarr);// loop stuff
	for ($phpexec_i = 0; $phpexec_i < $stop; $phpexec_i++) {
		$content = $textarr[$phpexec_i];
		if (preg_match("/^<phpcode>(.*)<\\/phpcode>/Us", $content, $code)) { // If it's a phpcode	
			$content = '[phpcode]' . base64_encode($code[1]) . '[/phpcode]';
		}
		$output .= $content;
	}
	return $output;
}

### unmask code after balanceTags ###
function php_exec_post($text) {
	$textarr = preg_split("/(\\[phpcode\\].*\\[\\/phpcode\\])/Us", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between
	$stop = count($textarr);// loop stuff
	for ($phpexec_i = 0; $phpexec_i < $stop; $phpexec_i++) {
		$content = $textarr[$phpexec_i];
		if (preg_match("/^\\[phpcode\\](.*)\\[\\/phpcode\\]/Us", $content, $code)) { // If it's a phpcode
			$content = '<phpcode>' . base64_decode($code[1]) . '</phpcode>';
		}
		$output .= $content;
	}
	return $output;
}

### main routine ###
function php_exec_process($phpexec_text) {
	$phpexec_userdata = get_userdatabylogin(the_author('login',false));
	if($phpexec_userdata->user_level >= php_exec_getuserlevel()){
		$phpexec_doeval = true;
	}

	$phpexec_textarr = preg_split("/(<phpcode>.*<\\/phpcode>)/Us", $phpexec_text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between
	$phpexec_stop = count($phpexec_textarr);// loop stuff
	for ($phpexec_i = 0; $phpexec_i < $phpexec_stop; $phpexec_i++) {
		$phpexec_content = $phpexec_textarr[$phpexec_i];
		if (preg_match("/^<phpcode>(.*)<\\/phpcode>/Us", $phpexec_content, $phpexec_code)) { // If it's a phpcode	
			$phpexec_php = $phpexec_code[1];
			if ($phpexec_doeval) {
				ob_start();
				eval("?>". $phpexec_php . "<?php ");
				$phpexec_output .= ob_get_clean();
			} else {
				$phpexec_output .= htmlspecialchars($phpexec_php);
			}
		} else {
			$phpexec_output .= $phpexec_content;
		}
	}
	return $phpexec_output;
}

function php_exec_options() {
	if($_POST['php_exec_save']){
		update_option('php_exec_userlevel',$_POST['php_exec_userlevel']);
		echo '<div class="updated"><p>User level saved successfully.</p></div>';
	}

	?>
	<div class="wrap">
	<h2>PHPExec Options</h2>
	<form method="post" id="php_exec_options">
		<fieldset class="options">
		<legend>Minimum User Level</legend>
		<table width="100%" cellspacing="2" cellpadding="5" class="editform"> 
			<tr valign="top"> 
				<th width="33%" scope="row">User Level:</th> 
				<td><input name="php_exec_userlevel" type="text" id="php_exec_userlevel" value="<?php echo get_option('php_exec_userlevel') ;?>" size="2" maxlength="1" />
				<br />Sets the minimum level to allow users to run PHP code in posts. If option is not set, then defaults to 9.</td> 
			</tr>
		</table>
		<p class="submit"><input type="submit" name="php_exec_save" value="Save" /></p>
		</fieldset>
	</form>
	</div>
	<?php
}

function php_exec_adminmenu(){
	add_options_page('PHPExec Options', 'PHPExec', 9, 'phpexec.php', 'php_exec_options');
}

function php_exec_getuserlevel(){
	if($level = get_option('php_exec_userlevel')){
		return $level;
	} else {
		return 9;
	}
}

add_action('admin_menu','php_exec_adminmenu',1);

add_filter('content_save_pre', 'php_exec_pre', 29);
add_filter('content_save_pre', 'php_exec_post', 71);
add_filter('the_content', 'php_exec_process', 2);

add_filter('excerpt_save_pre', 'php_exec_pre', 29);
add_filter('excerpt_save_pre', 'php_exec_post', 71);
add_filter('the_excerpt', 'php_exec_process', 2);

Edited by design324095: n/a

Votes + Comments
Catch the question.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.