2017-12-28 16 views
0

콘텐츠가 표시되지 않습니다. 나는 여러 번이 문서를 읽고 읽었습니다. 나는 심지어 다른 개발자들에게 코드를보고 확인해달라고 요청하기도했다.ACF 유연한 콘텐츠 - 작성자 페이지에서 데이터를 가져올 때 아무 것도 표시되지 않습니다.

작성자 페이지에 있어야합니다. 나는 사용자 정의 게시 유형, 페이지 등에서 이것을 테스트 해 보았습니다. 그러나이 정보는 작성자 페이지에서 가져와야합니다. The author page location

그리고 아래에있는 내 코드입니다 : enter image description here 여기

이 필드가 표시되는 곳입니다 : 여기

내 필드입니다. 항상 아무 것도 표시하지 않습니다. 왜 그런가요? 나는 버전 5.6.1

```

// check if the flexible content field has rows of data 

if(have_rows('social_media')): 

    // loop through the rows of data 
    while (have_rows('social_media')) : the_row(); 

     if(get_row_layout() == 'social_media_icons'): 

     echo the_sub_field('media_facebook'); 

     endif; 

    endwhile; 

else : 

    echo "nothing";// no layouts found 

endif; 

?> 

```

+0

while 루프에서 "social_media_icons"의 "social_media"insted를 시도하고 두 번째 인수로 have_rows의 페이지 ID도 전달합니다. –

+0

그 중 하나도 작동하지 않았습니다. 나는 전에도 그것을 시도했다. –

답변

0

나는 그것을 알아 냈습니다.

작성자 페이지입니다. 많은 저자들이 있으며 그들 각각은 독특합니다.

필드를 가져오고 10authors라고 말하면 어떤 필드가 당겨 집니까? 표준 루프는 여기서 작동하지 않습니다.

작성자 ID를 전달해야합니다. user_1.

정적인데, 우리는 그것을 동적으로 만들고 저자 ID를 얻을 수 있습니다. 그러면 그것을 user_ $ id에 연결합니다.

예를 들면 : ID가 지금은 동적이기 때문에이 작동합니다, 우리가 'USER_'에을 연결 한 후 현재 사용자 ID를 얻고있다

$author_id = get_the_author_meta('ID'); 

    while (have_posts()) : the_post(); 

       if(have_rows('social_media','user_'. $author_id)): 

        while (have_rows('social_media', 'user_'. $author_id)) : the_row(); 

         if(get_row_layout() == 'social_media_icons'): ?> 


    <?php endif; ?> 
        <?php endwhile; 

        else : 
         echo 'no content'; 
        endif; 


       endwhile; // End of the loop. 

.

해당 코드는 버전 5.6.5에서 100 % 작동하며 더 잘 작동해야합니다.

0

이 시도가이 라인 the_sub_field ('media_facebook')에서

$page_id = //your page id; 

// check if the flexible content field has rows of data 

if(have_rows('social_media',$page_id)): 

// loop through the rows of data 
while (have_rows('social_media',$page_id)) : the_row($page_id); 

    if(get_row_layout() == 'social_media_icons'): 

    echo the_sub_field('media_facebook'); 

    endif; 

endwhile; 

else : 

echo "nothing";// no layouts found 

endif; 

?> 
+0

그 중 하나가 작동하지 않았다. –

+0

페이지에서 acf 필드를 정의 했습니까? –

+0

많은 페이지를 보았습니다. 음, 저자 페이지와 페이지 연락처를 시도했습니다. –

0

제거 에코;

// check if the flexible content field has rows of data 
    if(have_rows('social_media')): 

     // loop through the rows of data 
     while (have_rows('social_media')) : the_row(); 

      if(get_row_layout() == 'social_media_icons'): 

       the_sub_field('media_facebook'); 

      endif; 

     endwhile; 

    else : 

     echo 'nothing'; // no layouts found 

    endif; 
+0

여전히 작동하지 않습니다. –