programing

apply_filter('the_content')가 아무것도 출력되지 않는 이유는 무엇입니까?

codeshow 2023. 10. 19. 22:54
반응형

apply_filter('the_content')가 아무것도 출력되지 않는 이유는 무엇입니까?

저는 워드프레스를 통해 $post->post_content를 포맷된 텍스트로 출력하도록 하기 위해 수많은 php 조합을 시도했습니다(원시 포맷과는 반대로).echo $post->post_content저를 줍니다.이 조합이 가장 유망한 것 같지만, 아무것도 나오지 않고 있습니다.무슨 생각 있어요?

(다음 줄입니다.<?php $content = apply_filters('the_content', $s->post_content); ?>)

<?php query_posts('orderby=menu_order&order=asc&posts_per_page=-1&post_type=page&post_parent='.$post->ID); if(have_posts()) { while(have_posts()) { the_post(); ?>
    <div class="page">
        <?php
            global $wpdb;
            $subs = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent='$post->ID' AND post_type='page' AND post_status='publish'");
            if($subs) {
        ?>
        <div class="navi"></div>
        <a class="naviNext"><img src="<?php bloginfo('template_url'); ?>/images/navi-next.png" alt="" /></a>
        <div class="scrollable">
            <div class="items">
                <?php foreach($subs as $s) { ?>
                <div class="item">
                    <h2><?php echo $s->post_title; ?></h2>
                    <?php $content = apply_filters('the_content', $s->post_content); echo $content; ?>
                </div>
                <?php } ?>
            </div>
        </div>
        <?php } else { the_content(); } ?>
    </div>
    <?php } } wp_reset_query(); ?>

메인 '포맷'을 콘텐츠 본문에 적용하는 기능은 wpautop()으로 알고 있습니다.이 함수는 워드 프레스를 통해 'the_content'에 연결되어야 합니다.이 기능은 (예를 들어 코드를 엉망으로 만드는 것과 같은) 성가신 일들을 하지만, 필터 스택에서 그것을 푸는 많은 플러그인들이 있습니다.회선 교체를 시도해 보십시오.

<?php $content = apply_filters('the_content', $s->post_content); echo $content; ?>

와 함께

<?php $content = wpautop($s->post_content); echo $content; ?>

그게 도움이 된다면 아마도 어딘가에서 wpautop가 풀리는 문제가 있을 것입니다.

저도 같은 문제가 있었습니다.내 테마에 필터링된 기능이 있는 것으로 드러났습니다.the content, 버그가 있어서 필터가 빈 문자열을 반환하도록 했습니다.

그래서 당신의 테마와 플러그인에서 필터링하는 기능을 확인합니다.the_content. 예를 들어 Subravity Text 2에서는 ++로 "파일에서 찾기"를 빠르게 수행하여 가능한 범인을 찾을 수 있습니다.

man86,

$wpdb->get_results()를 통해 게시물 데이터를 받고 있습니다.데이터가 원시 상태로 반환되므로 _content()와 같은 일반적인 게시 기능을 사용하려면 "준비"해야 합니다(이미 포맷된 콘텐츠를 원하는 대로 반환합니다).

이것을 시도해 보는 것은 어떨까요? (코드에 대한 의견 참조):

<?php query_posts('orderby=menu_order&order=asc&posts_per_page=-1&post_type=page&post_parent='.$post->ID); 

if(have_posts()) { while(have_posts()) { the_post(); ?>
<div class="page">
    <?php
        global $wpdb;
        $subs = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent='$post->ID' AND post_type='page' AND post_status='publish'");
        if($subs) { ?>
    <div class="navi"></div>
    <a class="naviNext"><img src="<?php bloginfo('template_url'); ?>/images/navi-next.png" alt="" /></a>
    <div class="scrollable">
        <div class="items">
            <?php foreach($subs as $post) { // <-- changed $s to $post
            setup_postdata($post) // <--use setup_postdata to prepare post
             ?>
            <div class="item">
                <h2><?php the_title(); // <-- use "the_title() now that the data has been prepared ?></h2>
                <?php the_content(); // <-- use "the_content() now that the data has been prepared ?>
            </div>
            <?php } ?>
        </div>
    </div>
    <?php } else { the_content(); } ?>
</div>
<?php } } wp_reset_query(); ?>

참조: http://codex.wordpress.org/Class_Reference/wpdb#Examples_5 ("사용자 5가 초안에 대한 모든 정보 가져오기")

감사합니다, 도움이 되었으면 좋겠네요!

Vq.

할 필요가 있습니다.echo의 결과apply_filters호출:

<?php echo apply_filters('the_content', $s->post_content); ?>

또는 코드화된 것처럼:

<?php 
    $content = apply_filters('the_content', $s->post_content); 
    echo $content;
?>

너무 기본적인 내용이라면 죄송합니다. 내용을 반복하면 도움이 될 수 있습니다.

<?php
$content = apply_filters('the_content', $s->post_content);
echo $content;
?>

필터는 어떻게 추가하는 겁니까?$content를 받을 함수를 지정하는 add_filter를 사용할 수 있습니다.이 기능을 통해 필요한 모든 필터링을 수행할 수 있습니다.

http://codex.wordpress.org/Plugin_API#Create_a_Filter_Function

음.. 왠지 윗줄과 아랫줄을 제거했을 때 표시할 컨텐츠를 얻을 수 있습니다.

query_posts 호출이 문제이지 apply_filters() 호출이 문제가 아닙니다.

apply_filters() 사용 여부에 따라 표시 모드를 전환할 수 있습니다.당신이 원하는 것이라고 생각합니다.

언급URL : https://stackoverflow.com/questions/3602941/why-isnt-apply-filterthe-content-outputting-anything

반응형