Flexslider thumbnail with more 4 image don't slide - php

I am creating a site with woocomerce and wordpress, and I have a product with 6 related images and instead of showing 4 images the flex slider shows me the 6 images in two lines. I tried using this filter to change the flexslider settings but I can't find a way to make it a slider.
I have the images inside a li inside a ol with class="flex-control-nav flex-control-thumbs"
add_filter( 'woocommerce_single_product_carousel_options', 'ud_update_woo_flexslider_options' );
function ud_update_woo_flexslider_options( $options ) {
$options['directionNav'] = true;
$options['sync'] = '.flex-control-thumbs';
$option['minItems']=0;
$option['maxItems']=4;
$option['animaton']='slide';
$option['itemWidth']=': 210';
return $options;
}
Thank you.

Did you sort this in the end? I also came across the same issue and so far I've found the following.
The FlexSlider 2 jQuery plugin is being used for the primary image and thumbnails on the WooCommerce product page. Specifically this example is being used - the "Slider w/thumbnail controlNav pattern"
Slider w/thumbnail controlNav pattern
This is what produces the unorder list mark-up you mention:
<ol class="flex-control-nav flex-control-thumbs">
<li><img/></li>
</ol>
But I haven't found an option to enable a horizontal scroll for this mark up generated for the thumbnails via FlexSlider 2. This would be the simplest solution here if there was an option. By default, there's no horizontal scroll and thumbnails display on multiple rows.
However, it looks like if we can change how WooCommerce uses Flexslider we can use the "Slider w/thumbnail slider" example form the FlexSlider website instead:
Slider w/thumbnail slider
I've been able to make progress with this and using the "woocommerce_single_product_carousel_options" filter you have done is correct but going slightly further:
add_filter( 'woocommerce_single_product_carousel_options', 'ud_update_woo_flexslider_options' );
function ud_update_woo_flexslider_options( $options ) {
$options['sync'] = '#our_own_thumnail_markup';
$options['controlNav'] = false;
return $options;
}
Note the "controlNav" option. This should be changed to false so the jQuery plugin doesn't automatically generate it's own thumbnails.
And taking the "Slider w/thumbnail slider" example from the FlexSlider website we need to generate our own markup for thumbnails just before the last closing div in "woocommerce/single-product/product-image.php" in our theme:
$attachment_ids = $product->get_gallery_image_ids();
if ( $attachment_ids && $product->get_image_id() ) {
echo '<div id="our_own_thumnail_markup">';
foreach ( $attachment_ids as $attachment_id ) {
echo wc_get_gallery_image_html( $attachment_id );
}
echo '</div>';
}
And call the following via jQuery:
$('#our_own_thumnail_markup').flexslider({
animation: "slide",
controlNav: false,
animationLoop: false,
slideshow: false,
itemWidth: 210,
itemMargin: 5,
asNavFor: '.woocommerce-product-gallery__wrapper'
});
I haven't got this to work but I think I'm heading in the right direction.

Related

How to repair the top navigation bar sticky position?

I use a WP 5.3 Twenty Seventeen child theme, but I don't want to edit templates, so I added a needed second (in fact it became the first in the displaying order) div wrap section to the top navigation menu with the bellow function. The problem is that I lost after this the fixed position of the menu (it is not sticky anymore now). How to remediate this? I played with the CSS code, but without success. The site in discussion is here.
function my_navigation_top( $slug, $name ) {
if( $name == 'top' ) { ?>
--- some content here ---
</div> <!-- wrap closed -->
<div class="wrap"> <!-- wrap opened -->
<?php }
}
add_action( 'get_template_part_template-parts/navigation/navigation', 'my_navigation_top', 10, 2 );
UPDATE
If instead of a second div wrap section I add a simple div section inside the wrap, the problem doesn't appear.
I am looking at the script file that sets the fixed class (that makes the top nav sticky when scrolling down). (File: twentyseventeen/assets/js/global.js)
And It seems the fixed class is not set if the height of the nav is too tall:
// Set properties of navigation.
function setNavProps() {
navigationHeight = $navigation.height();
navigationOuterHeight = $navigation.outerHeight();
navPadding = parseFloat( $navWrap.css( 'padding-top' ) ) * 2;
navMenuItemHeight = $navMenuItem.outerHeight() * 2;
idealNavHeight = navPadding + navMenuItemHeight;
navIsNotTooTall = navigationHeight <= idealNavHeight;
}
// Make navigation 'stick'.
function adjustScrollClass() {
// Make sure we're not on a mobile screen.
if ( 'none' === $menuToggle.css( 'display' ) ) {
// Make sure the nav isn't taller than two rows.
if ( navIsNotTooTall ) {
// When there's a custom header image or video, the header offset includes the height of the navigation.
if ( isFrontPage && ( $body.hasClass( 'has-header-image' ) || $body.hasClass( 'has-header-video' ) ) ) {
headerOffset = $customHeader.innerHeight() - navigationOuterHeight;
} else {
headerOffset = $customHeader.innerHeight();
}
// If the scroll is more than the custom header, set the fixed class.
if ( $( window ).scrollTop() >= headerOffset ) {
$navigation.addClass( navigationFixedClass );
} else {
$navigation.removeClass( navigationFixedClass );
}
} else {
// Remove 'fixed' class if nav is taller than two rows.
$navigation.removeClass( navigationFixedClass );
}
}
}
I am not entirely certain what the solution would be. One idea (which is not ideal) is to adapt the .js file and put true between the ( ) instead of navIsNotTooTall on this line:
if ( navIsNotTooTall ) {
If you want to add this change to the child theme, instead of the main theme: Put the changed global.js file in your child-theme directory here: twentyseventeen-child/assets/js/global.js
Then add this to functions.php of the child-theme:
add_action( 'wp_enqueue_scripts', 'override_globaljs_script', 100 );
function override_globaljs_script()
{
wp_dequeue_script( 'twentyseventeen-global' );
wp_deregister_script( 'twentyseventeen-global' );
wp_enqueue_script( 'twentyseventeen-global-child', get_stylesheet_directory_uri() . '/assets/js/global.js' );
}
It will unregister the main theme global.js and register it for the child theme. This is the 'proper' Wordpress way to do it as far as I am concerned.

How to make featured image clickable? -Wordpress

How to make all the featured image clickable automatically? As it's Wordpress theme, I can only edit php or add css.
Simply add this code to your theme’s functions.php file.
This code simply adds a link around the code generated to display featured images or post thumbnails on your website.
function wpb_autolink_featured_images( $html, $post_id, $post_image_id ) {
$html = '' . $html . '';
return $html;
}
add_filter( 'post_thumbnail_html', 'wpb_autolink_featured_images', 10, 3 );
This code will also add a link around featured images on single post pages. If you don’t want to link featured images on single post to the same post, then use this code.
function wpb_autolink_featured_images( $html, $post_id, $post_image_id ) {
If (! is_singular()) {
$html = '' . $html . '';
return $html;
} else {
return $html;
}
}
add_filter( 'post_thumbnail_html', 'wpb_autolink_featured_images', 10, 3 );
Normally the functionality of a featured image has no link attached to it. Different themes use the functionality of featured image differently. The new Twenty Nineteen theme, for example, uses it as the background for the page header, behind the post title.
So it will be better to make a child theme of your parent theme and edit the php file to set a link. Without editing the code you cannot set the link of the featured image.
Insert image > Click on the desired cell you want to insert it > Down on the right: “Linked to” > Personalized URL.

Adding an image page banner to shop page

I am using WordPress 4.9.6.
I have set the shop page to be the home-page.
How do I add a page banner to the shop page. I would like to add it just above the breadcrumb trail.
I have tried adding this to the following page archive-product.php
if (is_shop()) {
$args = array('taxonomy' => 'product_cat');
$product_categories = get_categories( $args );
$term_id = $product_categories[0]->term_id;
$content = get_term_meta($term_id, 'cat_meta');
if(isset($content[0]['cat_header'])){
echo do_shortcode($content[0]['cat_header']);
}
}
Unfortunately, not able to add any image to the page.
You can achieve using 2 methods.
1) Add your static image directly at the beginning of archive-product.php
echo "<img src='{YOUR_IMAGE_PATH}'>";
2) Add filter in your theme's functions.php file.
add_action ('woocommerce_archive_description' , 'shop_banner',99);
function shop_banner() {
echo '<img src="{YOUR_IMAGE_PATH}" >';
}
I'm not so sure if I understand exactly what you want. But this is what I understand so far.
If you want to display an Static image banner above the breadcrumbs in your Shop Page.
You could use the woocommerce_before_main_content action.
function BannerShop(){
if(is_shop()){
echo '<img src="https://localhost/demosite/wp-content/uploads/2015/06/512x356.png" >';
}
}
add_action( 'woocommerce_before_main_content', 'BannerShop', 10 );
Here i show the before and after. BTW I don't know what theme are you using so it may be displayed different.
Before
https://i.stack.imgur.com/Mv2YK.jpg
After https://i.stack.imgur.com/nTfCa.jpg

woocommerce-products-header in Subcategory - Remove Header Image

I have searched around but can't seem to find exactly what I am looking for. I have subcategories set up on my store, and images assigned to these subcategories, as I want the thumbnails to be displayed when you click into a main category .
However, when I then click into the subcategory page, to display products within that subcategory, the image I set for the thumbnail appears under the description, quite large.
I don't want the subcategory image on the product list page whatsoever. Is there anything within the woocommerce code I can change or add to make this happen? This is what it looks like now... I want it to look like this
Thanks in advance!
Using functions.php:
remove_action( 'woocommerce_before_subcategory_title', 'woocommerce_subcategory_thumbnail', 10 );
add_action( 'woocommerce_before_subcategory_title', 'custom_subcategory_thumbnail', 10 );
function custom_subcategory_thumbnail( $category ) {
if ( $category->parent == '0' ) {
woocommerce_subcategory_thumbnail( $category );
} else {
// do not show a category image
}
}
Using CSS:
.tax-product_cat ul.products li.product a img {
display:none
}
Note: this code was found here.

Set title of the WordPress page with two different colors

The title in my WordPress is of two words (say "The Company" for example). Right now the default color is Blue. But I want the "The" portion in the above example to be Grey. I used the font tag and set it as <font color="grey">The</font> Company in the site title Input box. In the preview page it is showing correctly, but when I visit my page , it is showing as
<font color="grey">The</font> Company
including the tags. How to modify? I'm using mindfulness theme in WordPress
(similar kind of) if someone throws a light on option two of this page.
A briefly describing image:
How to target specific words in the blog title of the Twenty Twelve theme?
You can try the following, it works for the Twenty Twelve theme:
/**
* Wrap the first word of the blog title with the <span>...</span> tag.
* Assumes the Twenty Twelve theme.
*
* #see http://stackoverflow.com/a/25096093/2078474
*/
add_filter( 'body_class',
function( $class )
{
add_filter( 'bloginfo', 'so_25094932_modify_first_word', 10, 2 );
return $class;
}
);
function so_25094932_modify_first_word( $output, $show )
{
static $counter = 0;
// Target the "name" part:
if( 'name' === $show )
{
// Target the second instance:
if( 2 === ++$counter )
{
remove_filter( current_filter(), __FUNCTION__ );
// Modify the first word of the blog title:
$title = explode( ' ', $output );
if( count( $title ) > 0 )
{
$title[0] = sprintf( '<span>%s</span>', $title[0] );
}
$output = join( ' ', $title );
}
}
return $output;
}
where we use the bloginfo filter to target only the second instance of the blog name, counted from the <body> tag.
Then we can target the span tag with CSS:
h1.site-title span{
color: red;
}
Example:
Here's a screenshot:
It should be possible to adjust our code snippet to other themes as well.
I hope this helps.
To do so you have to change the style.css that controls your design | theme.
Edit CSS from wordpress:
Login to WordPress, not sure which version you're running, but you should have a section called Themes or Design. From there choose Theme Editor. There will be a list of all the files you can edit, the CSS stylesheet should be named style.css.
You will have to have write access in order to edit it from within WP admin.
Otherwise you will have to find the file via FTP on your website, download it to your computer, edit it, and then upload it back to your site.
Edit CSS the way you want it:
<span id="the">The</span>
<span id="company">Company</span>
<style>
#the{color: #0033CC;} //refers to blue.
#company{color:#CCCCCC;} //refers to grey.
</style>
There is also a fiddle for you to test it:
JSFIDDLE Demo
GoodLuck!

Categories