WordPress 카테고리 ID 대 평가 문제
문제
좋아 이것은 조금 복잡합니다. 플러그인을 만들고 있으며 게시물 페이지에서 카테고리 ID를 찾고 싶습니다.
그것은 쉬운 부분입니다.
복잡한 것은 브라우저로 반환되기 전에 전체 페이지를 편집하려면 OB_START ( 'Template_Redirect'Action에서 시작) 내에서 수행하는 것입니다. OB_START 함수에서 충분히 쉽습니다.
ID가 반환 된 상태에서 SQL 필드에 저장된 일부 PHP를 평가하고 싶습니다. OB_START 함수 내 에서이 작업을 수행하려고합니다.
$tui_cifp_insertvalue = tui_cifp_evaluate_html($tui_cifp_insertvalue);
이것은 이것을 부릅니다
function tui_cifp_evaluate_html($string) {
return preg_replace_callback("/(<\?php|<\?|< \?php)(.*?)\?>/si",'EvalBuffer', $string);
}
차례로 전화합니다
function EvalBuffer($string) {
ob_start();
eval("$string[2];");
$ret = ob_get_contents();
ob_end_clean();
return $ret;
}
그리고 내가 평가하려는 PHP는 IS입니다.
<?php tui_findPostThumbIMG([categoryID],100,100,'categoryintro-thumbnail','','',''); ?>
이것은 모두 OB_START 루틴 외부에서 작동하지만 여기서 간단한 PHP조차 작동하지 않습니다. OB_START 루틴 내에서 플러그인이 나오고 빈 페이지가 반환됩니다.
그래서 OB_START가 시작되기 전에 PHP를 평가하고 글로벌 변수를 통해 결과를 전달할 수 있다고 생각했습니다. 그것은 작동하지만,이 시점에서 다음을 사용하기 시작하면 카테고리 ID를 사용할 수 없습니다.
if ( strpos($_SERVER['REQUEST_URI'], 'wp-admin') === false ) {
global $holdvalue;
$tui_cifp_insertvalue = get_option('tui_cifp_insertvalue');
$categories = get_the_category();
$categoryID = $categories[0]->cat_ID;
$tui_cifp_insertvalue = str_replace("[categoryID]", $categoryID, $tui_cifp_insertvalue);
$holdvalue = tui_cifp_evaluate_html($tui_cifp_insertvalue);
add_action('template_redirect','tui_cifp_ob_start'); //
}
OB_START 함수
function tui_cifp_ob_start()
{
ob_start('tui_cifp_templatefilter');
}
알았어 난 그크 럼에 ... 어떤 아이디어?
카테고리 ID에 액세스 할 수 있도록 적시에 실행되는 후크를 찾거나 OB_START 동안 PHP를 평가하는 방법을 해결해야합니다.
오 ... 말해야 할 것 같아요. 내가하고 싶은 것은 WordPress 페이지의 태그를 문자열에 저장 한 다른 정보로 바꾸는 것입니다. 그러나 전체 페이지를 그려면이 작업을 수행 할 수 있어야합니다.
감사합니다 Stephen
추신 : 나는 응답없이 WordPress 포럼에서 이것을 물었다. 크로스 게시에 대해 죄송하지만 조금 필사적입니다.
해결책 2
감사합니다 OIS, 해당 솔루션을 제안 해 주셔서 감사합니다. 그러나 그것은 내가하고있는 것과 똑같은 일을하고 있습니다. 다르게 구조화 된 것 같아요.
그러나 그것은 다른 예비에서 문제를 보게되었습니다.
내가 깨달은 것은 get_the_category()
매개 변수가 필요하고 사용할 수없는 게시물 ID이기 때문에 카테고리를 얻지 못했습니다. 나는 설정을 전면처럼하기 위해 문제를 해결했습니다.
function tui_cifp_ob_start()
{
global $tui_cifp_message, $tui_cifp_div, $wp_query;
if (is_single())
{
$tui_cifp_div = get_option('tui_cifp_div');
if ($tui_cifp_div !== '')
{
$thePostID = $wp_query->post->ID;
$categories = get_the_category($thePostID);
$categoryID = $categories[0]->cat_ID;
$tui_cifp_message = get_option('tui_cifp_message');
$categoryTitle = $categories[0]->cat_name;
$categoryDescription = $categories[0]->category_description;
$tui_cifp_message = str_replace("[categoryID]", $categoryID, $tui_cifp_message);
$tui_cifp_message = str_replace("[categoryTitle]", $categoryTitle, $tui_cifp_message);
$tui_cifp_message = str_replace("[categoryDescription]", $categoryDescription, $tui_cifp_message);
$tui_cifp_message = $tui_cifp_div.$tui_cifp_message;
$tui_cifp_message = tui_cifp_evaluate_html($tui_cifp_message);
}
ob_start('tui_cifp_templatefilter');
}
}
다시 한 번 감사드립니다.
다른 팁
나는 평가하기에 부분적이지 않지만, 이것은 끝에 출력 버퍼링이 있거나없는 상태에서 작동하는 것 같습니다 ...
function tui_findPostThumbIMG()
{
echo "hey hey\n";
}
ob_start();
$categoryID = 10;
$tui_cifp_insertvalue = "<?php tui_findPostThumbIMG([categoryID],100,100,'categoryintro-thumbnail','','',''); ?>";
$tui_cifp_insertvalue = str_replace("[categoryID]", $categoryID, $tui_cifp_insertvalue);
$tui_cifp_insertvalue = tui_cifp_evaluate_html($tui_cifp_insertvalue);
echo $tui_cifp_insertvalue;
ob_end_flush();