woo_breadcrumbs function and custom-post-type - wordpress

I am using the woo_breadcrumbs function and need to insert the name of the curent custom post type. Currently it is showing the home page + category, Home -> Category . Is there a simple way to call the name of the current Custom-Post-Type and insert it between home and category? The function inside the admin-fuction.php file in functions folder.
Thanks!!

So far I have found the following, hope it helps. This is written to be specific to a single taxonomy:
add_filter( 'woo_breadcrumbs_args', 'woo_video_filter_breadcrumbs_args', 10 );
if ( ! function_exists( 'woo_video_filter_breadcrumbs_args' ) ) {
function woo_video_filter_breadcrumbs_args( $args ) {
$args['singular_video_taxonomy'] = 'videos';
return $args;
}
}

Related

Woocommerce choose grid or list view for each category

I want the possibility to choose between grid and list view for each Woocommerce category. I have found this plugin: https://nl.wordpress.org/plugins/woocommerce-grid-list-toggle/
However, the plugin is meant for the shopper to choose whether to display items in grid view or list view. What I truly want is the ability to assign a view for each category in the back-end.
Example:
Category A is displayed as grid
Category B is displayed as list
Breaking my head over this.
Similar to this question you need to filter template_include. You need to call your custom archive template archive-list-view.php and save it in your theme's woocommerce folder. Obviously, you can name it anything you like, you will just have to adjust the code below to match.
Folder structure:
/theme-folder/functions.php
/theme-folder/woocommerce/archive-list-view.php
On the template_include filter we will check if we are on the term archive for the nussmylch product category. If so, we'll look for and supply the new template. Otherwise, the standard template is used.
EDIT: incorrect WooCommerce function is_product_taxonomy() was used. is_product_category() is needed to check for a specific category.
add_filter( 'template_include', 'so_33615903_custom_category_template', 20 );
function so_33615903_custom_category_template( $template ) {
// check you are on the taxonomy archive for specific category
if ( is_product_category( 'nussmylch' ) ) {
$new_template = locate_template( array( 'woocommerce/archive-list-view.php' ) );
if ( '' != $new_template ) {
$template = $new_template ;
}
}
return $template;
}
Working Example

Include only specific categories in WooCommerce product categories widget

I'm using WooCommerce plugin for Wordpress. It comes with a widget called WooCommerce Product Categories which can display a drop-down of all your product categories. I have searched online and found the following code which will exclude certain categories from appearing, categories with ID 16 and 20 in this snippet:
add_filter( 'woocommerce_product_categories_widget_args', 'woo_product_cat_widget_args' );
function woo_product_cat_widget_args( $cat_args ) {
$cat_args['exclude'] = array('16','20');
return $cat_args;
}
What I need is the opposite. I want a filter/function similar to above, but which enables me to specify which categories to include - i.e. exclude everything but the IDs that I specify.
You can try this;
add_filter( 'woocommerce_product_categories_widget_args', 'woo_product_cat_widget_args' );
function woo_product_cat_widget_args( $cat_args ) {
$cat_args['include'] = array('16','20');
return $cat_args;
}
actually you can use any of these arguments that listed on this page https://codex.wordpress.org/Template_Tags/wp_list_categories
Hope that helps!

Translate product category|tag title for JigoShop with qTranslate

qTranslate creates additional language fields for products pages in JigoShop but not also for category|tags product as it does for posts.
If I put in the title of a menu item <!--:en-->title<!--:--><!--:fr-->title<!--:--> i'll get the translation I want. But when creting a new category|tag title the <!--:--> is striped out. How can I enable comments tags for cat|tag title?
Another option is to use [:en]Title[:fr]Titre in the same title field when creating a new category|tag product. On the admin panel I see the proper text for the language selected but for end user i see [:en]Title[:fr]Titre.
I found this link https://wordpress.stackexchange.com/questions/28165/translating-a-custom-taxonomy and according to this answer http://www.qianqin.de/qtranslate/forum/viewtopic.php? f=4&t=2045&start=0#p7380 I addet in functions.php
add_action('jigoshop_add_form', 'qtrans_modifyTermFormFor');
add_action('jigoshop_edit_form', 'qtrans_modifyTermFormFor');
Did not work. I don't see aditional translations fields for categories|tags in JigoShop.
The basic question is:
How do I translate product categories|tags in JigoShop using qTranslate?
I was having very similar problem. I found a solution here: http://www.qianqin.de/qtranslate/forum/viewtopic.php?f=3&t=4064&start=10#p12940
Basically, all you have to do is to rename all the categories as suggested in the answer above, then add to your theme's functions.php file:
function p_filter_categories( $categories ) {
if ( is_array( $categories ) ) {
foreach ( $categories as $i => $cat ) {
$categories[ $i ]->name = __( $cat->name );
}
} else {
$categories->name = __( $categories->name );
}
return $categories;
}
add_filter( 'get_the_categories', 'p_filter_categories', 10 );
add_filter( 'get_the_terms', 'p_filter_categories', 10 );
add_filter( 'get_term', 'p_filter_categories', 10 );
Hope that helps!
Not the ideal solution but works.
In JigoShop/edit product category/name:
[:en] Big [:fr] Grand
In functions.php
function translate_q ($echo) {
if (function_exists('qtrans_split')) {
$selectLanguage = qtrans_split($echo);
return $selectLanguage[qtrans_getLanguage()];
} else {
return $echo;
}
}
qtrans_split and qtrans_getLanguage are functions created by qTranslate.
From JigoShop plugin directory I opened jigoshop_template_functions.php, I grabbed from jigoshop_breadcrumb() function all the echos in $echo variable and at the end I have:
echo function_exists('translate_q') ? translate_q($echo) : $echo;
You will have to do the same thing in other places in JigoShop. I posted here to be a starting point.

Exclude specific post from WP-feed

I know that you can generate a feed using urls like: ?cat=3&feed=rss2
And you can switch it around to exclude the category 3 by putting a subtract sign in front: ?cat=-3&feed=rss2
But, it doesn't look like you can do the same for posts? I'm using the JW video Player and have loaded the related plugin. The related plugin can take an rss-feed (media rss) as the parameter so it can link to other videos/wordpress posts that are related.
My problem is that currently this means that the active video also appears in the related videos feed.
What would be the best solution for solving this problem? I aim to create my own rss feed generator in the future, but for now I just want to keep it simple and use the generated feeds that wordpress creates. Is there a simple way to add support for an url parameter named post for example? It could then take post=-7 to exclude post with id 7 from displaying in the feed.
Or is there better solutions for this?
You can use a function
function exclude_category($query){
if ( $query->is_home || $query->is_feed || $query->is_archive ) {
$query->set('cat', '-1');
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category');
see'a
Instead of explaining the mechanisem - there are many plugins just for that ..
One that I know is :
StelthPubish
Edit I
I do not know about the URL - but you can try use the
function ok9_feed_filter($query) {
if ( !$query->is_admin && $query->is_feed) {
$query->set('post__not_in', array(15, 6) ); // page /post id
}
return $query;
}
add_filter( 'pre_get_posts', 'ok9_exclude_filter' );
or this
function ok9_feed_exlude($where, $wp_query = NULL) {
global $wpdb;
if ( !$wp_query )
global $wp_query;
if ($wp_query->is_feed) {
// exclude post id
$where .= " AND $wpdb->posts.ID NOT IN (15, 6)";
}
return $where;
}
add_filter( 'posts_where','ok9_feed_exlude', 1, 2 );
If you do not want to use a fixed id in the function - you can always add a custom field in the posts you want to exclude , and use that in the query ..

How can I select books randomly in Now Reading wordpress plugin?

I am using 'Now Reading' plugin in a wordpress project. In plugin's sidebar template I am using this query:
while( have_books('status=read&orderby=finished&num=2') ) : the_book();
to select 2 books.
What parameter should I pass to make it random? I tried with 'order=rand' and 'rand=true' but it did not work.
Any help will be appreciated!
Thanks in advance..
A random function doesn't actually exist. I have used this code, in my themes functions.php to allow random order before - not sure if it'll work in this situation, but worth a try.
Add this to your themes functions.php file:
function query_random_posts($query) {
return query_posts($query . '&random=true');
}
class RandomPosts {
function orderby($orderby) {
if ( get_query_var('random') == 'true' )
return "RAND()";
else
return $orderby;
}
function register_query_var($vars) {
$vars[] = 'random';
return $vars;
}
}
add_filter( 'posts_orderby', array('RandomPosts', 'orderby') );
add_filter( 'query_vars', array('RandomPosts', 'register_query_var') );
Then try this in your sidebar file:
while( have_books('status=read&orderby=finished&num=2&random=true') ) : the_book();
If not, my only other suggestion would be to get the 10 latest books, add them all to a new array, and then shuffle that array. May be a bit bloated though.

Resources