2012-02-18 2 views
0

현재 Wordpress 사이트의 내 게시물에 대한 축소판을 표시하는 데 사용하는 "축소판 그림"이라는 사용자 정의 필드가 있습니다. 최근에 새 템플릿을 구입했는데 작동하도록이 코드를 표시 할 수 없습니다. 나는 새로운 템플릿이 대신 배열을 사용하고 있기 때문이라고 생각한다.Wordpress의 미리보기 이미지 용 사용자 정의 필드 사용

현재, 난 그냥 넣어 가지고

<img src="<?php echo get_post_meta($post->ID, Thumbnail, true); ?>"/> 

과 완벽하게 표시합니다. 새 사이트에서 변경해야하는 코드는 다음과 같습니다.

배열을 사용하고있는 것처럼 보입니까? 하지만이 코드를 작동 시키려면 코드에 대해 충분히 알지 못합니다. 나는 위의 마지막 라인의 img 태그에 코드를 넣으려고했지만 꽤 다른 것을 바꿀 필요가 있음을 확신한다.

도와주세요! 감사.

** Ehs4n하고 @ 팀 @ 정보 주셔서 UPDATE * *

감사합니다! 여전히 행운은 없지만 배열을 검사하는 코드 부분을 제거함으로써보다 간단한 접근 방식을 시도하기로 결정했습니다. 나는 가깝다고 느낀다. 여기에 내가 가진 것이있다.

여전히 작은 미리보기 이미지가 표시됩니까? 내가 무엇을 놓치고 있는지 잘 모르겠다. 나는 해당 게시물의 서버에있는 그림에 적절한 링크가있는 Thumbnail이라는 Custom Field를 가지고있다. 나는 그 사진에의 img src에 대한의 실제 URL에 넣어하지만 난 ... 코드에서

<?php echo get_post_meta($post->ID, Thumbnail, true); ?> 

를 넣을 때 그것을 이해하지 못하는 것처럼 때 심지어 올바르게 작동합니다. Firebug는 src가 비어 있다고 알려주고, 반환하지 않는 것처럼 보입니다. Thumbnail Custom Field는 있어야합니다.

다음은 사이트 색인에 카테고리 레이아웃을 표시하는 위젯을 통한 포함 파일 전체입니다.

<?php 
add_action('widgets_init', 'pyre_homepage_1col_load_widgets'); 

function pyre_homepage_1col_load_widgets() 
{ 
    register_widget('Pyre_Homepage_1col_Widget'); 
} 

class Pyre_Homepage_1col_Widget extends WP_Widget { 

    function Pyre_Homepage_1col_Widget() 
    { 
     $widget_ops = array('classname' => 'pyre_homepage_1col', 'description' => 'Homepage 1-column recent posts widget.'); 

     $control_ops = array('id_base' => 'pyre_homepage_1col-widget'); 

     $this->WP_Widget('pyre_homepage_1col-widget', 'Avenue Theme: Home 1-column', $widget_ops, $control_ops); 
    } 

    function widget($args, $instance) 
    { 
     extract($args); 

     $title = $instance['title']; 
     $post_type = 'all'; 
     $categories = $instance['categories']; 
     $posts = $instance['posts']; 
     $images = true; 
     $rating = true; 
     $show_excerpt = isset($instance['show_excerpt']) ? 'true' : 'false'; 

     echo $before_widget; 
     ?> 

     <?php 
     $post_types = get_post_types(); 
     unset($post_types['page'], $post_types['attachment'], $post_types['revision'], $post_types['nav_menu_item']); 

     if($post_type == 'all') { 
      $post_type_array = $post_types; 
     } else { 
      $post_type_array = $post_type; 
     } 
     ?> 

     <div class="block full"> 

      <h3><a href="<?php echo get_category_link($categories); ?>"><?php echo $title; ?></a> <span class="arrows">&raquo;</span></h3> 

      <?php 
      $recent_posts = new WP_Query(array(
       'showposts' => $posts, 
       'cat' => $categories, 
      )); 
      ?> 
      <?php 
      $big_count = round($posts/4); 
      if(!$big_count) { $big_count = 1; } 
      ?> 
      <?php $counter = 1; while($recent_posts->have_posts()): $recent_posts->the_post(); ?> 
      <?php 
      if(has_post_format('video') || has_post_format('audio') || has_post_format('gallery')) { 
       $icon = '<span class="' . get_post_format($post->ID) . '-icon"></span>'; 
      } else { 
       $icon = ''; 
      } 
      ?> 
      <?php if($counter <= $big_count): ?> 
      <?php if($counter == $big_count) { $last = 'block-item-big-last'; } else { $last = ''; }?> 

     <!-- Movies Category --> 
     <?php if (in_category('movies')): ?> 
     <div class="block-item-big-Movies <?php echo $last; ?>"> 
       <div class="block-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?> movie review'><img src="<?php echo get_post_meta($post->ID, Thumbnail, true); ?>"/></a><?php echo $icon; ?></div> 
       <h2><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?> movie review'><?php the_title(); ?></a></h2> 
       <span class="block-meta"><?php the_time('F j, Y'); ?>, <?php comments_popup_link(); ?></span> 
       <?php if($show_excerpt == 'true'): ?><p><?php echo string_limit_words(get_the_excerpt(), 15); ?> ...</p><?php endif; ?> 
      </div> 
     <!-- END Movies Category --> 
     <!-- Music Category --> 
     <?php elseif (in_category('music')): ?> 
     <div class="block-item-big <?php echo $last; ?>"> 
       <?php if($images && has_post_thumbnail()): ?> 
       <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'widget-image'); ?> 
       <div class="block-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" width='290' height='160' /></a><?php echo $icon; ?></div> 
       <?php else: ?> 
       <div class="block-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php bloginfo('template_directory'); ?>/images/thumbnail.png&w=290&h=160" alt="<?php the_title(); ?>" width='290' height='160' /></a><?php echo $icon; ?></div> 
       <?php endif; ?> 
       <h2><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_title(); ?></a></h2> 
       <span class="block-meta"><?php the_time('F j, Y'); ?>, <?php comments_popup_link(); ?></span> 
       <?php if($show_excerpt == 'true'): ?><p><?php echo string_limit_words(get_the_excerpt(), 15); ?> ...</p><?php endif; ?> 
      </div> 
     <!-- END Music Category --> 
     <!-- Else Default Display --> 
     <?php else: ?> 
     <div class="block-item-big <?php echo $last; ?>"> 
       <?php if($images && has_post_thumbnail()): ?> 
       <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'widget-image'); ?> 
       <div class="block-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" width='290' height='160' /></a><?php echo $icon; ?></div> 
       <?php else: ?> 
       <div class="block-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php bloginfo('template_directory'); ?>/images/thumbnail.png&w=290&h=160" alt="<?php the_title(); ?>" width='290' height='160' /></a><?php echo $icon; ?></div> 
       <?php endif; ?> 
       <h2>MUSIC<a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_title(); ?></a></h2> 
       <span class="block-meta"><?php the_time('F j, Y'); ?>, <?php comments_popup_link(); ?></span> 
       <?php if($show_excerpt == 'true'): ?><p><?php echo string_limit_words(get_the_excerpt(), 15); ?> ...</p><?php endif; ?> 
      </div> 
     <!-- END Normal Display --> 
      <?php endif; ?> 


      <?php else: ?> 
      <div class="block-item-small"> 
       <?php if($images && has_post_thumbnail()): ?> 
       <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'widget-image-thumb'); ?> 
       <div class="block-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" width='50' height='50' /></a><?php echo $icon; ?></div> 
       <?php else: ?> 
       <div class="block-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php bloginfo('template_directory'); ?>/images/thumbnail.png&w=50&h=50" alt="<?php the_title(); ?>" width='50' height='50' /></a><?php echo $icon; ?></div> 
       <?php endif; ?> 
       <h2><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_title(); ?></a></h2> 
       <span class="block-meta"><?php the_time('F j, Y'); ?>, <?php comments_popup_link(); ?></span> 
      </div> 
      <?php endif; ?> 
      <?php $counter++; endwhile; ?> 

     </div> 

     <?php 
     echo $after_widget; 
    } 

    function update($new_instance, $old_instance) 
    { 
     $instance = $old_instance; 

     $instance['title'] = $new_instance['title']; 
     $instance['post_type'] = 'all'; 
     $instance['categories'] = $new_instance['categories']; 
     $instance['posts'] = $new_instance['posts']; 
     $instance['show_images'] = true; 
     $instance['show_rating'] = true; 
     $instance['show_excerpt'] = $new_instance['show_excerpt']; 

     return $instance; 
    } 

    function form($instance) 
    { 
     $defaults = array('title' => 'Recent Posts', 'post_type' => 'all', 'categories' => 'all', 'posts' => 4, 'show_excerpt' => null); 
     $instance = wp_parse_args((array) $instance, $defaults); ?> 
     <p> 
      <label for="<?php echo $this->get_field_id('title'); ?>">Title:</label> 
      <input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" /> 
     </p> 

     <p> 
      <label for="<?php echo $this->get_field_id('categories'); ?>">Filter by Category:</label> 
      <select id="<?php echo $this->get_field_id('categories'); ?>" name="<?php echo $this->get_field_name('categories'); ?>" class="widefat categories" style="width:100%;"> 
       <option value='all' <?php if ('all' == $instance['categories']) echo 'selected="selected"'; ?>>all categories</option> 
       <?php $categories = get_categories('hide_empty=0&depth=1&type=post'); ?> 
       <?php foreach($categories as $category) { ?> 
       <option value='<?php echo $category->term_id; ?>' <?php if ($category->term_id == $instance['categories']) echo 'selected="selected"'; ?>><?php echo $category->cat_name; ?></option> 
       <?php } ?> 
      </select> 
     </p> 

     <p> 
      <label for="<?php echo $this->get_field_id('posts'); ?>">Number of posts:</label> 
      <input class="widefat" style="width: 30px;" id="<?php echo $this->get_field_id('posts'); ?>" name="<?php echo $this->get_field_name('posts'); ?>" value="<?php echo $instance['posts']; ?>" /> 
     </p> 

     <p> 
      <input class="checkbox" type="checkbox" <?php checked($instance['show_excerpt'], 'on'); ?> id="<?php echo $this->get_field_id('show_excerpt'); ?>" name="<?php echo $this->get_field_name('show_excerpt'); ?>" /> 
      <label for="<?php echo $this->get_field_id('show_excerpt'); ?>">Show excerpt</label> 
     </p> 
    <?php } 
} 
?> 

답변

0

이미지가 배열인지 확인하려면 print_r($image)을 던집니다. image[0]을 사용하면 어떤 결과가 나타 납니까?

+0

죄송합니다. print_r의 구문에 익숙하지 않지만 실제로 축소판이라는 사용자 지정 필드를 전달하려고 배열을 찾지 않도록 코드가 변경되었습니다. 원래 질문을 확인하고 업데이트했습니다. –

+0

'print_r'은 쉽고 좋아할 것입니다. 'print_r ($ var)'라고 치면'var'의 내용이 타입에 관계없이 멋지게 표시됩니다. 배열과 객체가 확장되고 다른 모든 것은 정상적으로 보여집니다. – Tim

0

축소판 경로를 저장하기 위해 사용자 지정 필드를 사용하는 경우 템플릿에 사용 된 코드와 혼동하는 이유는 무엇입니까?

당신은 여전히 ​​템플릿의 코드를 찾고 이미지를

<?php echo get_post_meta($post->ID, Thumbnail, true); ?> 

를 얻기 위해 기존의 코드를 사용할 수 있습니다, 그것은 워드 프레스의 기능 세 가지 매개 변수를 wp_get_attachment_image_src(), $attachement_id를 사용 - 해당 미디어의 ID를 전달하는, $size - 미디어 크기/이미지 크기 &을 표시합니다. $icon (선택 사항) 첨부 파일을 나타내는 아이콘이 표시됩니다. 여기에 이미지 세트의 $ attachment_id를 게시물 미리보기 이미지의 크기와 크기로 전달합니다. 이 함수는 url, width 및 height가 포함 된 배열을 반환하며, 첫 번째는 url이므로 $image[0]을 사용하면 이미지 URL이 반환됩니다.

이미지가 여전히 표시되지 않는 경우 이미지를 게시 된 미리보기 이미지로 첨부했는지 확인하고 $images 변수가 절에 true을 반환하는지 확인해야합니다.

+0

통찰력을 가져 주셔서 감사합니다. 그 의미에서 이미지를 첨부하지 않기 때문에 wp_get_attachment_img 부분을 제거하기로 결정 했습니까? 새 게시물 내에서 업로드 기능을 통해 업로드하지만, 서버에서 제공 한 링크 URL을 복사 한 다음 해당 URL을 미리보기라는 맞춤 필드에 붙여 넣습니다. 어쨌든 내 원래의 질문을 체크 아웃, 나는 그것을 업데이 트했습니다. –

+0

그냥 오타입니다. 이어야합니다. ID, 'Thumbnail', true); ?> 대신 ID, Thumbnail, true); ?> 미리보기 이미지 주위의 따옴표에 주목하십시오. – Ehs4n

관련 문제