2013-07-15 6 views
1

작업 작동하지 the_content : (고급 사용자 정의 필드를 통해) 내가 (플러그인 사용자 정의 포스트 UI를 통해) 사용자 정의 포스트 유형을 추가 한워드 프레스 사용자 정의 워드 프레스 사용자 정의 포스트 유형 테마 만들 사용자 정의 포스트 유형

및 사용자 정의 필드를 . 커스텀 포스트가 생성 된 새로운 템플릿 페이지에 올바르게 표시됩니다 (single-custom.php). 개별 맞춤 게시물은 내가 원하는대로 정확하게 표시됩니다.

그러나 문제는 홈페이지에서만 제목이 표시되고 있다는 것입니다.

내가했던 무엇 :

add_filter('pre_get_posts', 'my_get_posts'); 

function my_get_posts($query) { 

if ((is_home() && $query->is_main_query()) || is_feed()) 
    $query->set('post_type', array('post', 'custom')); 

return $query; 
: 나는 새 게시물의 유형을 허용하려면 다음 코드를 추가 한

1)

은 functions.php를 통해 홈페이지/블로그 피드에 피드에 들어갔습니다 할

: 나는 정의의 콘텐츠 페이지의 내용 custom.php를 생성하고 인덱스 루프를 수정했습니다

2)이 그 템플릿을 호출 할 Justin Tadlock

감사합니다

내 홈페이지에는 여전히 내 맞춤 게시물의 제목 만 표시되며, 전체 내용은 표시하지 않습니다. 문제는 content-custom.php에있는 the_content의 호출과 관련이 있습니다. 그러나 저는 여전히 WordPress에 익숙해 져 있으므로이 문제를 찾을 수 없습니다.

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 
<header class="entry-header"> 
      //The title below is displayed correctly 
    <h1 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h1> 

</header><!-- .entry-header --> 

    // The problem begins below. The entry-content div is created but is empty and is not pulling any content from the custom post through the_content call. 

<div class="entry-content"> 
    <?php the_content(); ?> 
</div><!-- .entry-content --> 

답변

1

나는 당신이 언급 한 플러그인에 익숙하지 않은,하지만 사용자 정의 포스트 유형이 정말 "내용"필드가 있는지 확인 : 다음과 같은 내용 custom.php에 대한 관련 코드입니다.

은 "내용은"사용자 정의 필드 인 경우 당신은 내가 비슷한 문제가 있었과는 템플릿에 다음을 추가하여 고정

get_post_meta($post->ID, 'field name', true); 

그것을 얻을 수있는. 당신은 또한 당신의 내용 custom.php에 추가 시도 할 수 있습니다 :

<?php wp_reset_postdata(); ?> 
0

일부 후 관련 데이터가 the_content(), 또는 숫자 ID를 통해 같은 포스트 내용과 같은 기본으로 get_posts, 사용할 수 없습니다. $가 인수로서 배열을 게시와 함께이는 내부 함수 setup_postdata()를 호출하여 해결 :

<?php 
$args = array('posts_per_page' => 3); 
$lastposts = get_posts($args); 
foreach ($lastposts as $post) : 
    setup_postdata($post); ?> 
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
    <?php the_content(); ?> 
<?php endforeach; 
wp_reset_postdata(); 
?> 

참조 Access all post data

관련 문제