2013-07-10 52 views
0

我一直在關注使用quicksand.js做過濾器動畫的投資組合許多教程。在函數中,我可以用slu create創建過濾器(類別)。經過無盡的閱讀後,我無法弄清楚如何只顯示某個過濾器的縮略圖。WordPress的組合頁面只顯示某些過濾器的圖片

我已經從我functions.php

包括投資組合的部分,我知道這是一個很大的代碼,但是這是一個不得已而爲之。我無法得到它的工作,所以我希望一些PHP/WordPress的大師可能會指出我錯過的東西。

通過它閱讀了,我也設法通過使用拉出剛剛發佈的「特色」的特色照片:

<?php 
$args = array(
    'post_type' => 'portfolio', 
    'tax_query' => array(
     array(
      'taxonomy' => 'filter', 
      'field' => 'slug', 
      'terms' => 'featured' 
     ) 
    ) 
); 
$query = new WP_Query($args); 
?> 

然而,這只是翻出圖像和它的標題,沒有格式化我需要HTML。但將此應用到我已經使用的地方,就是我完全失去了自己的地方。

在此先感謝。

我的index.php

h2>Featured Work</h2> 



<ul id="image_gallery" class="group index_gallery filterable-grid"> 
<?php 

    // Query Out Database 
    $wpbp = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' =>'9')); 
?> 

<?php 

$terms = get_terms("filter"); 
$count = count($terms); 
if ($count > 0){ 
    echo "<ul>"; 
    foreach ($terms as $term) { 
     echo "<li>" . $term->name . "</li>"; 

    } 
    echo "</ul>"; 
} 
?> 

<?php 
    // Begin The Loop 
    if ($wpbp->have_posts()) : while ($wpbp->have_posts()) : $wpbp->the_post(); 
?> 

<?php 
    // Get The Taxonomy 'Filter' Categories 
    $terms = get_the_terms(get_the_ID(), 'filter'); 
?> 

<?php 
$large_image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'fullsize', false, ''); 
$large_image = $large_image[0]; 
?> 

     <?php 
      //Apply a data-id for unique indentity, 
      //and loop through the taxonomy and assign the terms to the portfolio item to a data-type, 
      // which will be referenced when writing our Quicksand Script 
     ?> 
<li class="gallery_image" data-id="id-<?php echo $count; ?>" data-type="<?php foreach ($terms as $term) { echo strtolower(preg_replace('/\s+/', '-', $term->name)). ' '; } ?>"> 
     <?php 
      // Check if wordpress supports featured images, and if so output the thumbnail 
      if ((function_exists('has_post_thumbnail')) && (has_post_thumbnail())) : 
     ?> 
      <?php // Output the featured image ?> 
      <a rel="prettyPhoto[gallery]" class="zoom" href="<?php echo $large_image ?>"> 
       <img class="mag" src="<?php bloginfo('template_url'); ?>/imgs/mag.png"/><div class="thumb_bg"></div><?php the_post_thumbnail('portfolio'); ?> 
      </a>          

     <?php endif; ?> 
     <!--<?php // Output the title of each portfolio item ?> 
     <p><a href="<?php the_permalink(); ?>"><?php echo get_the_title(); ?></a></p>--> 
</li> 
<?php $count++; // Increase the count by 1 ?>  
<?php endwhile; endif; // END the Wordpress Loop ?> 
<?php wp_reset_query(); // Reset the Query Loop?> 
</ul> 

<div class="gallery_control"> 
    <a href="<?php echo home_url(); ?>/portfolio/" class="gallery-btn artwork"><span class="icon-search"></span>View more</a> 
</div> 
<?php 
$taxonomy = 'filter'; 
    $terms = get_terms($taxonomy, ''); 
    if ($terms) { 
    foreach($terms as $term) { 
     echo '<p>' . '<a href="' . esc_attr(get_term_link($term, $taxonomy)) . '" title="' . sprintf(__("View all posts in %s"), $term->name) . '" ' . '>' . $term->name.'</a> has ' . $term->count . ' post(s). </p> '; 
    } 
    } 
?> 

投資組合的運作:

// function: post_type BEGIN 
     function post_type() 
     { 
     $labels = array( 
      'name' => __('Portfolio'), 
      'singular_name' => __('Portfolio'), 
      'rewrite' => array( 
       'slug' => __('portfolio') 
      ), 
      'add_new' => _x('Add Item', 'portfolio'), 
      'edit_item' => __('Edit Portfolio Item'), 
      'new_item' => __('New Portfolio Item'), 
      'view_item' => __('View Portfolio'), 
      'search_items' => __('Search Portfolio'), 
      'not_found' => __('No Portfolio Items Found'), 
      'not_found_in_trash' => __('No Portfolio Items Found In Trash'), 
      'parent_item_colon' => '' 
     ); 
      $args = array( 
      'labels' => $labels, 
      'public' => true, 
      'publicly_queryable' => true, 
      'show_ui' => true, 
      'query_var' => true, 
      'rewrite' => true, 
      'capability_type' => 'post', 
      'hierarchical' => false, 
      'menu_position' => null, 
      'supports' => array( 
       'title', 
       'editor', 
       'thumbnail' 
      ) 
     ); 

     register_post_type(__('portfolio'), $args); 

    } // function: post_type END 

    // function: portfolio_messages BEGIN 
    function portfolio_messages($messages) 
    { 
     $messages[__('portfolio')] = 
      array( 
       0 => '', 
       1 => sprintf(('Portfolio Updated. <a href="%s">View portfolio</a>'), esc_url(get_permalink($post_ID))), 
       2 => __('Custom Field Updated.'), 
       3 => __('Custom Field Deleted.'), 
       4 => __('Portfolio Updated.'), 
       5 => isset($_GET['revision']) ? sprintf(__('Portfolio Restored To Revision From %s'), wp_post_revision_title((int)$_GET['revision'], false)) : false, 
       6 => sprintf(__('Portfolio Published. <a href="%s">View Portfolio</a>'), esc_url(get_permalink($post_ID))), 
       7 => __('Portfolio Saved.'), 
       8 => sprintf(__('Portfolio Submitted. <a target="_blank" href="%s">Preview Portfolio</a>'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))), 
       9 => sprintf(__('Portfolio Scheduled For: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Portfolio</a>'), date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)), esc_url(get_permalink($post_ID))), 
       10 => sprintf(__('Portfolio Draft Updated. <a target="_blank" href="%s">Preview Portfolio</a>'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))), 
      ); 
     return $messages; 

    } // function: portfolio_messages END 

    // function: portfolio_filter BEGIN 
    function portfolio_filter() 
    { 
     register_taxonomy( 
      __("filter"), 
      array(__("portfolio")), 
      array( 
       "hierarchical" => true, 
       "label" => __("Filter"), 
       "singular_label" => __("Filter"), 
       "rewrite" => array( 
        'slug' => 'filter', 
        'hierarchical' => true 
       ) 
      ) 
     ); 
    } // function: portfolio_filter END 

    add_action('init', 'post_type'); 
    add_action('init', 'portfolio_filter', 0); 
    add_filter('post_updated_messages', 'portfolio_messages'); 

回答

0

我找到了一個解決方案:

<?php 
$args = array(
    'post_type' => 'project', 
    'tax_query' => array(
     array(
      'taxonomy' => 'filter', 
      'field' => 'slug', 
      'terms' => 'featured' 
     ) 
    ) 
); 
$query = new WP_Query($args); 
?> 

只顯示我的過濾項具有特色的名稱。

0

我不知道你在做什麼在這裏,但改變這種

<?php 
$large_image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'fullsize', false, ''); 
$large_image = $large_image[0]; 
?> 

<?php 
$large_images[] = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'fullsize', false, ''); 
$large_image = $large_images[0]; 
?> 
+0

是什麼,如果你不介意我問這個變化呢? – Doidgey

+0

在你的代碼中,你給'$ large_image分配一些值,然後在第二行中,你將同一個變量設置爲同一個變量索引爲0的元素的值。該元素不存在因爲變量不是數組。在我的代碼中,我添加了一個數組變量。 – RST

0

這是我用得到附加的圖像的完整圖像和Thumb代碼:

$args = array(
    'order' => 'ASC', 
    'post_mime_type' => 'image', 
    'post_parent' => $post->ID, 
    'post_status' => null, 
    'post_type' => 'attachment', 

); 

    $upload_dir = wp_upload_dir(); 
    $upload_url = $upload_dir['baseurl']; 


    // Get img data 
    $attachments = get_children($args); 
    $images = array(); 

    // Loop through attached images and get thumb + large img url 
    foreach($attachments as $attachment) { 
    $image_attributes = wp_get_attachment_image_src($attachment->ID, 'thumbnail'); 
    $img['thumb'] = $image_attributes[0]; 
    $image_attributes = wp_get_attachment_image_src($attachment->ID, 'large'); 
    $img['large'] = $image_attributes[0]; 
    array_push($images,$img); 
    } 

    // Get the image that you have set as the featured image in the post 
    $featured_img = wp_get_attachment_url(get_post_thumbnail_id($post->ID)); 
    $featured_img_thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail'); 
相關問題