what's wrong with this function - please please help
Posted: Mon Jun 21, 2010 11:57 am
Hi Everyone,
I need help with this inline post and categories plug-in. Originally by Aral Balkan but revised Ronny Welter.
Description: Allows you to include posts or categories in pages. This is simply done by using the syntax [[postid]] or [[cat:catid]].
The post id is working fine, but when I include a catid, it actually just pulls the 10 most recent posts from ALL categories. It's like it's not matching up the catid. Can you please take a look at this function???
Thank you! I really appreciate your help!!
//Added by Ronny Welter
//Get the [[cat:nnn]] tag from the post/page and get all posts in that category
//and add them in place to get them read by the includePosts function.
function includeCategoyPosts($content=''){
// Get the category IDs to include. Category IDs are in the form [[cat:nnn]].
preg_match_all('/(?<=\\[\\[cat\\:)[0-9]+(?=\\]\\])/', $content, $matches, PREG_PATTERN_ORDER);
$numCatMatches = count($matches[0]);
for ($i = 0; $i < $numCatMatches; $i++){//there might be different category includes, let's check them all
//
$allCatPosts=get_posts("numberposts=10&category=".$matches[0][$i]);
$numCatPosts = count($allCatPosts);
$thePostList='';
for ($j = 0; $j < $numCatPosts; $j++){//let's pot all the inline tags in there.
$thePostList .= "[[";
$thePostList .= $allCatPosts[$j]->ID;
$thePostList .= "]] \n";
}
//now let's put this part in the match in case
$content = str_replace("[[cat:".$matches[0][$i]."]]",$thePostList,$content);
}
//Ok, categories are replaced by the posts.
//Let's continue to Aral's function to put the posts in place.
return includePosts($content);
}
//
// Hooks
//
add_action('admin_menu', 'addAdminPage');
add_filter('the_content', 'includeCategoyPosts', 1);
I need help with this inline post and categories plug-in. Originally by Aral Balkan but revised Ronny Welter.
Description: Allows you to include posts or categories in pages. This is simply done by using the syntax [[postid]] or [[cat:catid]].
The post id is working fine, but when I include a catid, it actually just pulls the 10 most recent posts from ALL categories. It's like it's not matching up the catid. Can you please take a look at this function???
Thank you! I really appreciate your help!!
//Added by Ronny Welter
//Get the [[cat:nnn]] tag from the post/page and get all posts in that category
//and add them in place to get them read by the includePosts function.
function includeCategoyPosts($content=''){
// Get the category IDs to include. Category IDs are in the form [[cat:nnn]].
preg_match_all('/(?<=\\[\\[cat\\:)[0-9]+(?=\\]\\])/', $content, $matches, PREG_PATTERN_ORDER);
$numCatMatches = count($matches[0]);
for ($i = 0; $i < $numCatMatches; $i++){//there might be different category includes, let's check them all
//
$allCatPosts=get_posts("numberposts=10&category=".$matches[0][$i]);
$numCatPosts = count($allCatPosts);
$thePostList='';
for ($j = 0; $j < $numCatPosts; $j++){//let's pot all the inline tags in there.
$thePostList .= "[[";
$thePostList .= $allCatPosts[$j]->ID;
$thePostList .= "]] \n";
}
//now let's put this part in the match in case
$content = str_replace("[[cat:".$matches[0][$i]."]]",$thePostList,$content);
}
//Ok, categories are replaced by the posts.
//Let's continue to Aral's function to put the posts in place.
return includePosts($content);
}
//
// Hooks
//
add_action('admin_menu', 'addAdminPage');
add_filter('the_content', 'includeCategoyPosts', 1);