inflearn logo
강의

講義

知識共有

WordPress(WordPress)完全征服

25강 - Post meta 부분 질문입니다.

304

cjh30989499

投稿した質問数 1

0

25강 - Post meta 부분 질문입니다.

아래 그림처럼 default, alt 부분이 이상 있다는 안내가 나옵니다.

현재 이상 있는 것으로 추정 되는 부분이고, 그 아래는 index.php 파일 전문 올렸습니다. 파일 첨부가 안되어서 이렇게 질문 드립니다. 감사합니다.

<?php echo get_avatar(get_the_author_meta('ID'), '18', $default, $alt, array('class' => array())); ?>

 

 

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My First Website</title>
  <?php wp_head(); ?>
</head>

<body <?php body_class() ?>>
  <div class="container">
    <div class="section-content">
      <?php
      if (have_posts()) { ?>
        <main>
          <?php while (have_posts()) {
            the_post(); ?>

            <article id="post">
              <div class="post-header">
                <h4>
                  <?php if (!is_single()) { ?>
                    <a href="<?php the_permalink(); ?>">
                      <?php the_title(); ?>
                    </a>
                  <?php } else { ?>
                    <?php the_title(); ?>
                  <?php } ?>
                </h4>
                <div class="post-meta">
                  <?php echo get_avatar(get_the_author_meta('ID'), '18', $default, $alt, array('class' => array())); ?>
                  <span class="post-author"><?php echo get_the_author_meta('display_name'); ?></span> |
                  <span class="post-time"><?php the_time('Y-m-d'); ?></span> |
                  Cat: <?php the_category(); ?> |
                  Tag: <?php the_tags(); ?>


                </div>
              </div>

              <?php if (has_post_thumbnail()) { ?>
                <div class="post-body">
                  <?php if (!is_single()) { ?>
                    <a href="<?php the_permalink() ?>" class="post-featured">
                      <img src="<?php echo esc_url(wp_get_attachment_image_src(get_post_thumbnail_id(($post->ID)), 'medium')[0]); ?> " alt="<?php echo get_post_meta(get_post_thumbnail_id($post->ID), '_wp_attachment_image_alt', true); ?>" class="post-featured-image">
                    </a>
                  <?php } else { ?>
                    <div class="post-featured">
                      <img src="<?php echo esc_url(wp_get_attachment_image_src(get_post_thumbnail_id(($post->ID)), 'medium')[0]); ?> " alt="<?php echo get_post_meta(get_post_thumbnail_id($post->ID), '_wp_attachment_image_alt', true); ?>" class="post-featured-image">
                    </div>
                  <?php } ?>


                  <div class="post-text-with-featured">
                    <?php
                    if (is_home()) {
                      // the_excerpt();
                      if (has_excerpt()) {
                        echo get_the_excerpt();
                      } else {
                        echo wp_trim_words(get_the_content(), 30);
                      }
                    } elseif (is_single()) {
                      the_content();
                    }
                    ?>
                  </div>
                </div>
              <?php } else { ?>
                <div class="post-body">
                  <div class="post-text-without-featured">
                    <?php
                    if (is_home()) {
                      if (has_excerpt()) {
                        echo get_the_excerpt();
                      } else {
                        echo wp_trim_words(get_the_content(), 30);
                      }
                    } elseif (is_single()) {
                      the_content();
                    }
                    ?>
                  </div>
                </div>
              <?php } ?>

            </article>

          <?php
          } ?>
        </main>

        <div class="pagination">
          <?php
          // next_posts_link('&raquo; Older');
          // previous_posts_link('Newer &raquo;');
          // posts_nav_link();
          // echo paginate_links(); //prior to WP 4.1
          the_posts_pagination(); //For WP 4.1+
          ?> </div>

      <?php } else {
        echo '<p>Sorry, no posts.</p>';
      }      ?>
    </div>
  </div>

  <?php wp_footer(); ?>
</body>

</html>

wordpress

回答 1

0

Self-coding

안녕하세요.

 

예전에는 아바타 이미지 함수에서 변수 $default와

$alt 만 넣어도 됐었는데요,

언제부터인가는 $default ='',

$alt = '' 를 넣어주셔야 합니다. (그냥 작은 따옴표 2개)

 

참고 문헌:

https://developer.wordpress.org/reference/functions/get_avatar/

아래에 있는 예제를 참조해주세요.

 

예제 코드는,

echo get_avatar( get_the_author_meta( 'ID' ), $size = '18', $default = '', $alt = '', $args = array( 'class' => 'class_name_whatever_you_want' ) );

 

한번 해 보시고, 안 되면 다시 문의주세요.

뉴스페이퍼 싱글템플릿 디자인 관련 상담 요청

0

27

2

폰트 업로드 단계에 설치해야할 플러그인이 현재 없습니다

0

49

2

FASTCOMET SSL 설정 방법 문의

0

54

2

엘리멘터

0

48

2

워드프레스로 웹사이트를 만드는 경우애도 HTML, CSS 코드를 직접 작성해야 하나요? 프로젝트 1번을 거의 다 들었는데 대부분 작업이 CSS코딩과 HTML코딩 같아서요

0

144

2

블로그 페이지 게시물 페이지 오류

0

179

2

71강 gallery-title 누락

0

162

2

vscode

0

132

1

22강 요약문

0

166

2

bootstrap_5_wp_nav_menu_walker()드랍다운 방식을 메가메뉴로 설정할 수 있나요?

0

178

1

single 포스트글에서 페이지의 Top-Banner이미지 불러오는 법

0

199

2

single 포스트글에서도 페이지의 $theParent를 가져오는 법

0

177

1

강의 프로젝트 연습용 세컨드 프로젝트 만드는 법

0

229

1

16강 브라우저에서 출력되는 var_dump() 데이터 자동정렬 툴

0

299

2

start site

0

264

1

wordpress에서 js파일 모듈작업

0

308

2

$post가 정의되어있지 않다는 메시지가 나오네요.

0

364

2

관리자페이지 로그인이 안됩니다!

0

459

2

프로젝트1에서 게시글타이틀부분이 ㅜㅜ 갑자기 왜이렇게되는지 모르겠습니다

0

600

4

길이가 서로 틀려요

0

314

1

백그라운드 이미지ㅠㅠ

0

411

1

pagination 다음페이지에서 오류가 나는 경우

0

720

1

프로젝트 내에 있는 php파일을 a태그로 연결시킬 수 있을까요?

0

389

1

프로젝트4-마이그레이션 플러그인이 없어요..

0

304

1