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...
Related
I have a plugin that I've created within my site, which just shows one page where I'm calling all users and then some specific information about those users.
Would it be possible to allow users to search for other existing users from the front end of the site?
This is the kind of thing I've got going on at the moment, I haven't been able to find any kind of search of this sort of thing, so if anyone could point me in the right direction it's be very much appreciated,
I haven't included any code as it's not that relevant really, but I can include it if needs be,
Thanks in advance!
http://focusedlearning.hcrlaw.com/courses-admin/
<?php $total_users = count_users();
$total_users = $total_users['total_users'];
$paged = get_query_var('paged');
$number = 20;?>
<?php
$args = array(
'order' => 'ASC',
'orderby' => 'display_name',
'count_total' => 'true',
'role' => 'subscriber',
'offset' => $paged ? ($paged) * $number : 0,
'number' => $number,
);?>
<?php
$blogusers = get_users($args);?>
<?php // Array of WP_User objects.
foreach ( $blogusers as $user ) {?>
<?php $userId = $user->ID;?>
<?php echo '<input type="text" value="' . esc_html( $user->display_name ) . '">';?>
<div id="content">
<h2>Completed Courses</h2>
<!-- COMPLIANCE-->
<?php
$post_args = array(
'post_type' => 'tribe_events',
'eventDisplay'=>'custom',
'start_date' => date( 'Y-m-d H:i:s', strtotime( '-365 days' ) ),
'tax_query' => array(
array(
'taxonomy' => 'tribe_events_cat',
'field' => 'slug',
'terms' => 'compliance',
),
),
'meta_query' => array(
array(
'key' => 'associated_people',
'value' => '"' . $userid . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
); ?>
<!-- MEMBERSHIP A -->
<?php if( rcp_is_active() && 2 == rcp_get_subscription_id() ) : ?>
<?php
$post_list = new wp_query( $post_args ); ?>
<table style="width:100%">
<tr>
<td>Compliance</td>
</tr>
<?php
if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
?>
<tr>
<td><?php the_title(); ?></td>
<td><?php the_field('cpd_credits'); ?></td>
</tr>
<?php endwhile; else : ?>
<?php endif; wp_reset_query(); ?>
<?php
$total_credit = 0;
$post_list = new wp_query( $post_args ); ?>
<table style="width:100%">
<?php
if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
$cur_credit = get_field('cpd_credits');
$total_credit += $cur_credit;
?>
<?php endwhile; else : ?>
<?php endif; wp_reset_query(); ?>
<tr>
<td <?php if($total_credit >= 2): ?> style="background-color:#009137;" <?php endif; ?> <?php if($total_credit < 2): ?> style="background-color:#f50c1a;" <?php endif; ?>>
Total: <?php echo $total_credit;?> of 2 in the last 12 months
</td>
</tr>
</table>
<?php endif; ?>
<!-- END OF MEMBERSHIP A -->
<!-- MEMBERSHIP B -->
<?php if( rcp_is_active() && 3 == rcp_get_subscription_id() ) : ?>
<?php
$post_list = new wp_query( $post_args ); ?>
<table style="width:100%">
<tr>
<td>Compliance</td>
</tr>
<?php
if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
?>
<tr>
<td><?php the_title(); ?></td>
<td><?php the_field('cpd_credits'); ?></td>
</tr>
<?php endwhile; else : ?>
<?php endif; wp_reset_query(); ?>
<?php
$total_credit = 0;
$post_list = new wp_query( $post_args ); ?>
<table style="width:100%">
<?php
if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
$cur_credit = get_field('cpd_credits');
$total_credit += $cur_credit;
?>
<?php endwhile; else : ?>
<?php endif; wp_reset_query(); ?>
<tr>
<td <?php if($total_credit >= 2): ?> style="background-color:#009137;" <?php endif; ?> <?php if($total_credit < 2): ?> style="background-color:#f50c1a;" <?php endif; ?>>
Total: <?php echo $total_credit;?> of 2 in the last 12 months
</td>
</tr>
</table>
<?php endif; ?>
<!-- END OF MEMBERSHIP B -->
<!-- MEMBERSHIP C -->
<?php if( rcp_is_active() && 4 == rcp_get_subscription_id() ) : ?>
<?php
$post_list = new wp_query( $post_args ); ?>
<table style="width:100%">
<tr>
<td>Compliance</td>
</tr>
<?php
if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
?>
<tr>
<td><?php the_title(); ?></td>
<td><?php the_field('cpd_credits'); ?></td>
</tr>
<?php endwhile; else : ?>
<?php endif; wp_reset_query(); ?>
<?php
$total_credit = 0;
$post_list = new wp_query( $post_args ); ?>
<table style="width:100%">
<?php
if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
$cur_credit = get_field('cpd_credits');
$total_credit += $cur_credit;
?>
<?php endwhile; else : ?>
<?php endif; wp_reset_query(); ?>
<tr>
<td <?php if($total_credit >= 2): ?> style="background-color:#009137;" <?php endif; ?> <?php if($total_credit < 2): ?> style="background-color:#f50c1a;" <?php endif; ?>>
Total: <?php echo $total_credit;?> of 2 in the last 12 months
</td>
</tr>
</table>
<?php endif; ?>
<!-- END OF MEMBERSHIP C -->
<!-- MEMBERSHIP D -->
<?php if( rcp_is_active() && 5 == rcp_get_subscription_id() ) : ?>
<?php
$post_list = new wp_query( $post_args ); ?>
<table style="width:100%">
<tr>
<td>Compliance</td>
</tr>
<?php
if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
?>
<tr>
<td><?php the_title(); ?></td>
<td><?php the_field('cpd_credits'); ?></td>
</tr>
<?php endwhile; else : ?>
<?php endif; wp_reset_query(); ?>
<?php
$total_credit = 0;
$post_list = new wp_query( $post_args ); ?>
<table style="width:100%">
<?php
if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
$cur_credit = get_field('cpd_credits');
$total_credit += $cur_credit;
?>
<?php endwhile; else : ?>
<?php endif; wp_reset_query(); ?>
<tr>
<td <?php if($total_credit >= 2): ?> style="background-color:#009137;" <?php endif; ?> <?php if($total_credit < 2): ?> style="background-color:#f50c1a;" <?php endif; ?>>
Total: <?php echo $total_credit;?> of 2 in the last 12 months
</td>
</tr>
</table>
<?php endif; ?>
<!-- END OF MEMBERSHIP D -->
<!-- MEMBERSHIP E -->
<?php if( rcp_is_active() && 6 == rcp_get_subscription_id() ) : ?>
<?php
$post_list = new wp_query( $post_args ); ?>
<table style="width:100%">
<tr>
<td>Compliance</td>
</tr>
<?php
if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
?>
<tr>
<td><?php the_title(); ?></td>
<td><?php the_field('cpd_credits'); ?></td>
</tr>
<?php endwhile; else : ?>
<?php endif; wp_reset_query(); ?>
<?php
$total_credit = 0;
$post_list = new wp_query( $post_args ); ?>
<table style="width:100%">
<?php
if( $post_list->have_posts() ) : while( $post_list->have_posts() ) : $post_list->the_post();
$cur_credit = get_field('cpd_credits');
$total_credit += $cur_credit;
?>
<?php endwhile; else : ?>
<?php endif; wp_reset_query(); ?>
<tr>
<td <?php if($total_credit >= 2): ?> style="background-color:#009137;" <?php endif; ?> <?php if($total_credit < 2): ?> style="background-color:#f50c1a;" <?php endif; ?>>
Total: <?php echo $total_credit;?> of 2 in the last 12 months
</td>
</tr>
</table>
<?php endif; ?>
<!-- END OF MEMBERSHIP E -->
<!-- END OF COMPLIANCE-->
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.
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; ?>
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(); ?>
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; ?>