ACF Repeater display row number - count

Looking to display the individual number of each repeater row. So for example, the first row will display "1" and the second row will display "2".
I found this from Elliot,
<?php echo count( get_field('repeater_field') );?>
which counts how many rows there are in total. But I need the individual number next to each.
Thanks

I would suggest taking a look at Elliot's answer here:
http://support.advancedcustomfields.com/forums/topic/getting-instance-and-sort-of-id-of-repeater-field/
You would want to set up a counter variable ( $i ) and then add 1 to $i inside the loop.
<?php if( have_rows('repeater_field') ): $i = 0; ?>
<div class="repeater_loop">
<?php while( have_rows('repeater_field') ): the_row(); $i++; ?>
<p>This is row number <?php echo $i; ?>.</p>
<!-- call your sub_fields as needed -->
<?php endwhile; ?>
</div>
<?php endif; ?>
This would output a div with a paragraph tag that displays your row number.

<?php if( have_rows('tabel_produse_profit') ): $i = 0; ?>
<table width="100%" class="tab">
<tr>
<td>Nr.</td>
<td>Imagine</td>
<td>Nume</td>
<td>Evaluare</td>
<td>Verificati pretul</td>
</tr>
<?php while( have_rows('tabel_produse_profit') ): the_row(); $i++;
// vars
$image = get_sub_field('tabel_imagine_produs');
$link = get_sub_field('tabel_link_profit');
$titlu = get_sub_field('tabel_titlu_profit');
$evaluare = get_sub_field('tabel_evaluare');
$count = count(get_field('tabel_produse_profit'));
?>
<tr>
<td class="row1">
<?php echo $i; ?>
<?php if( $count ): ?>
<div class="rowc"> din <?php echo $count; ?></div>
<?php endif; ?>
</td>
<td class="row2">
<?php if( $image ): ?>
<img class="imag" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
<?php endif; ?>
</td>
<td class="row3">
<?php if( $titlu ): ?>
<h2><?php echo $titlu; ?></h2>
<?php endif; ?>
</td>
<td class="row4">
<?php if( $evaluare ): ?>
<div class="eva"><?php echo $evaluare; ?></div>
<?php endif; ?>
</td>
<td class="row5">
<?php if( $link ): ?>
<a class="ver" href="<?php echo $link; ?>">VERIFICAȚI PREȚUL</a>
<div class="mag">pe emag.ro</div>
<?php endif; ?>
</td>
<?php echo $content; ?>
</tr>
<?php endwhile; ?>
</table>
<?php endif; ?>

There is get_row_index() already available to use.

Related

ACF repeater field custom image size output

I'm trying to output custom image size in my code:
<?php if(get_field('repeater-field-name')) { ?>
<?php foreach (get_field('repeater-field-name') as $row) :?>
<div class="item" onclick="location.href='<?php print $row['link'] ?>';" style="cursor: pointer;">
<div class="sisseviskaja-title"><h2><?php print $row['title'] ?></h2></div>
<div class="sisseviskaja-pilt"><img src="<?php print $row['image'] ?>" alt="" /></div>
</div>
<?php endforeach; ?>
<?php } ?>
I have tried ACF tutorial codes but i'd like to keep foreach loop that i have. I'm no PHP guru so i havent got any good ideas to implement it.
Can someone, please, help me?
Here's the way to do with ACF codes. This is using array for the image (which you need to do if you want to pull out the dimensions). I'm not sure exactly if it can be done the way you want to do it.
<?php if (have_rows('project_listings')){ ?>
<?php while (have_rows('project_listings')){ the_row();
$link = get_sub_field('link_field');
$title = get_sub_field('title_field');
$image = get_sub_field('image');
//additional vars
$size = 'full';
$width = $image['sizes'][ $size . '-width' ];
$height = $image['sizes'][ $size . '-height' ];
?>
<div class="item" onclick="location.href='<?php echo $link ?>';" style="cursor: pointer;">
<div class="sisseviskaja-title">
<h2><?php echo $title ?></h2>
</div>
<div class="sisseviskaja-pilt">
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>"/>
</div>
</div>
<?php }; ?>
<?php }; ?>
I do it like this:
<?php if( have_rows('field-name') ): ?>
<?php while( have_rows('field-name') ): the_row(); ?>
<?php
$image = get_sub_field('picture');
$size = 'thumbnail'; // (thumbnail, medium, large, full or custom size)
if( $image ) {
echo wp_get_attachment_image( $image, $size );
}
?>
<?php endwhile; ?>
<?php endif; ?>

(Magento) Display product list

How to display products in list?
Replace the whole code of list.phtml to this...
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
<?php echo $this->getToolbarHtml() ?>
<?php // List mode ?>
<?php if($this->getMode()!='grid'): ?>
<?php $_iterator = 0; ?>
<table id="itemtable" style="width:100%;">
<thead><tr><th>Name</th><th>Short description</th><th>Brand</th><th>Price With Tax</th><th>Price Without Tax</th><th>Add To Cart</th></tr></thead>
<tbody>
<?php foreach ($_productCollection as $_product): ?>
<tr class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
<td><?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></td>
<td><?php echo $_product->getShortDescription(); ?></td>
<td>brand</td>
<td><?php
$_priceIncludingTax = Mage::helper('tax')->getPrice($_product, $_product->getPrice(), true, null, null, null, null, false);
echo $_priceIncludingTaxWithCurrency = Mage::helper('core')->currency($_priceIncludingTax); ?></td>
<td><?php
$_priceExcludingTax = Mage::helper('tax')->getPrice($_product, $_product->getPrice(), false, null, null, null, null, false);
echo $_priceExcludingTaxWithCurrency = Mage::helper('core')->currency($_priceExcludingTax); ?></td>
<td>
<?php if($_product->isSaleable() && !$_product->canConfigure()): ?>
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId(); ?>"><input name="qty" type="text" class="input-text qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" /><button class="form-button" onclick="productAddToCartForm_<?php echo $_product->getId(); ?>.submit()"><span><?php echo $this->__('Add to Cart'); ?></span></button></form>
<script type="text/javascript"> var productAddToCartForm_<?php echo $_product->getId(); ?> = new VarienForm('product_addtocart_form_<?php echo $_product->getId(); ?>'); productAddToCartForm_<?php echo $_product->getId(); ?>.submit = function(){ if (this.validator.validate()) { this.form.submit(); } }.bind(productAddToCartForm_<?php echo $_product->getId(); ?>);</script>
<?php endif;?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<script type="text/javascript">decorateList('products-list', 'none-recursive')</script>
<?php endif; ?>
<div class="toolbar-bottom">
<?php echo $this->getToolbarHtml() ?>
</div>
</div>
<?php endif; ?>
<?php
//set product collection on after blocks
$_afterChildren = $this->getChild('after')->getSortedChildren();
foreach($_afterChildren as $_afterChildName):
$_afterChild = $this->getChild('after')->getChild($_afterChildName);
$_afterChild->setProductCollection($_productCollection);
?>
<?php echo $_afterChild->toHtml(); ?>
<?php endforeach; ?>
<style>
#itemtable th{ font-weight:bold!important;text-align:center!important;}
#itemtable tr{ height:50px!important;}
#itemtable tr td{ text-align:center!important;}
</style>
Let me know if you have any query...

get post thumbnail image in wordpress and display in 3 coulmn

I am trying to display one particular category posts as a three column layout The problem I have is I am not sure how I can use for or forwach to loop the display of each post thumbnail so whn it comes more than three I can use one_thrid_last. css class.
<?php while ( have_posts() ) : the_post(); ?>
<?php if (is_category('actress-gallery') ):?>
<?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
<div class="one_fourth_last">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<?php echo $image_url = wp_get_attachment_image( get_post_thumbnail_id($post->ID) , 'thumbnail' ); ?>
<h2><?php the_title(); ?></h2>
</a>
</div><!-- post-thumbnail /-->
<?php endif; ?>
<div class="wrapper" style="width:800px; height:auto;">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php if ( has_post_thumbnail() ) { ?>
<div class="image-wrapper" style=" width:250px; height:300px;" >
<?php the_title();?>
<?php the_content();?>
<?php the_post_thumbnail(); ?>
</div>
<?php } endwhile; endif; ?>
</div>
<div class="wrapper" style="width:750px; height:700px;">
<?php while (have_posts()) : the_post(); ?>
<?php if ( has_post_thumbnail() ) { ?>
<div style="width:250px; height:300px;" >
<?php the_title();?>
<?php the_post_thumbnail(); ?>
</div>
<?php } endif; ?>
</div>
You can use a $count variable and check for the 3rd thumbnail.
<?php if ( have_posts() ) : ?>
<?php $count = 1; ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php if ( has_post_thumbnail() ) : ?>
<?php if ($count % 3 == 0) : ?>
<div class = "one_third_last">
<?php else : ?>
<div class = "other_class">
<?php endif; ?>
<?php the_title();?>
<?php the_content();?>
<?php the_post_thumbnail(); ?>
</div>
<?php endif; ?>
<?php $count++; ?>
<?php endwhile; ?>
<?php endif; ?>

Basic search in wordpress

I am creating a wordpress template in which I want to integrate a simple search form. I googled a lot about this in the last 3 days and tried several tutorials but I am afraid there is something I don't get at all. I have 3 pages for the search: search.php, searchform.php and searchpage.php. All the tutorials I read provide similar code like this:
search.php:
<?php if (have_posts()) : ?>
…
<?php while (have_posts()) : the_post(); ?>
…
<?php endwhile; else: ?>
… <p>The key word <strong><?php the_search_query(); ?></strong> is not on this website.</p>
<?php include (TEMPLATEPATH . "/searchform.php"); ?>
<?php include (TEMPLATEPATH . "/searchpage.php"); ?>
<?php endif; ?>
searchform.php:
<?php
$querystring = esc_attr(apply_filters('the_search_query', get_search_query()));
$searchstring = "Suchbegriff eingeben";
if (empty($querystring)) { $querystring = $searchstring; }
?>
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
<div>
<input type="text" name="s" id="s" value="<?php echo $querystring; ?>"
onblur="if (this.value == '') { this.value = '<?php echo $searchstring; ?>'; }"
onfocus="if (this.value == '<?php echo $searchstring; ?>') { this.value = ''; }" />
<input type="submit" id="searchsubmit" value="Suchen" />
</div>
</form>
searchpage.php (adapted from page.php):
<?php
/*
Template Name: Search Page
*/
?>
<div id="content">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div class="blogpost">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php $this->posts = $wpdb->get_results($this->request); ?>
</div> <!-- end class blogpost -->
<?php endwhile; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
If there is no match with the key word the search works. But if there is a match I only get … … … … … … … as output. I know that must be from the search.php but I have no idea how I can change that. Thanks for your advise and help, I really appreciate it!
The important file is search.php, which displays any matching results, or a failure message if there are no matches. Try something like this:
<?php
/**
* Search results page
*/
?>
<?php if ( have_posts() ): ?>
<h2>Search Results for '<?php echo get_search_query(); ?>'</h2>
<ol>
<?php while ( have_posts() ) : the_post(); ?>
<li>
<h2><?php the_title(); ?></h2>
<time datetime="<?php the_time( 'Y-m-d' ); ?>" pubdate><?php the_date(); ?> <?php the_time(); ?></time> <?php comments_popup_link('Leave a Comment', '1 Comment', '% Comments'); ?>
<?php the_content(); ?>
</li>
<?php endwhile; ?>
</ol>
<?php else: ?>
<h2>No results found for '<?php echo get_search_query(); ?>'</h2>
<?php endif; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

How do I set ACF repeater to only show X items per row

I'm using ACF pro repeater fields, which renders individual images per row. However it shows all images until it wraps to the next line:
<div class="client-logo-web-wrapper"><?php $logo_images = get_field( 'logo' ); ?>
<?php if ( $logo_images ) : ?>
<?php foreach ( $logo_images as $logo_image ): ?>
<a href="<?php echo $logo_image['url']; ?>">
<img src="<?php echo $logo_image['sizes']['thumbnail']; ?>" alt="<?php echo $logo_image['alt']; ?>" />
</a>
<p><?php echo $logo_image['caption']; ?></p>
<?php endforeach; ?>
<?php endif; ?>
<?php if ( have_rows( 'logo_gallery' ) ) : ?>
<?php while ( have_rows( 'logo_gallery' ) ) : the_row(); ?>
<?php $client_logo = get_sub_field( 'client_logo' ); ?>
<?php if ( $client_logo ) { ?>
<div class="client-logo"><img src="<?php echo $client_logo['url']; ?>" alt="<?php echo $client_logo['alt']; ?>" />
</div>
<?php } ?>
<?php endwhile; ?></div>
<?php else : ?>
<?php // no rows found ?>
<?php endif; ?>
Instead I would like to display a set number of images (for ex. 4) per row. Thanks!
You need to define the limit, and the break the loop once you reach that limit. Also, you can also set the max number of items in your ACF field definition.
Try the following with the limit set:
<?php
$show = 4;
$count = 0;
?>
<?php if ( $logo_images ) : ?>
<?php foreach ( $logo_images as $logo_image ): ?>
<?php $count++; ?>
<a href="<?php echo $logo_image['url']; ?>">
<img src="<?php echo $logo_image['sizes']['thumbnail']; ?>" alt="<?php echo $logo_image['alt']; ?>" />
</a>
<p><?php echo $logo_image['caption']; ?></p>
<?php if ($count > $show) { break; } ?>
<?php endforeach; ?>
<?php endif; ?>

Resources