0

我一直在关注许多关于使用 quicksand.js 进行过滤动画的作品集的教程。在函数中,我可以创建带有 slug 的过滤器(类别)。经过无数小时的阅读,我无法弄清楚如何仅显示某个过滤器的缩略图。

我已经包括了我的投资组合的部分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。但是将其应用于我已经使用的东西是我完全迷失的地方。

提前致谢。

我的索引.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' ); 
4

3 回答 3

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]; 
?>
于 2013-07-10T23:10:07.800 回答
0

我找到了一个解决方案:

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

仅显示我的过滤项目,其名称为特色。

于 2013-07-12T22:53:27.097 回答
0

这是我用来获取附加图像的完整图像和拇指的代码:

  $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' );
于 2013-07-12T22:55:11.633 回答