I have got a filter in tab. I use motors theme. Filter has to redirect on main filter's page with applied options. It redirects and options are applied in list but link is not changed (it should be like this: site.com/?page_id=16410&make=citroen&ca-year=2012&min_price=2000&max_price=200000 ) but it's just like this: site.com/?page_id=16410 (main filter page). On this image I chose Chevrolet cars but it didn't apply: Chevrolet
If I choose one more option, it will apply all of them but I want it to work from tabs properly.
Form code:
<form action="<?php echo esc_url( stm_get_listing_archive_link() ); ?>" method="post">
<?php foreach ( $tax_query_args as $taxonomy_term_key => $taxonomy_term ): ?>
<?php //empty($taxonomy_term[0]->numeric) and ?>
<?php if ( !empty( $taxonomy_term[0] ) ): ?>
<div class="col-md-<?php echo esc_attr( $filter_columns_number ); ?> col-sm-6">
<div class="form-group">
<select name="<?php echo ( esc_attr( $taxonomy_term_key ) == "price" ) ? "max_price" : esc_attr( $taxonomy_term_key ) ?>" class="form-control">
<option value=""><?php printf( esc_html__( 'Select %s', 'motors' ), stm_get_name_by_slug( $taxonomy_term_key ) ); ?></option>
<?php foreach ( $taxonomy_term as $attr_key => $attr ): ?>
<option value="<?php echo esc_attr( $attr->slug ); ?>"
<?php if ( $attr->count == 0 && !$taxonomy_term[0]->numeric ) {
echo 'disabled="disabled"';
} ?>
data-disabled="<?php echo ( esc_attr( $attr->count ) == 0 && !$taxonomy_term[0]->numeric ) ? 'disabled' : "null" ?>">
<?php echo ( esc_attr( $taxonomy_term_key ) == "price" ) ? stm_listing_price_view( $attr->name ) : esc_attr( $attr->name ); ?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>
<?php endif; ?>
<?php endforeach; ?>
<div class="col-md-3 col-sm-6">
<div class="row">
<div class="col-md-8 col-sm-12">
<button type="submit" class="button icon-button">
<i class="stm-icon-search"></i><?php esc_html_e( 'Search', 'motors' ); ?>
</button>
</div>
<div class="col-md-4 hidden-sm hidden-xs">
<a href="" class="reset-all reset-styled"
title="<?php esc_html_e( 'Reset search fields', 'motors' ); ?>">
<i class="stm-icon-reset"></i>
</a>
</div>
</div>
</div>
</form>
If you want the parameters to show in the URL, then you need to use method GET, not POST.
And because your form action URL already contains GET parameters, what is explained under submitting a GET form with query string params and hidden params disappear also needs to be taken into account - those would get discarded, when the form is submitted, so the parameter needs to be supplied via a hidden field instead:
<input type="hidden" name="page_id" value="16410">
Related
I am currently customizing (or trying) the yourtheme/woocommerce/single-product/add-to-cart/variable.php in my theme however even though I've tried I can't seem to get rid of the table in the woocommerce code and replace it by divs and dropdown lists. I would like it to look like the sections below:
<!-- Product Section -->
<section>
<div class="container my-5 px-5 pt-4 bg-light">
<div class="row no-gutters">
<div class="col-md-5">
<img src="<?php bloginfo('template_directory'); ?>/assets/images/best-seller.jpg" class="img-fluid w-75 m-auto d-block"
alt="Best Seller">
</div>
<div class="col-md-7 pr-md-5">
<h1 class="main-heading my-4">BLACK MATTE JAR</h1>
<form>
<div class="form-row">
<div class="form-group col-md-7">
<label for="inputSize">Size</label>
<select id="inputSize" class="form-control">
<option selected>Big - 14 oz</option>
<option>Small - 10 oz</option>
</select>
</div>
<div class="form-group col-md-4 offset-md-1">
<label for="inputQuantity">Quantity</label>
<select id="inputQuantity" class="form-control">
<option selected>1 unit</option>
<option>2 unit</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-7">
<label for="inputFragrance">Fragrance</label>
<select id="inputFragrance" class="form-control">
<option selected><img src="<?php bloginfo('template_directory'); ?>/assets/images/icon-1.png" class="d-inline w-25">Peace
of mind</option>
<option>Refreshing</option>
</select>
</div>
<div class="form-group col-md-4 offset-md-1 mt-auto">
<div class="product-price pb-3">
<h5>Price <span class="float-right">25$</span></h5>
</div>
</div>
</div>
<button type="submit" class="btn btn-lg px-5 my-4">ADD TO CART</button>
</form>
</div>
</div>
</div>
</section>
So when I started all this, I managed to get all my product variations with the code below, however I couldn't figure out how to manage the woocommerce hooks and how to get the proper variation price when the user changed the dropdown list (so the code below was not using hooks at all)
`<div class="col-md-7 pr-md-5">
<h1 class="main-heading my-4"><?php the_title(); ?></h1>
<?php
/*** ADD TO CART DYNAMIC */
$attribute_keys = array_keys( $attributes );
$variations_json = wp_json_encode( $available_variations );
$variations_attr = function_exists( 'wc_esc_json' ) ? wc_esc_json( $variations_json ) : _wp_specialchars( $variations_json, ENT_QUOTES, 'UTF-8', true );
do_action( 'woocommerce_before_add_to_cart_form' ); ?>
<form class="variations_form cart" action="<?php echo esc_url( apply_filters( 'woocommerce_add_to_cart_form_action', $product->get_permalink() ) ); ?>" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint( $product->get_id() ); ?>" data-product_variations="<?php echo $variations_attr; // WPCS: XSS ok. ?>">
<div class="form-row">
<div class="form-group col-md-7">
<label for="inputSize">Size</label>
<select id="inputSize" class="form-control">
<?php
$product = wc_get_product( get_the_id() );
$size = $product->get_attribute('size');
$size_array = print_r ($size , TRUE);
$size_text = explode ('|', $size_array);
$aux_size = 0;
foreach ($size_text as $s_txt){
if ($aux ==0) {
?><option selected><?php echo $s_txt ?></option>
<?php
} else {
?><option><?php echo $s_txt ?></option>
<?php
}
}
?>
</select>
</div>
<div class="form-group col-md-4 offset-md-1">
<label for="inputQuantity">Quantity</label>
<select id="inputQuantity" class="form-control">
<option selected>1 Unit</option>
<option>2 Units</option>
<option>3 Units</option>
<option>4 Units</option>
<option>5 Units</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-7">
<label for="inputFragrance">Fragrance</label>
<select id="inputFragrance" class="form-control">
<?php
$fragrance = $product->get_attribute('fragrance');
$fragrance_array = print_r ($fragrance , TRUE);
$fragrance_text = explode ('|', $fragrance_array);
$aux_size = 0;
foreach ($fragrance_text as $f_txt){
if ($aux ==0) {
?><option selected><?php echo $f_txt ?></option>
<?php
} else {
?><option><?php echo $f_txt ?></option>
<?php
}
}
?>
</select>
</div>
<div class="form-group col-md-4 offset-md-1 mt-auto">
<div class="product-price pb-3">
<h5>Price <span class="float-right">25$</span></h5>
</div>
</div>
</div>
<button onclick="Add_to_cart(<?php $product?>)" type="submit" class="btn btn-lg px-5 my-4">ADD TO CART</button>`
Then I discovered the variable.php, so below is what I can't make it:
1 - can't seem to give the same look and feel as before (refer to first code shown in this post.
2 - When I replace in the below code the and by div's the first div on the first iteration gives me $attribute_name = null.
<?php foreach ( $attributes as $attribute_name => $options ) : ?>
<tr>
<td class="label"><label for="<?php echo esc_attr( sanitize_title( $attribute_name ) ); ?>"><?php echo wc_attribute_label( $attribute_name ); // WPCS: XSS ok. ?></label></td>
<td class="value">
3 - I can't seem to fetch the variation price upon user change the product attributes.
Did any of you managed to achieve this? If so could you share your code? I really hope this thread is cleaner and clearer. I've added till where I've got in the code below.
<div class="col-md-7 pr-md-5">
<h1 class="main-heading my-4"><?php the_title(); ?></h1>
<?php
/*** ADD TO CART DYNAMIC */
$available_variations = $product->get_available_variations();
$attributes = $product->get_variation_attributes();
$attribute_keys = array_keys( $attributes );
$variations_json = wp_json_encode( $available_variations );
$variations_attr = function_exists( 'wc_esc_json' ) ? wc_esc_json( $variations_json ) : _wp_specialchars( $variations_json, ENT_QUOTES, 'UTF-8', true );
do_action( 'woocommerce_before_add_to_cart_form' ); ?>
<form class="variations_form cart" action="<?php echo esc_url( apply_filters( 'woocommerce_add_to_cart_form_action', $product->get_permalink() ) ); ?>" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint( $product->get_id() ); ?>" data-product_variations="<?php echo $variations_attr; // WPCS: XSS ok. ?>">
<?php do_action( 'woocommerce_before_variations_form' );
?>
<?php if ( empty( $available_variations ) && false !== $available_variations ) : ?>
<p class="stock out-of-stock"><?php echo esc_html( apply_filters( 'woocommerce_out_of_stock_message', __( 'This product is currently out of stock and unavailable.', 'woocommerce' ) ) ); ?></p>
<?php else : ?>
<table class="variations" cellspacing="0">
<tbody>
<?php foreach ( $attributes as $attribute_name => $options ) : ?>
<tr>
<td class="label"><label for="<?php echo esc_attr( sanitize_title( $attribute_name ) ); ?>"><?php echo wc_attribute_label( $attribute_name ); // WPCS: XSS ok. ?></label></td>
<td class="value">
<?php
wc_dropdown_variation_attribute_options(
array(
'options' => $options,
'attribute' => $attribute_name,
'product' => $product,
)
);
?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="single_variation_wrap">
<?php
/**
* Hook: woocommerce_before_single_variation.
*/
do_action( 'woocommerce_before_single_variation' );
/**
* Hook: woocommerce_single_variation. Used to output the cart button and placeholder for variation data.
*
* #since 2.4.0
* #hooked woocommerce_single_variation - 10 Empty div for variation data.
* #hooked woocommerce_single_variation_add_to_cart_button - 20 Qty and cart button.
*/
do_action( 'woocommerce_single_variation' );
/**
* Hook: woocommerce_after_single_variation.
*/
do_action( 'woocommerce_after_single_variation' );
?>
</div>
<?php endif; ?>
Ive been trying to change it for days without any success I return back to the original code most of the time this is the reason why I made my first post here as I cannot add the price into this code, nor turn it as per my html design.
Sorry for the simple question but I can't find anyone online that have achieved this before.
I've managed to do it with the following code:
<?php endforeach; ?>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="">Quantity</label>
<div class="single_variation_wrap">
<?php
/**
* Hook: woocommerce_before_single_variation.
*/
do_action( 'woocommerce_before_single_variation' );
/**
* Hook: woocommerce_single_variation. Used to output the cart button and placeholder for variation data.
*
* #since 2.4.0
* #hooked woocommerce_single_variation - 10 Empty div for variation data.
* #hooked woocommerce_single_variation_add_to_cart_button - 20 Qty and cart button.
*/
do_action( 'woocommerce_single_variation' );
/**
* Hook: woocommerce_after_single_variation.
*/
do_action( 'woocommerce_after_single_variation' );
?>
</div>
</div>
<div class="form-group col-md-6 mt-6">
<div class="product-price pb-3">
<h5 >Price <?php echo $product->get_price_html(); ?></h5>
</div>
</div>
</div>
<?php endif; ?>
<?php do_action( 'woocommerce_after_variations_form' ); ?>
</form>
I've converted the tds into div's in an easy manner that is still identifiable by woocommerce. Furthermore I've managed to fetch the price as shown in the code.
Now I am only having one issue which is to force the user to stay in my custom page if no selection is made.
Hope someone can suport me
I am building an e-commerce shop using WordPress that uses Woocommerce. I have a custom page for products page that needs to hold the dropdowns menus (from the variation attribute). But the drop down does not appear. How can call those variations into this page.
This is my code for the single-product.php:
<?php
$attributes = $product->get_attributes();
?>
<div class="ProductViewing_DescSizing">
<div class="row">
<?php foreach ( $attributes as $attribute_name => $options ) : ?>
<?php $terms = get_the_terms($product->id, $attribute_name); ?>
<div class="col-sm-6">
<div class="form-group">
<label for="<?php echo sanitize_title( $attribute_name ); ?>"><?php echo wc_attribute_label( $attribute_name ); ?></label><!-- get attribute name per product -->
<select class="form-control">
<?php foreach ($terms as $value) { ?>
<option value="<?php echo $value->name; ?>"> <?php echo $value->name; ?></option>
<?php } ?>
</select>
</div>
</div>
<?php endforeach;?>
</div>
<div class="addtocart">
<input type="submit" name="" value="ADD TO CART" class="btn btn-red btn-addtocart">
</div>
SHOW Size guide
</div>
I have a custom post type called storylist, which is done as a plugin for a sidebar widget.The custom post type story list compiles lists of other custom post types and displays them in the sidebar. The same way the posts are displaying in the sidebar, I need to have that same list, which in this case is "hot topics" display on a page when the "view more" button is clicked. The best I got was an archive of all the storylist posts but when you click on them, such as hot topics, it take you to the url http://site/storylist/hot-topics , which is the correct url, but it's blank and only shows the title of the page. Any suggestions on how to make those posts appear on hot topics?
Here's the code to make it display in the widget:
<?php
// Prevent loading this file directly
defined( 'ABSPATH' ) || exit;
class ChemTabs extends WP_Widget {
function __construct() {
parent::__construct(
'tabs', _('Tabs Widget'),
array(
'description' => _('A tabs widget.'),
));
}
private function ce_getPostClass($style, $index) {
switch ($style) {
case 'first-up':
if ( $index == 0 ) return 'first-up';
else return 'list-type';
break;
default:
return $style;
}
}
private function ce_has($listStyle, $index, $post) {
$class = $this->ce_getPostClass($listStyle, $index);
$has = array(
'thumb' => false,
'terms' => true,
'date' => true,
'content' => false,
'excerpt' => false,
'title' => true,
'video' => false,
'webinarDate' => false
);
switch ($class) {
case 'first-up':
$has['thumb'] = true;
$has['excerpt'] = true;
break;
case 'list-type':
$has['terms'] = false;
break;
case 'thumblist':
$has['thumb'] = true;
break;
case 'single': // no need for this anymore probably
$has['content'] = true;
break;
}
switch ($post->post_type) {
case 'video':
$has['video'] = true;
break;
case 'webinar':
$has['webinarDate'] = true;
break;
}
return $has;
}
public function widget( $args, $instance ) {
global $post;
$instance['tab_1_title'] = isset($instance['tab_1_title'])?$instance['tab_1_title']:'Tab 1';
$instance['tab_2_title'] = isset($instance['tab_2_title'])?$instance['tab_2_title']:'Tab 2';
$instance['storylist_id_1'] = isset($instance['storylist_id_1']) ? $instance['storylist_id_1'] : '';
$instance['storylist_id_2'] = isset($instance['storylist_id_2']) ? $instance['storylist_id_2'] : '';
$instance['n'] = isset($instance['n']) ? $instance['n'] : 4;
$title = isset($instance['title'])?$instance['title']:'';
$type = isset($instance['type'])?$instance['type']:'color';
$class = isset($instance['class'])?$instance['class']:'brand-primary';
// Post list configuration
// Note: posts temporarily rendered with ajax
$list_style = isset($instance['listStyle'])?$instance['listStyle']:'thumblist';
$list_post_type = isset($instance['post_type'])?$instance['post_type']:'post';
$list_filter = isset($instance['filter'])?$instance['filter']:'{}';
$list_display = isset($instance['display'])?$instance['display']:5;
$list_channel = isset($instance['channel'])?$instance['channel']:0;
$list_division = isset($instance['division'])?$instance['division']:0;
$readmore = isset($instance['readmore'])?$instance['readmore'] : '';
$list_args1 = array( "post_type" => "any", "post__in" => get_post_meta($instance['storylist_id_1'], 'storylist', true), "orderby" => "post__in" );
$posts1 = new WP_Query();
$posts1 = $posts1->query($list_args1);
$list_args2 = array( "post_type" => "any", "post__in" => get_post_meta($instance['storylist_id_2'], 'storylist', true), "orderby" => "post__in" );
$posts2 = new WP_Query();
$posts2 = $posts2->query($list_args2);
// Note: posts temporarily rendered with ajax
echo $args['before_widget'];
$instance['tab_2_title'] = get_the_title($instance['storylist_id_2']);
//#TODO: Use get_template_part('content/post', $modifier); on tabs too.
?>
<div class="module tabs">
<div class="striped striped-gray">
<!-- Nav tabs -->
<ul class="nav nav-tabs nav-justified" role="tablist">
<li class="active">
<a href="#tab-pane-1" role="tab" data-toggle="tab">
<h2 class="h4"><?= $instance['tab_1_title'] ?></h2>
</a>
</li>
<li>
<a href="#tab-pane-2" role="tab" data-toggle="tab">
<h2 class="h4"><?= $instance['tab_2_title'] ?></h2>
</a>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane active" id="tab-pane-1">
<div class="post-list no-c-paginator" max="<?= $instance['n'] ?>">
<?php
$n = 0;
foreach((array)$posts1 as $post): setup_postdata($post);
$n++;
if ( $n % 3 == 1) {
?> <div class="no-c-container<?php echo $n == 1 ? ' active' : '';?>"> <?php
}
?>
<article class="article thumblist no-c-paginator-item">
<!-- thumbnail -->
<?php echo the_post_thumbnail('cm_thumb', array('class' => 'img-thumbnail pull-left', 'style' => 'margin-right: 0.5em;')) ?>
<header>
<!-- terms -->
<?php if (!empty($terms) ): ?>
<p class="terms">
<?= $terms[0]['name'] ?>
</p>
<?php endif; ?>
<!-- title -->
<h3 class="title"><?php echo apply_filters('the_title', the_title()); ?></h3>
<!-- Time -->
<div class="date-author">
<?php include(locate_template('UI/byline.php')); ?>
<span class="topic"><?php echo cm_get_single_topic() ?></span>
</div>
</header>
<div class="clearfix"></div><!-- to clear the thumbnail's left floating -->
</article>
<?php
if ( $n % 3 == 0) {
?> </div> <?php
}
endforeach; wp_reset_postdata();
if ( $n % 3 != 0) {
?> </div> <?php
}
?>
<?php if($readmore): ?>
<div class="actions">
<button href="<?php echo $readmore; ?>" class="btn btn-primary btn-xs">View More</button>
</div>
<?php endif; ?>
</div>
<div class="actions">
<button class="btn btn-primary prev-item" disabled="disabled"><i class="fa fa-chevron-circle-left"></i> Prev</button>
<button class="btn btn-primary next-item">Next <i class="fa fa-chevron-circle-right"></i></button>
</div>
</div>
<div class="tab-pane" id="tab-pane-2">
<div class="post-list no-c-paginator" max="<?= $instance['n'] ?>">
<?php
$n = 0;
foreach((array)$posts2 as $post):
$n++;
if ( $n % 3 == 1) {
?> <div class="no-c-container<?php echo $n == 1 ? ' active' : '';?> "> <?php
}
?>
<article class="article thumblist no-c-paginator-item">
<!-- thumbnail -->
<?php echo get_the_post_thumbnail($post->ID, 'cm_thumb', array('class' => 'img-thumbnail pull-left', 'style' => 'margin-right: 0.5em;')) ?>
<header>
<!-- terms -->
<?php if (!empty($terms) ): ?>
<p class="terms">
<?= $terms[0]['name'] ?>
</p>
<?php endif; ?>
<!-- title -->
<h3 class="title"><?php echo apply_filters('the_title', $post->post_title); ?></h3>
<!-- Time -->
<div class="date-author">
<time datetime="<?php the_time('c'); ?>" pubdate="pubdate" ><?php the_time('F j, Y'); ?></time>
<?php include(locate_template('UI/byline.php')); ?>
<span class="topic"><?php echo cm_get_single_topic() ?></span>
</div>
</header>
<div class="clearfix"></div><!-- to clear the thumbnail's left floating -->
</article>
<?php
if ( $n % 3 == 0) {
?> </div> <?php
}
endforeach;
if ( $n % 3 != 0) {
?> </div> <?php
}
?>
<?php //if($readmore): ?>
<div class="actions">
View More
</div>
<?php //endif; ?>
<!--<div class="actions">
<button class="btn btn-primary prev-item" disabled="disabled"><i class="fa fa-chevron-circle-left"></i> Prev</button>
<button class="btn btn-primary next-item">Next <i class="fa fa-chevron-circle-right"></i></button>
</div>-->
</div>
</div>
</div>
</div>
</div>
<?php
echo $args['after_widget'];
}
public function form( $instance ) {
$instance['tab_1_title'] = isset($instance['tab_1_title'])?$instance['tab_1_title']:'Tab 1';
$instance['tab_2_title'] = isset($instance['tab_2_title'])?$instance['tab_2_title']:'Tab 2';
$instance['n'] = isset($instance['n'])?$instance['n']:4;
$sl_posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'storylist'
));
?>
<h5>Tab 1</h5>
<p>
<label for="<?php echo $this->get_field_id( 'tab_1_title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'tab_1_title' ); ?>" name="<?php echo $this->get_field_name( 'tab_1_title' ); ?>" type="text" value="<?php echo esc_attr( $instance['tab_1_title'] ); ?>">
</p>
<p>
<label for="<?php echo $this->get_field_id( 'storylist_id_1' ); ?>"><?php _e( 'Story List:' ); ?></label>
<select id="<?php echo $this->get_field_id( 'storylist_id_1' ); ?>" name="<?php echo $this->get_field_name( 'storylist_id_1' ); ?>">
<?php
if (count($sl_posts)) {
foreach($sl_posts as $storyList) {
$selected = ($instance['storylist_id_1'] == $storyList->ID ? "selected='selected'" : "");
echo "<option value='{$storyList->ID}' {$selected}>{$storyList->post_title}</option>";
}
} else {
echo "<option value='0'>"._('No Story Lists Found')."</option>";
}
?>
</select>
</p>
<!-- Number of items to show -->
<p>
<label for="<?php echo $this->get_field_id( 'n' ); ?>"><?php _e( 'Number of items to show at once:' ); ?></label>
<input id="<?php echo $this->get_field_id( 'n' ); ?>" name="<?php echo $this->get_field_name( 'n' ); ?>" type="number" min="0" step="1" value="<?php echo intval($instance['n']) ?>">
</p>
<h5>Tab 2</h5>
<p>
<label for="<?php echo $this->get_field_id( 'tab_2_title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'tab_2_title' ); ?>" name="<?php echo $this->get_field_name( 'tab_2_title' ); ?>" type="text" value="<?php echo esc_attr( $instance['tab_2_title'] ); ?>">
</p>
<p>
<label for="<?php echo $this->get_field_id( 'storylist_id_2' ); ?>"><?php _e( 'Story List:' ); ?></label>
<select id="<?php echo $this->get_field_id( 'storylist_id_2' ); ?>" name="<?php echo $this->get_field_name( 'storylist_id_2' ); ?>">
<?php
if (count($sl_posts)) {
foreach($sl_posts as $storyList) {
$selected = ($instance['storylist_id_2'] == $storyList->ID ? "selected='selected'" : "");
echo "<option value='{$storyList->ID}' {$selected}>{$storyList->post_title}</option>";
}
} else {
echo "<option value='0'>"._('No Story Lists Found')."</option>";
}
?>
</select>
</p>
<?php
}
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['tab_1_title'] = isset($new_instance['tab_1_title'])?$new_instance['tab_1_title']:'Tab 1';
$instance['tab_2_title'] = isset($new_instance['tab_2_title'])?$new_instance['tab_2_title']:'Tab 2';
$instance['storylist_id_1'] = isset($new_instance['storylist_id_1']) ? (int)$new_instance['storylist_id_1'] : 0;
$instance['storylist_id_2'] = isset($new_instance['storylist_id_2']) ? (int)$new_instance['storylist_id_2'] : 0;
$instance['n'] = isset($new_instance['n']) ? (int)$new_instance['n'] : 4;
return $instance;
}
}
add_action( 'widgets_init', function(){ register_widget( 'ChemTabs' ); });
Is there any way I can make a page template displaying the page id? I tried to do that but it didn't display anything.
I solved this by adding this code $list_args2 = array( "post_type" => "any", "post__in" => get_post_meta( 210639, 'storylist', true), "orderby" => "post__in", 'post_status' => 'publish' );
I'm pretty new to Wordpress and I've been building a theme with reverie-master but the only problem is the search page. All the other pages, category, archive, etc are working.
I use this for searching in my header.php :
<form method="post" action="<?php echo home_url('/'); ?>" class="search-form" role="search">
<div class="small-9 columns no-pad">
<input type="text" class="search-input" name="s" placeholder="Search" value="" />
</div>
<div class="small-3 columns no-pad">
<input class="btn-submit postfix search-input" type="submit" value=""/>
</div>
This shows the search results on the homepage. If I type in "ok" in the search bar it takes me to example : www.homepage.com when it should be on www.homepage.com/?s=ok. The problem with it being on the home page, the paginations will take you to page 2 of the home blog feed instead on www.homepage.com/page/2/ when it should be something ilke this www.homepage.com/page/2/?s=test
When I manualy type in this url in the browser : www.homepage.com/page/2/?s=test the pagination is working. My problem is the pagination and I am wondering why the posts displays on the homepage(which I assume is the problem)
Here is my search.php code :
Starts with <?php get_header(); ?> and ends with <?php get_footer(); ?>
This is the loop in between with pagination :
<h2><?php _e('Search Results for', 'reverie'); ?> "<?php echo get_search_query(); ?>"</h2>
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="row pad-row">
<div class="large-11 columns bor-bottom">
<a class="fade" href="<?php the_permalink(); ?>"><p class="feed-title"><?php the_title(); ?></p></a>
<p class="feed-info">By <span class="feed-author"><?php the_author(); ?> </span> <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?>
<?php
foreach((g_the_category()) as $category) {
if ($category->cat_name != 'featured') {
echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> ';
}
}
?>
<span class="feed-cmt"><?php comments_number( '0 Comments', '1 Comments', '% Comments' ); ?>. </span></p>
<?php the_excerpt(); ?>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; // end have_posts() check ?>
<!-- Start Pagination -->
<div class="row pad-row">
<div class="large-11 columns pagination-centered large-centered panel-page">
<?php /* Display navigation to next/previous pages when applicable */ ?>
<?php if ( function_exists('reverie_pagination') ) { reverie_pagination(); } else if ( is_paged() ) { ?>
<nav id="post-nav">
<div class="post-previous"><?php next_posts_link( __( '← Older posts', 'reverie' ) ); ?></div>
<div class="post-next"><?php previous_posts_link( __( 'Newer posts →', 'reverie' ) ); ?></div>
</nav>
<?php } ?>
</div>
</div>
Do not put search form directly. WP has a functionality to get search form called get_search_form(). This function prints wp basic search form, but still you can customize this. In order to customize, you can use a filter called get_search_form.
function custom_search_form( $form ) {
$form = '<form method="get" action="' . home_url('/') . '" class="search-form" role="search">
<div class="small-9 columns no-pad">
<input type="text" class="search-input" name="s" id="s" placeholder="Search" value="' . get_search_query() . '" />
</div>
<div class="small-3 columns no-pad">
<input class="btn-submit postfix search-input" id="searchsubmit" type="submit" value="'. esc_attr__( 'Search' ) .'"/>
</div>
</form>';
return $form;
}
add_filter( 'get_search_form', 'custom_search_form' );
And put this to functions.php
Everytime when I try to search on my website, it keeps returning to the homepage. I have a search form though, built-in with my theme. Can't find the problem. Can you help me?
<?php get_header(); ?>
<div class="content">
<?php tie_breadcrumbs(); ?>
<div class="page-head">
<h2 class="page-title">
<?php if ( have_posts() ) : ?>
<?php printf( __( 'Search Results for: %s', 'tie' ), '<span>' . get_search_query() . '</span>' ); ?>
<?php else : ?>
<?php _e( 'Nothing Found', 'tie' ); ?>
<?php endif; ?>
</h2>
<div class="stripe-line"></div>
</div>
<?php if ( have_posts() ) : ?>
<?php get_template_part( 'loop', 'search' ); ?>
<?php if ($wp_query->max_num_pages > 1) tie_pagenavi(); ?>
<?php else : ?>
<div id="post-0" class="post not-found post-listing">
<div class="entry">
<p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'tie' ); ?></p>
</div>
</div>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
This is the website: http://plugr.nl
Addition: The HTML
<?php if(tie_get_option( 'top_right' ) == 'search'): ?>
<div class="search-block">
<form method="get" id="searchform" action="<?php echo home_url(); ?>/">
<button class="search-button" type="submit" value="<?php if( !$is_IE ) _e( 'Search' , 'tie' ) ?>"></button>
<input type="text" id="s" name="s" value="<?php _e( 'Search...' , 'tie' ) ?>" onfocus="if (this.value == '<?php _e( 'Search...' , 'tie' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search...' , 'tie' ) ?>';}" />
</form>
</div><!-- .search-block /-->
Looks like this search URL is what your template is expecting:
http://plugr.nl/?s=waar
Your form has code like:
<form method="get" id="searchform" action="http://plugr.nl/">
<input type="text" name="inputBox" placeholder="Typ wat je zoekt en druk op enter">
</form>
Change the input name to "s" and see what that does for you.
You might need to grep through the files in your template to find where this form is actually generated. Nested template files will not show up in the wordpress GUI editor. It's also possible your search form is provided through a widget which the template depends on, so you might need to dig a little further.
You need to place "s" for the name value...name="s". Its a default setting for wordpress which will detect this variable for what kind of search you did.. /?s="whatever you searched for"