flavaflav37 Posted October 6, 2012 Share Posted October 6, 2012 Hi folks, I have a Wordpress loop which displays portfolio items, and I would basically like to add a number to each item in that loop, before the item name (ie; 01 - A portfolio item, 02 - A portfolio item, 03 - A portfolio item etc...) Quite basic, but how do I achieve this? thanks Link to comment https://forums.phpfreaks.com/topic/269156-wordpress-adding-number-before-item/ Share on other sites More sharing options...
Jessica Posted October 6, 2012 Share Posted October 6, 2012 Code?? foreach($arr AS $key=>$val){ Echo "$key $val"; } Link to comment https://forums.phpfreaks.com/topic/269156-wordpress-adding-number-before-item/#findComment-1383205 Share on other sites More sharing options...
flavaflav37 Posted October 16, 2012 Author Share Posted October 16, 2012 Hi Jessica, Apologies, have been away, only just spotted your reply. My current code - <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php $cur_terms = get_the_terms( $post->ID, 'project-type' ); foreach ( (array) $cur_terms as $cur_term ) { }?> <article class="one-third column item <?php echo strtolower($cur_term->slug); ?>" data-filter=""> <div class="thumbnail"> <a data-lightbox="width:940;height:550" data-overlayer="overlayDefault:overlay-default portfolio" href="<?php echo get_post_meta($post->ID, 'portfolio_video_url', true) ?>?autoplay=1"> <?php the_post_thumbnail('latest-thumb'); ?> <div class="roll"> <em> <i class="icon-film icon-large"></i> view project </em> </div> </a><!-- end lightbox --> </div><!-- end .thumbnail --> <h2>01 | <a data-lightbox="width:940;height:550" href="<?php echo get_post_meta($post->ID, 'portfolio_video_url', true) ?>?autoplay=1"><?php the_title(); ?></a></h2> <?php if ( get_post_meta($post->ID, 'project_date', true) ) : ?> <p>~ <strong><?php echo get_post_meta($post->ID, 'project_date', true) ?></strong></p> <?php endif; ?> </article><!-- end article --> <?php endwhile; endif; ?> As you can see in the H2 tag i currently have it set static, which of course loops through, and shows 01 for all entries currently, which is what I want to change. Thanks in advance Link to comment https://forums.phpfreaks.com/topic/269156-wordpress-adding-number-before-item/#findComment-1385605 Share on other sites More sharing options...
Jessica Posted October 16, 2012 Share Posted October 16, 2012 foreach($arr AS $key=>$val){ Echo "$key $val"; } Link to comment https://forums.phpfreaks.com/topic/269156-wordpress-adding-number-before-item/#findComment-1385606 Share on other sites More sharing options...
flavaflav37 Posted October 16, 2012 Author Share Posted October 16, 2012 Hi Jessica, Where am I placing this exactly? Many thanks Link to comment https://forums.phpfreaks.com/topic/269156-wordpress-adding-number-before-item/#findComment-1385610 Share on other sites More sharing options...
Jessica Posted October 16, 2012 Share Posted October 16, 2012 Wherever you want the number. You can't just copy and paste that, you need to change your code. Did you read the manual on foreach yet? Link to comment https://forums.phpfreaks.com/topic/269156-wordpress-adding-number-before-item/#findComment-1385632 Share on other sites More sharing options...
flavaflav37 Posted October 16, 2012 Author Share Posted October 16, 2012 No not yet Would be a good start!! Link to comment https://forums.phpfreaks.com/topic/269156-wordpress-adding-number-before-item/#findComment-1385634 Share on other sites More sharing options...
flavaflav37 Posted October 17, 2012 Author Share Posted October 17, 2012 Hi folks, Fixed this with the following - <?php $i=1; ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php $cur_terms = get_the_terms( $post->ID, 'project-type' ); foreach ( (array) $cur_terms as $cur_term ) { }?> <article class="one-third column item <?php echo strtolower($cur_term->slug); ?>" data-filter=""> <div class="thumbnail"> <a data-lightbox="width:940;height:550" data-overlayer="overlayDefault:overlay-default portfolio" href="<?php echo get_post_meta($post->ID, 'portfolio_video_url', true) ?>?autoplay=1"> <?php the_post_thumbnail('latest-thumb'); ?> <div class="roll"> <em> <i class="icon-film icon-large"></i> view project </em> </div> </a><!-- end lightbox --> </div><!-- end .thumbnail --> <h2><?php echo str_pad($i++,2,'0',STR_PAD_LEFT); ?> | <a data-lightbox="width:940;height:550" href="<?php echo get_post_meta($post->ID, 'portfolio_video_url', true) ?>?autoplay=1"><?php the_title(); ?></a></h2> <?php if ( get_post_meta($post->ID, 'gt_project_date', true) ) : ?> <p>~ <strong><?php echo get_post_meta($post->ID, 'project_date', true) ?></strong></p> <?php endif; ?> </article><!-- end article --> <?php endwhile; endif; ?> Link to comment https://forums.phpfreaks.com/topic/269156-wordpress-adding-number-before-item/#findComment-1385745 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.