Created
September 22, 2010 10:02
-
-
Save quis/591441 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
/* | |
Plugin Name: quis.cc inline images | |
Plugin URI: http://quis.cc | |
Description: Embed an image post inside a text post | |
Version: 0.1 | |
Author: Chris Hill-Scott | |
Author URI: http://quis.cc | |
License: GPL2 | |
Usage: [[1234]] where 1234 is a post ID | |
*/ | |
// Hook into Wordpress | |
add_filter("the_content", "qImage"); | |
// Function to filter posts | |
function qImage($postContent) { | |
// Buffer content so that function can return it | |
ob_start(); | |
// This variable is used in the page template to generate correct permalinks | |
$parentLink = get_permalink(); | |
// Search line-by-line for [[1234]] | |
foreach ( | |
explode("\n", $postContent) | |
as $line | |
) { | |
if (preg_match("/\[\[(\d*)\]\]/", $line, $matches)) { | |
// Retrieve post and set up for image template | |
global $post; | |
$holdingPost = $post; | |
foreach ( | |
get_posts("p=".$matches[1]."&post_status=any") | |
as $post | |
) { | |
setup_postdata($post); | |
require(TEMPLATEPATH."/image.php"); | |
} | |
$post = $holdingPost; | |
} else { | |
// Pass output through if special syntax not found | |
echo $line; | |
} | |
} | |
// Return buffered contents | |
$output = ob_get_contents(); | |
ob_end_clean(); | |
return $output; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment