在Wordpress中大写投资组合类别字符串

时间:2014-07-10 21:27:58

标签: php wordpress categories capitalize

我试图利用Wordpress组合类别字符串"企业形象"。

我尝试过使用这篇文章:Capitalise every word of a string in PHP?,但没有运气。

网址:http://utopia.gerandeklerk.com/

在主页上,将鼠标悬停在第一个项目组合项目(Steam Africa 2014)上,您会注意到悬停状态,它列出了投资组合类别" Collat​​eral"和#34;企业形象"。客户想要它显示"企业标识",就像在它上面的类别过滤器菜单中一样。

我添加了以下字符串 - 有人可以告诉我哪里出错了吗?

$portfolio_category[] = ucwords(strtolower($term->slug)); // Capitalise Portfolio Category String

以下是portfolio.php

的代码
<div class="filter-container">
  <ul data-drop-content class="filter-list">
  <li><a href="#" data-filter="*">All</a></li>
  <?php
   $terms = get_terms("portfolio_category");
   foreach ( $terms as $term ) {
   echo "<li><a href='#' data-filter='" . "." . strtolower($term->slug) . "'>" . $term->name . "</a></li>";
  };
  ?>
  </ul>
  <a href="#" data-drop-down class="filter-select"><span>| More filters</span> <img src="<?php echo get_template_directory_uri(); ?>/images/down-arrow.png"></a>  

<?php
$desired_width = 440;
$desired_height = 440;

if(is_tax()) { // is category page
    $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
    $args = array( 'post_type' => 'portfolio', 'portfolio_category' => $term -> slug, 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order'=>'ASC' ); 
}
else { // is main portfolio page
    $args = array( 'post_type' => 'portfolio', 'posts_per_page' => -1, 'orderby' => 'menu_order','order'=>'ASC' ); 
}
$loop = new WP_Query( $args );
if($loop->have_posts()) {

&GT;

    <div class="portfolio-gallery group isotope">
        <?php
         //output the latest projects from the 'my_portfolio' custom post type
         while ($loop->have_posts()) : $loop->the_post();
        ?>
    <?php
      $terms = get_the_terms( $post->ID, 'portfolio_category' );
      if ( $terms && ! is_wp_error( $terms ) ) {
        $portfolio_category = array();
        foreach ( $terms as $term ) {
          $portfolio_category[] = ucwords(strtolower($term->slug)); // Capitalise Portfolio Category String 
        }
        $the_tax = join( " ", $portfolio_category );
      } else {
        $the_tax = "";
      };       
    ?>

            <div class="portfolio-item <?php echo $the_tax; ?> portfolio-item-<?php the_ID(); ?>">      
                <a class="project-link" href="<?php the_permalink(); ?>">
                        <div class="thumb-container">
            <div class="portfolio-thumb">
              <?php if( get_field('gray_scale_image') ): ?>
                <img src="<?php the_field('gray_scale_image'); ?>" class="grey-scale-image" />
              <?php endif; ?>
              <?php if( get_field('gray_scale_image') ): ?>
                <img src="<?php the_field('colour_image'); ?>" class="colour-image" />
              <?php endif; ?>
            </div>                          
                        </div><!-- /.thumb-container -->
                </a><!-- /.project-link -->
      <h3 class="portfolio-category"><?php echo str_replace('-',' ',ucwords(join(", ", explode(" ", $the_tax))) ); ?></h3>
      <h3 class="portfolio-title"><?php the_title(); ?></h3>
            </div><!-- /.portfolio-item -->

        <?php endwhile; ?>
    </div><!-- .portfolio-gallery -->
<?php } // end if ?>

1 个答案:

答案 0 :(得分:0)

这一行出错了

<h3 class="portfolio-category"><?php echo str_replace('-',' ',ucwords(join(", ", explode(" ", $the_tax))) ); ?></h3>

在此行中,您可以尝试以前提到的以下功能

$bar = ucwords(strtolower($bar)); // Hello World!

我没有测试代码