Customize no result page - wordpress

I have a problem with no result page. I have a search box, if you find something then u can see "Search result : ", but if u didnt find then u can see "No Search result : ". I want to remove this NO before search result, but I dont find any solution for this. I tried already many different functions and css, but nothing .. I want to remove this NO, or whole this line (No search result : ).
This is what I have atm in functions.php
add_filter( 'tc_search_results_title' , 'my_search_results_title');
function my_search_results_title(){
$my_search_results_title = __('Search result :', 'customizr-child');
return $my_search_results_title;
}
add_filter('tc_breadcrumb_trail_items', 'search_results_breadcrumb');
function search_results_breadcrumb( $trail ){
if ( ! is_search() )
return $trail;
$_last = sizeof($trail) - 1;
$_search_string = __('Search result: ', 'customizr-child');
/* or you an use the function used for that other snippet to have the same title, in this case remove the comment of the line below */
// $_search_string = my_search_results_title();
if ( is_paged() )
$trail[$_last] = '' . sprintf( '%2$s "%1$s"' , esc_attr( get_search_query() ), $_search_string ) . '';
else
$trail[$_last] = sprintf( '%2$s "%1$s"', esc_attr( get_search_query() ), $_search_string );
return $trail;
}
add_filter( 'tc_no_result_content', 'my_no_result_content');
function my_no_result_content() {
return '<div class="tc-content span12"><h1>Didnt find anything, try again</h1></div>';
}
I use Customizr child theme in Wordpress
Maybe somebody can help me with this.
Thanks !

You're using the wrong filter. You'll have to use tc_search_results_header_content instead and replace the No string. You can also use to original part of code and remove the unwanted part, something like:
function my_search_results_header_content ($content) {
return sprintf( '<div class="row-fluid"><div class="%1$s"><h1 class="%2$s">%3$s%4$s %5$s </h1></div><div class="%6$s">%7$s</div></div>',
apply_filters( 'tc_search_result_header_title_class', 'span8' ),
apply_filters( 'tc_archive_icon', 'format-icon' ),
'', // Original uses: have_posts() ? '' : __( 'No' , 'customizr' ).' ' ,
apply_filters( 'tc_search_results_title' , __( 'Search Results for :' , 'customizr' ) ),
'<span>' . get_search_query() . '</span>',
apply_filters( 'tc_search_result_header_form_class', 'span4' ),
have_posts() ? get_search_form(false) : ''
);
}
add_filter('tc_search_results_header_content', 'my_search_results_header_content');
Hope it helps.

Related

Add image title and/or description to the caption

Is it possible to manipulate the output of the image captions within the_content in such a way that not only the caption, but also the image title and/or description (defined in the media library) are output under each image?
Possibly via the functions.php?
Yes it is possible to manipulate the on the_content.
The easiest way which it looks like you are wanting to do is add a filter in your functions.php file.
I just pulled this from the Codex and modified a bit so you can get the gist of what I'm talking about.
add_filter( 'img_caption_shortcode', 'my_img_caption_shortcode', 10, 3 );
function my_img_caption_shortcode( $output, $attr, $content ) {
$attr = shortcode_atts( array(
'id' => '',
'align' => 'alignnone',
'width' => '',
'caption' => ''
), $attr );
if ( 1 > (int) $attr['width'] || empty( $attr['caption'] ) ) {
return '';
}
if ( $attr['id'] ) {
$attr['id'] = 'id="' . esc_attr( $attr['id'] ) . '" ';
}
return '<div ' . $attr['id']
. 'class="wp-caption ' . esc_attr( $attr['align'] ) . '" '
. 'style="max-width: ' . ( 10 + (int) $attr['width'] ) . 'px;">'
. do_shortcode( $content )
. '<p class="wp-caption-text">' . $attr['caption'] . '</p>'
. '</div>';
}
What you can then do is if you see the $attr['caption'], you can modify how you would like it to be. So you can do: get_the_title($attr['id']) to add the title or get_post_meta($attr['id'], '_wp_attachment_image_alt', TRUE); to get the image alt.
To make things easier if you want to grab all the details on a specific attachment you can use a function like this and then get whatever you want.
Here's an example of adding the title to your caption. The format is "Title - Caption"
. '<p class="wp-caption-text">' . get_the_title($attr['id']) . " - " . $attr['caption'] . '</p>'
Link to Code reference: https://developer.wordpress.org/reference/hooks/img_caption_shortcode/
Maybe i'm not understanding your question but it seems to me that you're using the Gutenberg editor?
... All the features you're looking for are already built-in.
If you want to set the alt="" or title="" attributes you can do it on the right side action column, by clicking on the image itself, while in the Gutenberg editor.
For the figcaption, you can set it right under the image, by clicking on the image itself, while in the Gutenberg editor.

Problem with parentheses in Woocommerce cart page

I have a problem with Woocommerce + "Yith deposits and down payments" plugin.
The page shows:
$26.997
(of
$93.980
)
And I need the site shows this:
$26.997
(of)
$93.980
This is the code from this part:
if( $grand_total ) {
$total_html .= apply_filters( 'yith_wcdp_show_cart_total_html', sprintf( ' (%s <strong>%s</strong>)', __( 'of', 'yith-woocommerce-deposits-and-down-payments' ), wc_price( $grand_total ) ), WC()->cart );
}
Any idea how to fix this problem?
Thank you.
Update this part sprintf( ' (%s) <strong>%s</strong>'
Try this code
if( $grand_total ) {
$total_html .= apply_filters( 'yith_wcdp_show_cart_total_html', sprintf( ' (%s) <strong>%s</strong>', __( 'of', 'yith-woocommerce-deposits-and-down-payments' ), wc_price( $grand_total ) ), WC()->cart );
}

How to search in WordPress content instead of title only

I'm using the following query/code for a custom WordPress search-plugin.
add_filter( 'posts_where', 'title_like_posts_where', 10, 2 );
function title_like_posts_where( $where, &$wp_query ) {
global $wpdb;
if ( $post_title_like = $wp_query->get( 'post_title_like' ) ) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'' . esc_sql( $wpdb->esc_like( $post_title_like ) ) . '%\'';
}
return $where;
}
But it is only searching in the post-titles, where I want it to search in both the title and the content.
If I simply change the word 'title' with the word 'content', it doesn't work.
Anyone knows what I have to do in order to make the query search in both the title and the content?

Woocommerce - Display single product attribute(s) with shortcodes in Frontend

i've read many Q/A's here during the last few days, but unfortunately none of them solved my issue.
I'm trying to fetch product attributes and display them on the frontend with a shortcode. I have managed to display ALL available attributes and display them in a list, but i need to select only one or two of them in different locations (thats why using shortcodes). For example like [shortcode_attribute name="brand"].
Any help is highly appreciated!
my code so far:
function tutsplus_list_attributes( $product ) {
global $product;
global $post;
$attributes = $product->get_attributes();
if ( ! $attributes ) {
return;
}
foreach ( $attributes as $attribute ) {
// Get the taxonomy.
$terms = wp_get_post_terms( $product->id, $attribute[ 'name' ], 'all' );
$taxonomy = $terms[ 0 ]->taxonomy;
// Get the taxonomy object.
$taxonomy_object = get_taxonomy( $taxonomy );
// Get the attribute label.
$attribute_label = $taxonomy_object->labels->name;
// Display the label followed by a clickable list of terms.
echo get_the_term_list( $post->ID, $attribute[ 'name' ] , '<div><li class="bullet-arrow">' . $attribute_label . ': ' , ', ', '</li></div>' );
}
}
add_action( 'woocommerce_product_meta_end', 'tutsplus_list_attributes' );
add_shortcode('display_attributes', 'tutsplus_list_attributes');
While I am still not 100% clear what you're after, what I'm going to create is a shortcode that creates a list of all terms in all attributes. To make it more flexible I'll add support for a shortcode parameter so you can create a list of specific attribute terms.
One major thing you need to alter from your code, is that shortcodes need to RETURN a string and not ECHO out html. Echoing out shortcodes can result in unexpected weirdness.
/**
* Attributes shortcode callback.
*/
function so_39394127_attributes_shortcode( $atts ) {
global $product;
if( ! is_object( $product ) || ! $product->has_attributes() ){
return;
}
// parse the shortcode attributes
$args = shortcode_atts( array(
'attributes' => array_keys( $product->get_attributes() ), // by default show all attributes
), $atts );
// is pass an attributes param, turn into array
if( is_string( $args['attributes'] ) ){
$args['attributes'] = array_map( 'trim', explode( '|' , $args['attributes'] ) );
}
// start with a null string because shortcodes need to return not echo a value
$html = '';
if( ! empty( $args['attributes'] ) ){
foreach ( $args['attributes'] as $attribute ) {
// get the WC-standard attribute taxonomy name
$taxonomy = strpos( $attribute, 'pa_' ) === false ? wc_attribute_taxonomy_name( $attribute ) : $attribute;
if( taxonomy_is_product_attribute( $taxonomy ) ){
// Get the attribute label.
$attribute_label = wc_attribute_label( $taxonomy );
// Build the html string with the label followed by a clickable list of terms.
// Updated for WC3.0 to use getters instead of directly accessing property.
$html .= get_the_term_list( $product->get_id(), $taxonomy, '<li class="bullet-arrow">' . $attribute_label . ': ' , ', ', '</li>' );
}
}
// if we have anything to display, wrap it in a <ul> for proper markup
// OR: delete these lines if you only wish to return the <li> elements
if( $html ){
$html = '<ul class="product-attributes">' . $html . '</ul>';
}
}
return $html;
}
add_shortcode( 'display_attributes', 'so_39394127_attributes_shortcode' );
Usage: This would be used in 1 of 2 ways.
First, to display specific attributes use:
[display_attributes attributes="color|material"]
Second, to display all attributes use:
[display_attributes]
Edit
Here's an always single display edition:
/**
* Attribute shortcode callback.
*/
function so_39394127_singular_attribute_shortcode( $atts ) {
global $product;
if( ! is_object( $product ) || ! $product->has_attributes() ){
return;
}
// parse the shortcode attributes
$args = shortcode_atts( array(
'attribute' => ''
), $atts );
// start with a null string because shortcodes need to return not echo a value
$html = '';
if( $args['attribute'] ){
// get the WC-standard attribute taxonomy name
$taxonomy = strpos( $args['attribute'], 'pa_' ) === false ? wc_attribute_taxonomy_name( $args['attribute'] ) : $args['attribute'];
if( taxonomy_is_product_attribute( $taxonomy ) ){
// Get the attribute label.
$attribute_label = wc_attribute_label( $taxonomy );
// Build the html string with the label followed by a clickable list of terms.
// Updated for WC3.0 to use getters instead of directly accessing property.
$html .= get_the_term_list( $product->get_id(), $taxonomy, $attribute_label . ': ' , ', ', '' );
}
}
return $html;
}
add_shortcode( 'display_attribute', 'so_39394127_singular_attribute_shortcode' );
This removes all HTML markup, and so you'd need to provide your own... which would happen if you are making a custom list.
<ul>
<li class="arrow">Static List Item</li>
<li class="arrow">[display_attribute attribute="color"]</li>
<ul>
EDIT: This code can be added to your theme's functions.php, but preferably either in a site-specific plugin or via the Code Snippets plugin.
If anyone else just wants to simply output the attribute value as text, replace the $html .= line with this:
$html .= strip_tags(get_the_term_list($product->get_id(), $taxonomy));
#helgatheviking There must be a more elegant way than this! :)
Needed this recently - found https://wordpress.org/plugins/wcpas-product-attributes-shortcode/ does the trick.
With this plugin you can set an "attribute" parameter to match one of the product attributes you have setup.
For example if you have a brand attribute you can use:
[wcpas_product_attributes attribute="brand"]
This will output a <ul> list containing all brands.
There are also a number of parameters you can use alongside the attribute including:
orderby (order the list by an orderby value)
order (order asc, desc, rand, etc)
hide_empty (hide empty terms)
show_counts (show the total number of products in the brand)
archive_links (use an archive based URL instead of a filter based URL)
min_price (When using archive_links = 0 you can have a price filter based URL off a minimum price)
max_price (When using archive_links = 0 you can have a price filter based URL off a maximum price)

Get nav menu item custom field value

I have a custom walker for my navigation menu, inside which I want to get the menu item custom field value to further customize my menu items. Here is my code..
My menu item custom field is menu-item-mymenucolor
and I want to get its value in $menu_color (currently I get blank!)
wp_nav_menu( array(
'menu' => 'primary',
'walker' => new WPDocs_Walker_Nav_Menu()
)
);
// Custom Nav Menu walker class.
class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
function start_lvl( &$output, $depth = 0, $args = array() ) {
// Depth-dependent classes.
$indent = ( $depth > 0 ? str_repeat( "\t", $depth ) : '' ); // code indent
$display_depth = ( $depth + 1); // because it counts the first submenu as 0
// Custom nav menu item custom field value i want to get in the $classes.
$menu_color = '"style="background-color: '.get_post_meta($item->ID, 'menu-item-mymenucolor', true).';';
// Combine values of classes.
$classes = array(
'dropdown-menu',
( $display_depth % 2 ? 'menu-odd' : 'menu-even' ),
( $display_depth >=2 ? 'sub-sub-menu' : '' ),
'menu-depth-' . $display_depth,
''. $menu_color
);
$class_names = implode( ' ', $classes );
// Build HTML for output.
$output .= ($depth == 0) ? "\n" . $indent . '<ul class="' . $class_names . '">' . "\n" . "\n <div class=\"megamenu-content\">\n" . "\n<div class=\"row\">\n" : "\n<ul class=\"elementy-ul\">\n";
}
// Start the element output codes from here.....
}
Actually I can easily get the value of Woocommerce in the $menu_color place by just inserting the $woocommerce global variable, so is there anything to do with global variables? here take a look at this,
global $woocommerce;
// get cart quantity
$cart_qty = $woocommerce->cart->get_cart_contents_count();
$classes = array(
'dropdown-menu',
( $display_depth % 2 ? 'menu-odd' : 'menu-even' ),
( $display_depth >=2 ? 'sub-sub-menu' : '' ),
'menu-depth-' . $display_depth,
''. $cart_qty
);
Whereas, its much easier to get the menu item custom field value inside start element of this walker section, I will just post an important part of the code to make it short. I hope you understand where it must have been..
$item_output .= '<a'. $attributes .' style="background-color: '.get_post_meta($item->ID, 'menu-item-mymenucolor', true).';">';
$item_output .= '</a>';
I have tried almost every possibilities to get the value but none could work as of now. I know this will absolutely work like a charm, but I think i am missing something important here.
So, Is there any way this can be achieved?
Thanks!
You need to use $item->object_id instead of $item->ID and everything will work fine.
Maybe this is a late answer but since no one answered till now I thought it's a good idea to answer it, maybe it will help someone else too.

Resources