- 2009-10-12 (月) 21:04
- WordPress
Wiki書式では[[タイトル]] とすると、その記事へのリンクを生成してくれます。
そのWiki書式のリンクをWordPressにも実装するInterlinksプラグインを使っていたのですが、ちょっくらバグがあったので修正したというメモ。
function hq_interparse($content){
if(strpos($content, "[[") !== false){
preg_match_all('/(\[\[.+?\]\])/',$content,$wikilinks, PREG_SET_ORDER);
foreach ($wikilinks as $val) {
if(strpos($val[0], "|") !== false){
$pieces = explode("|", $val[0]);
$new_val = preg_replace('/\[\[(.+?)/', '$1', $pieces[0]);
$link_text = preg_replace('/(.+?)\]\]/', '$1', $pieces[1]);
$post_id = hq_interreplace($new_val);
if($post_id == 0){
$content2 = "<span style='color:red;'>$new_val</span>";
} else {
$permalink = get_permalink($post_id);
$content2 = "<a href='$permalink'>$link_text</a>";
}
$content = str_replace($val[0], $content2, $content);
} else {
$new_val = preg_replace('/\[\[(.+?)\]\]/', '$1', $val[0]);
$post_id = hq_interreplace($new_val);
if($post_id == 0){
$content2 = "<span style='color:red;'>$val[0]</span>";
} else {
$permalink = get_permalink($post_id);
$content2 = "<a href='$permalink'>$new_val</a>";
}
$content = str_replace($val[0], $content2, $content);
}
}
}
return $content;
}
コメント:0
トラックバック:0
- この記事のトラックバック URL
- http://web.lovingcat.net/interlinks27-bugfix/trackback/
- トラックバックの送信元リスト
- Interlinks 2.7 に修正を加える - LC Memo より