如何在Wordpress中显示投资组合图片?

问题描述:

我在我的主题中有一个可排序的投资组合。我想在其中显示投资组合标签图片。我找到了this插件。但我无法很好地定制它。如何在Wordpress中显示投资组合图片?

因为我不想显示帖子的类别图像,我想在索引中显示投资组合的标签图像。我想这个screenshot很明显,我想在索引中将这些图片称为屏幕截图。

这里是我的主题代码:

<?php 

$query = ff_get_query_for_section(); 
if(!ff_archive_layout_type_test('portfolio', basename(__FILE__))){ 
    return false; 
} 

ff_require_portfolio_archive_helper_before(); 


$numberOfPosts = ($query->get('number-of-posts')) ; 

?> 
      <!-- Filter Section --> 
      <section <?php ff_print_section_attributes($query->get('section-options-sortable section-options'), 'small-section'); //class="small-section bg-gray-lighter"?>> 
       <div class="container relative"> 
        <!-- Works Filter --> 
        <div class="container align-center"> 
         <div class="works-filter mb-0"> 

         <a href="#" class="filter active" data-filter="*"><?php $query->printText('trans-all'); ?></a> 
<?php 
$portfolioTagsArray = array(); 
$portfolioTagsString = ''; 
$postCounter = 0; 
if (have_posts()) { 
    while (have_posts()) { 
     the_post(); 
     $postCounter++; 
      $t = wp_get_post_terms($post->ID, 'ff-portfolio-tag'); 
      if(!empty($t)) foreach ($t as $onePortfolioTag) { 

       if(!isset($portfolioTagsArray[ $onePortfolioTag->slug ])) { 
        $portfolioTagsString .= '<a href="#" class="filter" data-filter=".tag-'.esc_attr($onePortfolioTag->term_id).'">'.ff_wp_kses($onePortfolioTag->name).'</a>'; 
       } 

       $portfolioTagsArray[ $onePortfolioTag->slug ] = $onePortfolioTag; 
      } 
      if($numberOfPosts > 0 && $postCounter >= $numberOfPosts) { 
       break; 
      } 

     } 
    } 

    // Escaped HTML with tags 
    echo $portfolioTagsString; 

?> 
         </div> 
        </div> 
        <!-- End Works Filter --> 

       </div> 
      </section> 
      <!-- End Filter Section --> 


      <!-- Section --> 
      <section <?php ff_print_section_attributes($query->get('section-options'), 'page-section');//class="page-section" id="portfolio"?>> 
       <div class="container relative"> 

        <!-- Works Grid --> 
        <ul class="works-grid work-grid-3 hover-color clearfix" id="work-grid"> 

<?php 
$fwc = ffContainer::getInstance(); 
$postMeta = $fwc->getDataStorageFactory()->createDataStorageWPPostMetas(); 
    rewind_posts(); 
    $postCounter = 0; 
    if (have_posts()) { 
     while (have_posts()) { 
      the_post(); 
      $postCounter++; 
      $currentPostId = $post->ID; 

      require dirname(__FILE__).'/portfolio-archive-one-post.php'; 

      if($numberOfPosts > 0 && $postCounter >= $numberOfPosts ) { 
       break; 
      } 
     } 
    } 
?> 
        </ul> 
        <!-- End Works Grid --> 

        <?php 
        if($query->get('show-pagination')) { 
         ff_bigstream_print_pagination(); 
        } 
        ?> 

       </div> 
      </section> 

      <!-- End Section --> 
<?php 
ff_require_portfolio_archive_helper_after(); 

,我试图在这个文件中添加以下代码:

<?php foreach (wp_get_post_terms($post->ID, 'ff-portfolio-tag') as $cat) : ?> 

<?php z_taxonomy_image($cat->term_id); ?> 
<a href="<?php echo get_term_link($cat->term_id, 'ff-portfolio-tag'); ?>"><?php echo $cat->name; ?></a> 

<?php endforeach; ?> 

但我不能全成。如果你有帮助,我会很感激。非常感谢。

get_the_tags()一个对象数组,每个标签分配给该帖子的一个对象。如果在The Loop中使用此函数,则不需要传递任何ID。 此功能不显示任何内容;你应该访问对象,然后回显或以其他方式使用所需的成员变量。

The following example displays the tag name of each tag assigned to the post (this is like using the_tags() , but without linking each tag to the tag view, and using spaces instead of commas):

<?php 
$posttags = get_the_tags(); 
if ($posttags) { 
    foreach($posttags as $tag) { 
    echo $tag->name . ' '; 
    } 
} 
?> 
+0

我不很了解。我考虑你的方式做了这个修改,但它是错误的。 '? TAG_ID);> name; ?> ' @? HassanALi – Katzenliebe

+0

get_the_tags($ post_id)用这种方式你会得到结果 –

+0

对不起,它不起作用。 – Katzenliebe