! Requirement
* Link easily from blog posts to wiki pages in a way that does not need re-editing if I move the wiki and which copes with non-CamelCase [WikiWord]s.
! Approach
* Define custom tags that will be used in blog posts.
* Create [http://www.wordpress.org/ "WordPress"] filter plugin to replace custom tags (see [WordPress:Plugin/API]) with links to the relevant wiki pages.
!Usage
* Save the [.#code "code"] below into a suitably-named php file.
* Upload the file to the wp-content/plugins directory.
* Go to the !WordPress plugins admin screen and activate the plugin.
* Write a test post.
! Change history
* 2005-03-11 changed the regexes to be non-greedy - fixes bug where more than one wiki link on one line of blog post
! To Do
* A more sophisticated version would query the wiki to see if the pages existed already and alter the presentation appropriately.
* This plugin could become a general-purpose tag-replacer, the limit is your understanding of regular expressions!
! Code [#code]
<code>
<?php
Register this filter
add_filter('the_content', 'to_wiki', 9);
add_filter('the_excerpt', 'to_wiki', 9);
add_filter('the_content', 'to_bliki', 9);
add_filter('the_excerpt', 'to_bliki', 9);



_to_wiki: callback function for preg_replace_callback in to_wiki
function _to_wiki($matches)
{

$expr = $matches[1];
$wikipage = '<a href="http://mysite.com/path/to/wiki/' ;
$wikipage .= $expr;
$wikipage .= '" title = "Link to Wiki:';
$wikipage .= $expr;
$wikipage .= '">';
$wikipage .= $expr;
$wikipage .= '</a>';

return $wikipage;
}


to_wiki: A WordPress URL filter that returns link to my wiki
function to_wiki($content)
{
return preg_replace_callback('|((?U)\[wiki\](.*)\[/wiki\])|i', '_to_wiki', $content);
}

/


_to_bliki: callback function for preg_replace_callback in to_bliki
function _to_bliki($matches)
{

$expr = $matches[1];
$wikipage = '<a href="http://mysite.com/path/to/personal/wiki/' ;
$wikipage .= $expr;
$wikipage .= '" title = "Link to my personal wiki:';
$wikipage .= $expr;
$wikipage .= '">';
$wikipage .= $expr;
$wikipage .= '</a>';

return $wikipage;
}


to_bliki: A WordPress URL filter that returns link to my other wiki
function to_bliki($content)
{
return preg_replace_callback('|((?U)\[bliki\](.*)\[/bliki\])|i', '_to_bliki', $content);
}



?>
</code>
! Licence
Public domain, do what you like with it but it's your responsibility...


CategoryWordPress
CategorySiteDesign
CategoryCoding
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki