First of all : Cool idea.
I don’t know whether there exists a plugin for this task, but I would simply implement this as a new small plugin.
I would recommend changing your syntax, so that it won’t contain the links as html.
I changed it to:
{{previousKnowledge|first=...|second=...}}
Here is my simple first approach :
<?php
/*
Plugin Name: Previous Knowledge
Plugin URI: TODO
Description: TODO
Author: xaeDes
Version: 0.1
Author URI: TODO
License: GPL2
*/
function previous_knowledge_preg_replace_callback( $matches ) {
//$matches[1] contains the "https://wordpress.stackexchange.com/questions/46725/..." in '{{previousKnowledge|...}}'
$items = explode("|", $matches[1]);
$replaced = '<div id="previousKnowledge"><ul>';
foreach( $items as $item ) {
$item_info = explode("=",$item);
$replaced .= "<li><a href="https://wordpress.stackexchange.com/questions/46725/${item_info[1]}">${item_info[0]}</a></li>";
}
$replaced .= '</ul></div>';
return $replaced;
}
/**
* Looks for occurrences of {{previousKnowledge|...}} tags and replaces them by html.
* @param string $content
* @return string
*/
function previous_knowledge_content_filter( $content ) {
return preg_replace_callback('#{{previousKnowledge\\s*\\|(.+)}}#i','previous_knowledge_preg_replace_callback', $content);
}
add_filter( 'the_content' , 'previous_knowledge_content_filter' );
?>
I tested with your example and it works.
You may change the output html in previous_knowledge_preg_replace_callback(..).
How to install it in your wordpress :
-
Create a folder named ‘previous_knowledge’ (or whatever name you find appropriate) in wp-contents/plugins/.
-
Create a php file named previous_knowledge.php inside this folder and paste the code into the file.
-
Now you only have to activate it and put “{{previousKnowledge|first=…|second=…}}” into your posts or pages.
Do you want further explanations?