Woocommerce thumbnail over title - wordpress

So i have a website where i want the page that shows my products like this
Thumbnail
Title
Description
at the moment it is like
Title
woocommerce_archive_description (which is both the description and thumbnail)
this is the page template:
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
get_header('shop');
?>
<div class="woo-leasing" id="woo-leasing" >
<?php
$term = get_queried_object();
$hasChilds = wooTermHasChildren($term->term_id);
if (!empty($term) && $term->count > 0) {
$args = array('term' => $term);
wc_get_template('content-leasing-single.php', $args);
} elseif (!empty($term) && $hasChilds) {
do_action('woocommerce_archive_description');
echo '<h1 class="page-title">';
woocommerce_page_title();
echo '</h1>';
woocommerce_product_loop_start();
woocommerce_product_subcategories();
woocommerce_product_loop_end();
} elseif (!woocommerce_product_subcategories(array('before' => woocommerce_product_loop_start(false), 'after' => woocommerce_product_loop_end(false)))) {
wc_get_template('loop/no-products-found.php');
}
?>
</div>
<?php get_footer('shop'); ?>
As i am inexperienced i believe this is the code to manipulate.
do_action('woocommerce_archive_description');
echo '<h1 class="page-title">';
woocommerce_page_title();
echo '</h1>';
woocommerce_product_loop_start();
woocommerce_product_subcategories();
woocommerce_product_loop_end();
i want to seperate the woocommerce_archive_description so i could do something like this.
woocommerce_page_thumbnail();
echo '<h1 class="page-title">';
woocommerce_page_title();
echo '</h1>';
woocommerce_page_description();
woocommerce_product_loop_start();
woocommerce_product_subcategories();
woocommerce_product_loop_end();
I hope you understand my question, and i would be happy if you could help me to approach this issue.

Related

Get ACF Taxonomy selection in Block and display fields

Figured this would be pretty easy but I am running into an issue.
The website I am building, the client has a list of taxonomies that have an ACF Image Field and ACF Description field.
What they want to do is have a block where they can select certain ingredients from the Taxonomy Block, then have it render out formatted (on a page)(At this time it doesnt need to link to the actual category) but they want to do it this way so they dont need to update page by page when an ingredient changes description or image they can just change it in the taxonomy list.
Below is the code i am using to try and get it going from the docs, it wont render the name or original description it will render the slug but skips over the name but the slug is correct
I've been trying this with no luck, it just returns 3 li's which is correct but i can get a name or custom field to come through.
If i just the the_field('ingredients_selector'); I get the ID's just fine But for the life of me i can not get a term name or the ACF field attached to it/
$terms = get_field('ingredients_selector');
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
echo '<ul class="ingredients-list">';
foreach ( $terms as $term ) {
echo '<li class="ingredients-list__item">' . $term->name . '</li>'; ?>
<p>Description: <?php the_field('description', $term); ?></p>
<p>Image: <?php the_field('image', $term); ?></p>
<?php }
echo '</ul>';
}
?>
I've also tried this way, this gives me same reuslt but the slug with work, it will skip term name again but "view all" will link at least
<?php
$terms = get_field('ingredients_selector');
if( $terms ): ?>
<ul>
<?php foreach( $terms as $term ): ?>
<li>
<h2><?php echo esc_html( $term->name ); ?></h2>
<p>Term description: <?php the_field('description', $term); ?></p>
<p>Term Image: <?php the_field('image', $term); ?></p>
<p><?php echo esc_html( $term->description ); ?></p>
View all '<?php echo esc_html( $term->name ); ?>' posts
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Attached is my set up of the ACF fields
EDIT****
This was my solution
<?php
$tax = 'ingredients';
$terms = get_terms( $tax, $args = array(
'hide_empty' => false, // do not hide empty terms
));
foreach( $terms as $term ) {
$term_link = get_term_link( $term );
$image = get_field('image', 'ingredients_' . $term->term_id );
$description = get_field('description', 'ingredients_' . $term->term_id );
if( $term->count > 0 ) {
echo '<a href="' . esc_url( $term_link ) . '">';
echo '<img src="' . $image['url'] . '" alt="' . $image['alt'] .'">';
echo $term->name .'</a>';
echo $description;
} elseif( $term->count !== 0 ) {
echo '' . $term->name .'';
}
}
?>
Try this and replace term_name_ with your actual term slug:
<?php
$terms = get_field('ingredients_selector');
if( $terms ): ?>
<ul>
<?php foreach( $terms as $term ): ?>
<li>
<h2><?php echo esc_html( $term->name ); ?></h2>
<p>Term description: <?php the_field('description', 'term_name_'.$term->term_id); ?></p>
<p>Term Image: <?php the_field('image', 'term_name_'.$term->term_id); ?></p>
<p><?php echo esc_html( $term->description ); ?></p>
View all '<?php echo esc_html( $term->name ); ?>' posts
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
You can find more about this here.

Get custom fields without _edit_last, _edit_lock, _wp_page_template and _visual-subtitle

I'm getting custom fields using
<?php $meta = get_post_custom($level_2->ID); ?>
<?php foreach ( $meta as $key => $value) { ?>
<?php echo $key.': '.$value[0].'<br />'; ?>
<?php } ?>
and it is showing
_edit_last: 1<br>
_edit_lock: 1483226440:1<br>
_wp_page_template: page-services.php<br>
Body Repair: ValueBodyRepair<br>
_visual-subtitle: <br>
I need only 4th row Body Repair: ValueBodyRepair<br>
If you would adjust the code this way, you would get only the one you need:
<?php $meta = get_post_custom($level_2->ID); ?>
<?php foreach ( $meta as $key => $value) { ?>
<?php if(substr($key, 0, 1) !== '_'): ?>
<?php echo $key.': '.$value[0].'<br />'; ?>
<?php endif; ?>
<?php } ?>

Wordpress query posts with thumbnail images and recent post titles

i am beginner to wordpress theme development.I am developing a theme.I am going through a problem.
In my index.php page i want the most latest post displayed as thumbnail.The second,third and fourth latest post is displayed with only title.I also have five categories.I want the posts displayed category wise.
Now how to do that.Can anyone help me???
Please review the wordpress query before creating a theme first : http://codex.wordpress.org/Class_Reference/WP_Query . With regards to the question. Try this :
// The Query
$args = array('post_type' => 'post', 'posts_per_page' => 5);
$the_query = new WP_Query( $args );
$count = 0;
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
if($count == 0){
the_post_thumbnail();
}else{
echo get_the_title();
}
$count++;
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
Cheers!
Please test with this code:
<?php $the_query = new WP_Query('posts_per_page=5&cat=18');
$count = 0;
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) : $the_query->the_post();
if($count == 0){?>
<?php the_post_thumbnail('medium'); ?>
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( '%s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<?php the_title(); ?>
</a>
<?php
}else{ ?>
<li class="list">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( '%s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<?php the_title(); ?>
</a>
</li>
<?php
}
$count++;
echo "</li>";
endwhile;
} else {
echo "No Post Found!";
}
/* Restore original Post Data */
wp_reset_postdata();
?>

Custom layout for search result

In Wordpress 3.5.1 I want to create & use custom layout to display search result. I googled and found http://codex.wordpress.org/Creating_a_Search_Page but this is not exactly what I want.
Okay I solved my problem and now very happy :)
I write following script in search.php file
while ( have_posts() ) {
the_post();
//get_template_part( 'content', get_post_format() );
$permalink = get_permalink($post->ID);
$title = get_the_title($post->ID);
$feed = truncate( strip_tags( get_the_content($post->ID) ), 0, 300, "[...]");
echo '<div class="posts">';
echo '<div style="float:left">';
echo '<a class="featured-img">
'.the_post_thumbnail('thumbnail').'
</a>';
echo '</div>';
echo '<div class="posts-content">';
echo '<div class="heading">'.$title.'</div>';
echo '<div class="comments"> </div>'.
$feed
.'</div>';
echo '</div>';
}

Wordpress post query php custom field conditional

Here's the situation:
In wordpress I'm trying to reset a post WP_Query so that I can rewrite the post link based on whether or not a custom field exists in the post. I'm trying to give the post a NEW link in the custom field.
All I've managed to do here is kill the link entirely. Any and all help is greatly appreciated, I'm pretty green to php.
Here's my WP_Query:
<?php
$recentPosts = new WP_Query();
$recentPosts->query('showposts=3');
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<?php
$attribute = the_title_attribute();
$title = the_title();
$key = 'NewPostLink';
$newLink = get_post_meta( $post->ID, $key, TRUE );
if ($newLink != '') {
$theLink = get_permalink ($post->ID );
if (has_post_thumbnail()) {
$image = get_the_post_thumbnail( $post->ID );
echo '<div class="thumbnailbox"><div class="thumbnail">'.$image.'</div></div>';
echo '<h2>'.$title.'</h2>';
} else {
echo '<h2>'.$title.'</h2>';
}
} else {
$theLink = $newLink;
if (has_post_thumbnail()) {
$image = get_the_post_thumbnail( $post->ID );
echo '<div class="thumbnailbox"><div class="thumbnail">'.$image.'</div></div>';
echo '<h2>'.$title.'</h2>';
} else {
echo '<h2>'.$title.'</h2>';
}
}
?>
<small><?php the_time('F jS, Y') ?></small>
<div class="entry">
<?php the_excerpt(); ?>
</div>
</div>
<?php endwhile; ?>
I think this is what you need. It's hard to tell. I suppose that the first part of the if statement is what runs if there is no custom post meta? I couldn't tell. Here's what the problem was. The if statement ran the first part if there IS a value returned for the custom post meta, otherwise it ran the second part, using the empty string as the href. (The first part runs if the custom value either doesn't exist or is anything but an empty string). Changing the if statement to check if it's empty is better because it will catch it if it doesn't exist (returns false), or if it does exist but is an empty string (declared but not defined).
I've marked what I edited with comments (just one line).
<?php
$recentPosts = new WP_Query();
$recentPosts->query('showposts=3');
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<?php
$attribute = the_title_attribute();
$title = the_title();
$key = 'NewPostLink';
$newLink = get_post_meta( $post->ID, $key, TRUE );
/* EDITED */ if (empty($newLink)) {
$theLink = get_permalink ($post->ID );
if (has_post_thumbnail()) {
$image = get_the_post_thumbnail( $post->ID );
echo '<div class="thumbnailbox"><div class="thumbnail">'.$image.'</div></div>';
echo '<h2>'.$title.'</h2>';
} else {
echo '<h2>'.$title.'</h2>';
}
} else {
$theLink = $newLink;
if (has_post_thumbnail()) {
$image = get_the_post_thumbnail( $post->ID );
echo '<div class="thumbnailbox"><div class="thumbnail">'.$image.'</div></div>';
echo '<h2>'.$title.'</h2>';
} else {
echo '<h2>'.$title.'</h2>';
}
}
?>
<small><?php the_time('F jS, Y') ?></small>
<div class="entry">
<?php the_excerpt(); ?>
</div>
</div>
<?php endwhile; ?>

Resources