Custom layout for search result - wordpress

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>';
}

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.

How to create author dropdown having list of authors in wordpress?

How to create authors list dropdown in wordpress ?
I need to filter posts by author.
Please help !
echo '<form method="get">';
$authors = get_users( 'orderby=nicename' );
$ret='';
foreach ( $authors as $aut ) {
$ret.= '<option value="'.$aut->ID.'">' . esc_html( $aut->user_nicename ) . '</option>';
}
echo '<select name="author">'.$ret.'</select><input type="submit"></form>';
Use this code
<ul>
<?php $allUsers = get_users('show_fullname=1&optioncount=1&orderby=post_count&order=DESC&role=author');
foreach($allUsers as $user){ ?>
<li><?php echo $user->display_name; echo " (".count_user_posts( $user->ID ).")";?></li>
<?php } ?>
</ul>

Woocommerce thumbnail over title

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.

Using an ACF image object for a custom taxonomy within an echo block loop

I can't seem to pull a ACF image object for a custom taxonomy when used in this loop, which is made of echo blocks:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$terms = get_terms( 'product_type' );
$image = get_field('product_type_tax_image');
$hero_image = $image['sizes']['medium'];
foreach ( $terms as $term ) {
// The $term is an object, so we don't need to specify the $taxonomy.
$term_link = get_term_link( $term );
// If there was an error, continue to the next term.
if ( is_wp_error( $term_link ) ) {
continue;
}
var_dump($hero_image);
// We successfully got a link. Print it out.
echo '<a href="' . esc_url( $term_link ) . '" class="product-grid- block" style="' . $hero_image[0] . '">';
echo '<div class="product-grid-inner-txt-wrap">';
echo '<h4>' . $term->name . '</h4>';
echo '<p>' . $term->description . '</p>';
echo '</div>';
echo '</a>';
}
?>
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
The var dump just returns NULL. I've looked at this and this but don't seem to help. What am I doing wrong?
Take a look at this article:
http://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/
To pull a custom field from a Taxonomy Term, you need to add a second item to your get_field function call. Like this:
$image = get_field('product_type_tax_image', $term );
Also, it looks like you're trying to loop through $terms, but you're grabbing the custom field's value outside of your foreach loop, so that should get moved inside that loop, like so:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$terms = get_terms( 'product_type' );
foreach ( $terms as $term ) {
//get $term's image
$image = get_field('product_type_tax_image', $term );
$hero_image = $image['sizes']['medium'];
// The $term is an object, so we don't need to specify the $taxonomy.
$term_link = get_term_link( $term );
// If there was an error, continue to the next term.
if ( is_wp_error( $term_link ) ) {
continue;
}
var_dump($hero_image);
// We successfully got a link. Print it out.
echo '<a href="' . esc_url( $term_link ) . '" class="product-grid- block" style="' . $hero_image[0] . '">';
echo '<div class="product-grid-inner-txt-wrap">';
echo '<h4>' . $term->name . '</h4>';
echo '<p>' . $term->description . '</p>';
echo '</div>';
echo '</a>';
}
?>
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>

Remove posts permalink (href)

I am trying to figure out a way to remove permalink's from posts with the category 'nolink'. I have tried a few java script attempts - but have not managed to get it to work.
<?php
query_posts( 'tag=Client-list' );
while ( have_posts() ) : the_post();
echo '<ul class="client-thumb-wrap">';
echo '<a href="';
the_permalink();
echo '">';
echo '<li class="';
$category = get_the_category( $custompost );
echo $category[0]->cat_name ;
echo ' ';
echo $category[1]->cat_name ;
echo ' ';
echo $category[2]->cat_name ;
echo ' ';
echo $category[3]->cat_name ;
echo '">';
echo '<img src="';
the_field('client_logo');
echo '">';
echo '</li>';
echo '</ul>';
endwhile;
wp_reset_query();
?>
has_term allows you to check if a post has a specific term assigned (or not), try:
$href = ( has_term( 'nolink', 'category' ) ) ? '#' : get_permalink();
echo '<a href="' . $href . '">';

Resources