Showing posts with label wordpress-theming. Show all posts
Showing posts with label wordpress-theming. Show all posts

Tuesday, October 9, 2018

wordpress sticky post on archive page with pagination

Leave a Comment

I have category page which is redirecing to archieve.php.

you can see here : https://www.dealfinder.lk/category/dining/

There are two sticky posts at the top.

1) Up to 25% OFF at &Co Pub and Kitchen with COMBANK Cards

2) 20% OFF at Robata – Movenpick Hotel Colombo for all HSBC Credit Cards

My pagination is 10 items per post

Right now, it shows me 12 items per post.

Here is my code :

function yell_category_sticky_posts( $posts, $wp_query ) {      global $wp_the_query;      // Don't continue if this isn't a category query, we're not in the main query or we're in the admin     if ( ! $wp_query->is_category || $wp_query !== $wp_the_query || is_admin() )         return $posts;      global $wpdb;      $q = $wp_query->query_vars;      $page = absint( $q['paged'] );      if ( empty( $page ) )         $page = 1;      $post_type = $q['post_type'];      $sticky_posts = get_option( 'sticky_posts' );      if ( $wp_query->is_category && $page <= 1 && is_array( $sticky_posts ) && !empty( $sticky_posts ) && ! $q['ignore_sticky_posts'] ) {          $num_posts = count( $posts );          $sticky_offset = 0;          // Loop over posts and relocate stickies to the front.         for ( $i = 0; $i < $num_posts; $i++ ) {              if ( in_array( $posts[$i]->ID, $sticky_posts ) ) {                  $sticky_post = $posts[$i];                  // Remove sticky from current position                 array_splice( $posts, $i, 1 );                  // Move to front, after other stickies                 array_splice( $posts, $sticky_offset, 0, array( $sticky_post ) );                  // Increment the sticky offset.  The next sticky will be placed at this offset.                 $sticky_offset++;                  // Remove post from sticky posts array                 $offset = array_search( $sticky_post->ID, $sticky_posts );                 unset( $sticky_posts[$offset] );              }          }          // If any posts have been excluded specifically, Ignore those that are sticky.         if ( !empty( $sticky_posts ) && !empty( $q['post__not_in'] ) )             $sticky_posts = array_diff( $sticky_posts, $q['post__not_in'] );          // Fetch sticky posts that weren't in the query results         if ( !empty( $sticky_posts ) ) {              $stickies__in = implode( ',', array_map( 'absint', $sticky_posts ));              // honor post type(s) if not set to any             $stickies_where = '';              if ( 'any' != $post_type && '' != $post_type ) {                  if ( is_array( $post_type ) )                     $post_types = join( "', '", $post_type );                  else                     $post_types = $post_type;                  $stickies_where = "AND $wpdb->posts.post_type IN ('" . $post_types . "')";             }              $stickies = $wpdb->get_results( "SELECT wp_posts.* FROM $wpdb->posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1  AND ( wp_term_relationships.term_taxonomy_id IN (" . get_term( $wp_query->query_vars['cat'], 'category' )->term_taxonomy_id . ") ) AND $wpdb->posts.ID IN ($stickies__in) $stickies_where" );              foreach ( $stickies as $sticky_post ) {                  // Ignore sticky posts are not published.                 if ( 'publish' != $sticky_post->post_status )                     continue;                  array_splice( $posts, $sticky_offset, 0, array( $sticky_post ) );                  $sticky_offset++;              }         }     }      return $posts;  } add_filter( 'the_posts', 'yell_category_sticky_posts', 10, 2 ); 

My Issue:

I want to show 10 posts per page, currently it shows 12 posts per page with sticky post.

This question is for master not for new learner.

Anybody master here? Thanks in advance

2 Answers

Answers 1

As I suggested in the comment, save the 'sticky posts' in meta (assuming is_featured_post as the 'meta key').

Run these only once to set the meta value for existing posts. You can skip this since you are already saving in the meta.

// set meta value of all posts to 0 $all_posts = get_posts(array('post_type'=>'post','posts_per_page'=>-1)); if( is_array( $all_posts ) ) {     foreach( $all_posts as $post ) {         update_post_meta( $post->ID, 'is_featured_post', '0'  );     } }  // set meta value of all sticky posts alone to 1 $sticky_posts = get_option( 'sticky_posts' ); if( is_array( $sticky_posts ) ) {     foreach ( $sticky_posts as $sticky_post ) {          update_post_meta( $sticky_post, 'is_featured_post', '1'  );     } } 

The below function will update the new sticky meta is_featured_post each time a post updated (or new post saved).

function save_sticky_meta( $post_id ) {     if ( isset( $_REQUEST['sticky'] ) ) {         update_post_meta( $post_id, 'is_featured_post', '1'  );     }     else {         update_post_meta( $post_id, 'is_featured_post', '0'  );     } } add_action( 'save_post', 'save_sticky_meta' ); add_action( 'edit_post', 'save_sticky_meta' ); 

Then use pre_get_posts action to set the category query. We are ordering by both 'meta' and 'date' descending to show the latest at top.

function include_sticky_posts( $query ) {     if ( ! is_admin() && $query->is_main_query() && $query->is_category() ) {         $query->set( 'meta_key', 'is_featured_post' );         $query->set( 'sticky_sort', true ); //custom sticky order query         $query->set( 'orderby', 'meta_value_num date' );         $query->set( 'order', 'DESC' );     } } add_action( 'pre_get_posts', 'include_sticky_posts' ); 

If you want to randomize non-sticky posts, change the order using the_posts filter as below.

add_filter( 'the_posts', 'sticky_posts_sort', 10, 2 ); function sticky_posts_sort( $posts, $query ) {     // if custom sort set from category query     if ( true !== $query->get( 'sticky_sort' ) )         return $posts;       // loop through posts & save sticky & other posts in seperate arrays     $sticky_posts = get_option( 'sticky_posts' );     $sticky_array = array();     $posts_array = array();     foreach ( $posts as $p ) {         if( in_array( $p->ID, $sticky_posts ) )             $sticky_array[] = $p;         else             $posts_array[] = $p;     }      // merge both arrays and randomize non-sticky posts alone     if( is_array( $posts_array ) )         shuffle( $posts_array );     if( is_array( $sticky_array ) && is_array( $posts_array ) )         $posts = array_merge( $sticky_array, $posts_array );     elseif( is_array( $sticky_array ) )         $posts = $sticky_array;     else         $posts = $posts_array;      return $posts; } 

Answers 2

The below function pushes stickies to the top, you should be able to use this to help in your case.

add_filter('the_posts', 'bump_sticky_posts_to_top'); function bump_sticky_posts_to_top($posts) {     $stickies = array();     foreach($posts as $i => $post) {         if(is_sticky($post->ID)) {             $stickies[] = $post;             unset($posts[$i]);         }     }     return array_merge($stickies, $posts); } 
Read More

Sunday, December 24, 2017

Use custom template with Essential Grid

Leave a Comment

Using Essential Grid plugin for WordPress theme development, I've created a masonry layout with cards which display all the post. Each card has an image, title, and so forth. With shortcodes, I've been able to add the same masonry layout found on the homepage to the post page. I've created a custom template for the post content. However, my custom template shows as the first post(which I want), but the other cards which are in the masonry layout are below it. I'm trying to have it float next to each other.

Desired layout: 1 being my custom card template

1-2-3-4-5-6-7 8-9-etc.. 

Current Layout:

1 2-3-4-5-6-7 

For better reference, I'm trying to achieve this type of layout using the Essential Grid plugin for WordPress.

1 Answers

Answers 1

Easiest way these days for this would be flexbox, check out this article: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

You need to apply display: flex; to the wrapper and flex-wrap: wrap;, in article You can find more details on how to manipulate alignments for best-looking results.

Read More

Monday, October 30, 2017

Resize images in WordPress using its URL

Leave a Comment

I need to resize some images in some of my posts. I can get the image URL stored in postmeta created using the Types plugin.
So using postmeta I can get the URL, but how to resize the images of a specific post type?

1 Answers

Answers 1

First you have to find attached image id from image URL. To get attached image id from image URL add below function in your theme functions.php file:

function pn_get_attachment_id_from_url( $attachment_url = '' ) {     global $wpdb;      $attachment_id = false;      // If there is no url, return.     if ('' == $attachment_url)         return;      // Get the upload directory paths     $upload_dir_paths = wp_upload_dir();      // Make sure the upload path base directory exists in the attachment URL, to verify that we're working with a media library image     if (false !== strpos($attachment_url, $upload_dir_paths['baseurl'])) {          // If this is the URL of an auto-generated thumbnail, get the URL of the original image         $attachment_url = preg_replace('/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i', '', $attachment_url);          // Remove the upload path base directory from the attachment URL         $attachment_url = str_replace($upload_dir_paths['baseurl'] . '/', '', $attachment_url);          // Finally, run a custom database query to get the attachment ID from the modified attachment URL         $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT wposts.ID FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = '_wp_attached_file' AND wpostmeta.meta_value = '%s' AND wposts.post_type = 'attachment'", $attachment_url));     }      return $attachment_id; } 

For more information read see url - https://philipnewcomer.net/2012/11/get-the-attachment-id-from-an-image-url-in-wordpress/

Then we need to use image resize function in function.php:

add_image_size( 'latestproperty_thumb', 370,293,true ); 

To get the image attachment id use:

$attachid = pn_get_attachment_id_from_url($url); 

After this install https://wordpress.org/plugins/regenerate-thumbnails/. Then go to Tools->Regenerate thumbnail and regenerate all thumbnails.

After that use this to get the regenerated image url:

$src = wp_get_attachment_image_src($attachid, 'latestproperty_thumb'); 
Read More

Saturday, February 4, 2017

Customizer Color Scheme Not Passing Colors

Leave a Comment

I haven't worked on WordPress in years, Customizer is totally new to me and I believe I have messed up getting the default color scheme values and could really use some help. I took an HTML site and built it ontop of the stock TwentySixteen theme for base file structure as well as to tie into some of the newer features (well new to me). I went in changed the Customizer.php file the way I needed it for CSS changes, but its not picking up the color scheme options anymore and passing them through, so my theme currently starts with basically no colors. I am continuing to look through it to see what I have messed up but if anyone could point me in a direction to solving this that would be great.

Here is a pastebin of my Customizer.php file.

http://pastebin.com/gmK4KmGX

While normally I would try to offer more details of what I have tried to do to fix it, at this point I am totally lost just pulled up the Codex to start figuring out some of the new things hoping to get a break somewhere.

Any help would be greatly appreciated.

Edit: If I manually select colors and save it, it works. Just isn't working with Color Schemes and the default color scheme.

Edit 2: Also noticed its not auto updating the site when editing in Customizer (as in picking new colors), I am totally stuck now and have to be missing something painfully simple. Going to start a bounty on this.

1 Answers

Answers 1

You need to update the array in color-scheme-control.js to reflect your changes in customizer.php and also your array index in customizer.php for $color_scheme is wrong, since you've removed the $wp_customize->remove_control( 'background_color' ); the index 0 is for page_background_color not index 1

Below is the changes I made, currently only works for 'Header Background Image' section which applied to .site selector

color-scheme-control.js

/* global colorScheme, Color */ /**  * Add a listener to the Color Scheme control to update other color controls to new values/defaults.  * Also trigger an update of the Color Scheme CSS when a color is changed.  */  (function(api) {   var cssTemplate = wp.template('twentysixteen-color-scheme'),     colorSchemeKeys = [       'page_background_color',       'link_color',       'main_text_color',       'secondary_text_color'     ],     colorSettings = [       'page_background_color',       'link_color',       'main_text_color',       'secondary_text_color'     ];    api.controlConstructor.select = api.Control.extend({     ready: function() {       if ('color_scheme' === this.id) {         this.setting.bind('change', function(value) {           var colors = colorScheme[value].colors;            // Update Page Background Color.           var color = colors[0];           api('page_background_color').set(color);           api.control('page_background_color').container.find('.color-picker-hex')             .data('data-default-color', color)             .wpColorPicker('defaultColor', color);            // Update Link Color.           color = colors[1];           api('link_color').set(color);           api.control('link_color').container.find('.color-picker-hex')             .data('data-default-color', color)             .wpColorPicker('defaultColor', color);            // Update Main Text Color.           color = colors[2];           api('main_text_color').set(color);           api.control('main_text_color').container.find('.color-picker-hex')             .data('data-default-color', color)             .wpColorPicker('defaultColor', color);            // Update Secondary Text Color.           color = colors[3];           api('secondary_text_color').set(color);           api.control('secondary_text_color').container.find('.color-picker-hex')             .data('data-default-color', color)             .wpColorPicker('defaultColor', color);         });       }     }   });    // Generate the CSS for the current Color Scheme.   function updateCSS() {     var scheme = api('color_scheme')(),       css,       colors = _.object(colorSchemeKeys, colorScheme[scheme].colors);      // Merge in color scheme overrides.     _.each(colorSettings, function(setting) {       colors[setting] = api(setting)();     });      // Add additional color.     // jscs:disable     colors.border_color = Color(colors.main_text_color).toCSS('rgba', 0.2);     // jscs:enable      css = cssTemplate(colors);      api.previewer.send('update-color-scheme-css', css);   }    // Update the CSS whenever a color setting is changed.   _.each(colorSettings, function(setting) {     api(setting, function(setting) {       setting.bind(updateCSS);     });   }); })(wp.customize); 

customizer.php

<?php /**  * Twenty Sixteen Customizer functionality  *  * @package WordPress  * @subpackage Twenty_Sixteen  * @since Twenty Sixteen 1.0  */  /**  * Sets up the WordPress core custom header and custom background features.  *  * @since Twenty Sixteen 1.0  *  * @see twentysixteen_header_style()  */ function twentysixteen_custom_header_and_background() {     $color_scheme             = twentysixteen_get_color_scheme();     $default_background_color = trim( $color_scheme[0], '#' );     $default_text_color       = trim( $color_scheme[3], '#' );      /**      * Filter the arguments used when adding 'custom-background' support in Twenty Sixteen.      *      * @since Twenty Sixteen 1.0      *      * @param array $args {      *     An array of custom-background support arguments.      *      *     @type string $default-color Default color of the background.      * }      */     add_theme_support( 'custom-background', apply_filters( 'twentysixteen_custom_background_args', array(         'default-color' => $default_background_color,     ) ) );      /**      * Filter the arguments used when adding 'custom-header' support in Twenty Sixteen.      *      * @since Twenty Sixteen 1.0      *      * @param array $args {      *     An array of custom-header support arguments.      *      *     @type string $default-text-color Default color of the header text.      *     @type int      $width            Width in pixels of the custom header image. Default 1200.      *     @type int      $height           Height in pixels of the custom header image. Default 280.      *     @type bool     $flex-height      Whether to allow flexible-height header images. Default true.      *     @type callable $wp-head-callback Callback function used to style the header image and text      *                                      displayed on the blog.      * }      */     add_theme_support( 'custom-header', apply_filters( 'twentysixteen_custom_header_args', array(         'default-text-color'     => $default_text_color,         'width'                  => 1200,         'height'                 => 280,         'flex-height'            => true,         'wp-head-callback'       => 'twentysixteen_header_style',     ) ) ); }   if ( ! function_exists( 'twentysixteen_header_style' ) ) : /**  * Styles the header text displayed on the site.  *  * Create your own twentysixteen_header_style() function to override in a child theme.  *  * @since Twenty Sixteen 1.0  *  * @see twentysixteen_custom_header_and_background().  */ function twentysixteen_header_style() {     // If the header text option is untouched, let's bail.     if ( display_header_text() ) {         return;     }      // If the header text has been hidden.     ?>     <style type="text/css" id="twentysixteen-header-css">         .site-branding {             margin: 0 auto 0 0;         }          .site-branding .site-title,         .site-description {             clip: rect(1px, 1px, 1px, 1px);             position: absolute;         }     </style>     <?php } endif; // twentysixteen_header_style  /**  * Adds postMessage support for site title and description for the Customizer.  *  * @since Twenty Sixteen 1.0  *  * @param WP_Customize_Manager $wp_customize The Customizer object.  */ function twentysixteen_customize_register( $wp_customize ) {     $color_scheme = twentysixteen_get_color_scheme();      $wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';     $wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';      if ( isset( $wp_customize->selective_refresh ) ) {         $wp_customize->selective_refresh->add_partial( 'blogname', array(             'selector' => '.site-title a',             'container_inclusive' => false,             'render_callback' => 'twentysixteen_customize_partial_blogname',         ) );         $wp_customize->selective_refresh->add_partial( 'blogdescription', array(             'selector' => '.site-description',             'container_inclusive' => false,             'render_callback' => 'twentysixteen_customize_partial_blogdescription',         ) );     }  // Remove the core header textcolor control, as it shares the main text color. $wp_customize->remove_control( 'background_color' );      // Add color scheme setting and control.     $wp_customize->add_setting( 'color_scheme', array(         'default'           => 'default',         'sanitize_callback' => 'twentysixteen_sanitize_color_scheme',         'transport'         => 'postMessage',     ) );      $wp_customize->add_control( 'color_scheme', array(         'label'    => __( 'Base Color Scheme', 'twentysixteen' ),         'section'  => 'colors',         'type'     => 'select',         'choices'  => twentysixteen_get_color_scheme_choices(),         'priority' => 1,     ) );       // Add page background color setting and control.     $wp_customize->add_setting( 'page_background_color', array(         'default'           => $color_scheme[0],         'sanitize_callback' => 'sanitize_hex_color',         'transport'         => 'postMessage',     ) );      $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'page_background_color', array(         'label'       => __( 'Header Background Color', 'twentysixteen' ),         'section'     => 'colors',     ) ) );      // Remove the core header textcolor control, as it shares the main text color.     $wp_customize->remove_control( 'header_textcolor' );      // Add link color setting and control.     $wp_customize->add_setting( 'link_color', array(         'default'           => $color_scheme[1],         'sanitize_callback' => 'sanitize_hex_color',         'transport'         => 'postMessage',     ) );      $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array(         'label'       => __( 'Header Text Color', 'twentysixteen' ),         'section'     => 'colors',     ) ) );      // Add main text color setting and control.     $wp_customize->add_setting( 'main_text_color', array(         'default'           => $color_scheme[2],         'sanitize_callback' => 'sanitize_hex_color',         'transport'         => 'postMessage',     ) );      $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'main_text_color', array(         'label'       => __( 'Sidebar Left Background Color', 'twentysixteen' ),         'section'     => 'colors',     ) ) );      // Add secondary text color setting and control.     $wp_customize->add_setting( 'secondary_text_color', array(         'default'           => $color_scheme[3],         'sanitize_callback' => 'sanitize_hex_color',         'transport'         => 'postMessage',     ) );      $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'secondary_text_color', array(         'label'       => __( 'Sidebar Right Background Color', 'twentysixteen' ),         'section'     => 'colors',     ) ) ); } add_action( 'customize_register', 'twentysixteen_customize_register', 11 );  /**  * Render the site title for the selective refresh partial.  *  * @since Twenty Sixteen 1.2  * @see twentysixteen_customize_register()  *  * @return void  */ function twentysixteen_customize_partial_blogname() {     bloginfo( 'name' ); }  /**  * Render the site tagline for the selective refresh partial.  *  * @since Twenty Sixteen 1.2  * @see twentysixteen_customize_register()  *  * @return void  */ function twentysixteen_customize_partial_blogdescription() {     bloginfo( 'description' ); }  /**  * Registers color schemes for Twenty Sixteen.  *  * Can be filtered with {@see 'twentysixteen_color_schemes'}.  *  * The order of colors in a colors array:  * 1. Main Background Color.  * 2. Page Background Color.  * 3. Link Color.  * 4. Main Text Color.  * 5. Secondary Text Color.  *  * @since Twenty Sixteen 1.0  *  * @return array An associative array of color scheme options.  */ function twentysixteen_get_color_schemes() {     /**      * Filter the color schemes registered for use with Twenty Sixteen.      *      * The default schemes include 'default', 'dark', 'gray', 'red', and 'yellow'.      *      * @since Twenty Sixteen 1.0      *      * @param array $schemes {      *     Associative array of color schemes data.      *      *     @type array $slug {      *         Associative array of information for setting up the color scheme.      *      *         @type string $label  Color scheme label.      *         @type array  $colors HEX codes for default colors prepended with a hash symbol ('#').      *                              Colors are defined in the following order: Main background, page      *                              background, link, main text, secondary text.      *     }      * }      */     return apply_filters( 'twentysixteen_color_schemes', array(         'default' => array(             'label'  => __( 'Default', 'twentysixteen' ),             'colors' => array(                 '#ffffff',                 '#ffffff',                 '#007acc',                 '#1a1a1a',                 '#686868',             ),         ),         'dark' => array(             'label'  => __( 'Dark', 'twentysixteen' ),             'colors' => array(                 '#262626',                 '#1a1a1a',                 '#9adffd',                 '#e5e5e5',                 '#c1c1c1',             ),         ),         'gray' => array(             'label'  => __( 'Gray', 'twentysixteen' ),             'colors' => array(                 '#616a73',                 '#4d545c',                 '#c7c7c7',                 '#f2f2f2',                 '#f2f2f2',             ),         ),         'red' => array(             'label'  => __( 'Red', 'twentysixteen' ),             'colors' => array(                 '#ffffff',                 '#ff675f',                 '#640c1f',                 '#402b30',                 '#402b30',             ),         ),         'yellow' => array(             'label'  => __( 'Yellow', 'twentysixteen' ),             'colors' => array(                 '#3b3721',                 '#ffef8e',                 '#774e24',                 '#3b3721',                 '#5b4d3e',             ),         ),     ) ); }  if ( ! function_exists( 'twentysixteen_get_color_scheme' ) ) : /**  * Retrieves the current Twenty Sixteen color scheme.  *  * Create your own twentysixteen_get_color_scheme() function to override in a child theme.  *  * @since Twenty Sixteen 1.0  *  * @return array An associative array of either the current or default color scheme HEX values.  */ function twentysixteen_get_color_scheme() {     $color_scheme_option = get_theme_mod( 'color_scheme', 'default' );     $color_schemes       = twentysixteen_get_color_schemes();      if ( array_key_exists( $color_scheme_option, $color_schemes ) ) {         return $color_schemes[ $color_scheme_option ]['colors'];     }      return $color_schemes['default']['colors']; } endif; // twentysixteen_get_color_scheme  if ( ! function_exists( 'twentysixteen_get_color_scheme_choices' ) ) : /**  * Retrieves an array of color scheme choices registered for Twenty Sixteen.  *  * Create your own twentysixteen_get_color_scheme_choices() function to override  * in a child theme.  *  * @since Twenty Sixteen 1.0  *  * @return array Array of color schemes.  */ function twentysixteen_get_color_scheme_choices() {     $color_schemes                = twentysixteen_get_color_schemes();     $color_scheme_control_options = array();      foreach ( $color_schemes as $color_scheme => $value ) {         $color_scheme_control_options[ $color_scheme ] = $value['label'];     }      return $color_scheme_control_options; } endif; // twentysixteen_get_color_scheme_choices   if ( ! function_exists( 'twentysixteen_sanitize_color_scheme' ) ) : /**  * Handles sanitization for Twenty Sixteen color schemes.  *  * Create your own twentysixteen_sanitize_color_scheme() function to override  * in a child theme.  *  * @since Twenty Sixteen 1.0  *  * @param string $value Color scheme name value.  * @return string Color scheme name.  */ function twentysixteen_sanitize_color_scheme( $value ) {     $color_schemes = twentysixteen_get_color_scheme_choices();      if ( ! array_key_exists( $value, $color_schemes ) ) {         return 'default';     }      return $value; } endif; // twentysixteen_sanitize_color_scheme  /**  * Enqueues front-end CSS for color scheme.  *  * @since Twenty Sixteen 1.0  *  * @see wp_add_inline_style()  */ function twentysixteen_color_scheme_css() {     $color_scheme_option = get_theme_mod( 'color_scheme', 'default' );      // Don't do anything if the default color scheme is selected.     if ( 'default' === $color_scheme_option ) {         return;     }      $color_scheme = twentysixteen_get_color_scheme();      // Convert main text hex color to rgba.     $color_textcolor_rgb = twentysixteen_hex2rgb( $color_scheme[3] );      // If the rgba values are empty return early.     if ( empty( $color_textcolor_rgb ) ) {         return;     }      // If we get this far, we have a custom color scheme.     $colors = array(         'page_background_color' => $color_scheme[0],         'link_color'            => $color_scheme[1],         'main_text_color'       => $color_scheme[2],         'secondary_text_color'  => $color_scheme[3],         'border_color'          => vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.2)', $color_textcolor_rgb ),      );      $color_scheme_css = twentysixteen_get_color_scheme_css( $colors );      wp_add_inline_style( 'twentysixteen-style', $color_scheme_css ); } add_action( 'wp_enqueue_scripts', 'twentysixteen_color_scheme_css' );  /**  * Binds the JS listener to make Customizer color_scheme control.  *  * Passes color scheme data as colorScheme global.  *  * @since Twenty Sixteen 1.0  */ function twentysixteen_customize_control_js() {     wp_enqueue_script( 'color-scheme-control', get_template_directory_uri() . '/js/color-scheme-control.js', array( 'customize-controls', 'iris', 'underscore', 'wp-util' ), '20160816', true );     wp_localize_script( 'color-scheme-control', 'colorScheme', twentysixteen_get_color_schemes() ); } add_action( 'customize_controls_enqueue_scripts', 'twentysixteen_customize_control_js' );  /**  * Binds JS handlers to make the Customizer preview reload changes asynchronously.  *  * @since Twenty Sixteen 1.0  */ function twentysixteen_customize_preview_js() {     wp_enqueue_script( 'twentysixteen-customize-preview', get_template_directory_uri() . '/js/customize-preview.js', array( 'customize-preview' ), '20160816', true ); } add_action( 'customize_preview_init', 'twentysixteen_customize_preview_js' );  /**  * Returns CSS for the color schemes.  *  * @since Twenty Sixteen 1.0  *  * @param array $colors Color scheme colors.  * @return string Color scheme CSS.  */ function twentysixteen_get_color_scheme_css( $colors ) {     $colors = wp_parse_args( $colors, array(         'page_background_color' => '',         'link_color'            => '',         'main_text_color'       => '',         'secondary_text_color'  => '',         'border_color'          => '',     ) );      return <<<CSS     /* Color Scheme */      /* Background Color */       /* Page Background Color */     .site {         background-color: {$colors['page_background_color']};     }   CSS; }   /**  * Outputs an Underscore template for generating CSS for the color scheme.  *  * The template generates the css dynamically for instant display in the  * Customizer preview.  *  * @since Twenty Sixteen 1.0  */ function twentysixteen_color_scheme_css_template() {     $colors = array(         'page_background_color' => '{{ data.page_background_color }}',         'link_color'            => '{{ data.link_color }}',         'main_text_color'       => '{{ data.main_text_color }}',         'secondary_text_color'  => '{{ data.secondary_text_color }}',         'border_color'          => '{{ data.border_color }}',     );     ?>     <script type="text/html" id="tmpl-twentysixteen-color-scheme">         <?php echo twentysixteen_get_color_scheme_css( $colors ); ?>     </script>     <?php } add_action( 'customize_controls_print_footer_scripts', 'twentysixteen_color_scheme_css_template' );  /**  * Enqueues front-end CSS for the page background color.  *  * @since Twenty Sixteen 1.0  *  * @see wp_add_inline_style()  */ function twentysixteen_page_background_color_css() {     $color_scheme          = twentysixteen_get_color_scheme();     $default_color         = $color_scheme[0];     $page_background_color = get_theme_mod( 'page_background_color', $default_color );      // Don't do anything if the current color is the default.     if ( $page_background_color === $default_color ) {         return;     }      $css = '         /* Custom Header Background Color */         .site {             background-color: %1$s;         }         .ui-bar-a {             background-color: %1$s;         }      ';      wp_add_inline_style( 'twentysixteen-style', sprintf( $css, $page_background_color ) ); } add_action( 'wp_enqueue_scripts', 'twentysixteen_page_background_color_css', 11 );  /**  * Enqueues front-end CSS for the link color.  *  * @since Twenty Sixteen 1.0  *  * @see wp_add_inline_style()  */ function twentysixteen_link_color_css() {     $color_scheme    = twentysixteen_get_color_scheme();     $default_color   = $color_scheme[2];     $link_color = get_theme_mod( 'link_color', $default_color );      // Don't do anything if the current color is the default.     if ( $link_color === $default_color ) {         return;     }      $css = '         /* Custom Header Text Color */          [data-role=header] .header-title {              color: %1$s;          }           [data-role=panel][data-theme=d] .widget * {              color: %1$s;          }           [data-role=panel][data-theme=d] ul li a {          color: %1$s !important;          }     ';      wp_add_inline_style( 'twentysixteen-style', sprintf( $css, $link_color ) ); } add_action( 'wp_enqueue_scripts', 'twentysixteen_link_color_css', 11 );  /**  * Enqueues front-end CSS for the main text color.  *  * @since Twenty Sixteen 1.0  *  * @see wp_add_inline_style()  */ function twentysixteen_main_text_color_css() {     $color_scheme    = twentysixteen_get_color_scheme();     $default_color   = $color_scheme[3];     $main_text_color = get_theme_mod( 'main_text_color', $default_color );      // Don't do anything if the current color is the default.     if ( $main_text_color === $default_color ) {         return;     }      // Convert main text hex color to rgba.     $main_text_color_rgb = twentysixteen_hex2rgb( $main_text_color );      // If the rgba values are empty return early.     if ( empty( $main_text_color_rgb ) ) {         return;     }      // If we get this far, we have a custom color scheme.     $border_color = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.2)', $main_text_color_rgb );      $css = '      /* Custom Sidebar Left Background Color */      [data-role=panel][data-theme=a] {         background: %1$s;         border-right: 1px solid %1$s;     }        ';      wp_add_inline_style( 'twentysixteen-style', sprintf( $css, $main_text_color, $border_color ) ); } add_action( 'wp_enqueue_scripts', 'twentysixteen_main_text_color_css', 11 );  /**  * Enqueues front-end CSS for the secondary text color.  *  * @since Twenty Sixteen 1.0  *  * @see wp_add_inline_style()  */ function twentysixteen_secondary_text_color_css() {     $color_scheme    = twentysixteen_get_color_scheme();     $default_color   = $color_scheme[4];     $secondary_text_color = get_theme_mod( 'secondary_text_color', $default_color );      // Don't do anything if the current color is the default.     if ( $secondary_text_color === $default_color ) {         return;     }      $css = '         /* Custom Sidebar Right Background Color */      .ui-panel-animate.ui-panel-open.ui-panel-position-right.ui-panel-display-overlay, .ui-panel-animate.ui-panel-open.ui-panel-position-right.ui-panel-display-push {         background: %1$s;     }      .ui-panel-animate.ui-panel-position-right.ui-panel-display-overlay, .ui-panel-animate.ui-panel-position-right.ui-panel-display-push {         background: %1$s;     }      ';      wp_add_inline_style( 'twentysixteen-style', sprintf( $css, $secondary_text_color ) ); } add_action( 'wp_enqueue_scripts', 'twentysixteen_secondary_text_color_css', 11 ); 
Read More

Thursday, January 5, 2017

Bogo Plugin: Post in alternative language appears on blog despite draft, scheduled or bin status

Leave a Comment

I'm using the Bogo plugin on a OnePress theme to create Polish versions of my English posts. When I create drafts or scheduled posts in English, everything is fine. When I create the translated versions of these posts in Polish, no matter what status I set (draft, scheduled, move to bin!) they appear immediately on the Polish blog index. To hide them, I have to delete them and permanently empty the bin.

My theme:

  • OnePress 1.2.4 (also tested with 1.3.0 with the same result)

My active plugins:

  • Bogo 2.8.1 (also tested 3.1 with the same result)
  • CBX Flexible CountDown 1.7.2
  • Contact Form 7 4.5
  • Justified Gallery 1.1
  • Limit Login Attempts 1.7.1
  • Password Protected 2.0.3
  • Postman SMTP 1.7.2
  • Windows Azure Storage for WordPress 3.0.1
  • Wordpress Branding 1.0.3
  • WP-Optimize 2.0.1

1 Answers

Answers 1

From what I see in the Bogo plugin code, it looks like in some instances it retrieves posts without consideration for status.

Similar issue:

https://wordpress.org/support/topic/draft-post-is-unintentionally-linked/

Read More

Monday, October 24, 2016

Regenerate WordPress thumbnails with media hosted on S3

Leave a Comment

I have a WordPress site that uses the WPRO (WordPress Read Only) plugin to host all media files on Amazon S3. I've changed the thumbnail and image sizes in my custom theme, and uploading new images to the media library uses the new sizes. However, when I try to regenerate all thumbnails using "Regenerate Thumbnails," it doesn't work, often complaining that the original cannot be found.

How can I force the regenerate thumbnails plugin to use the original image on S3 to recreate the thumbnails for existing images?

0 Answers

Read More

Friday, April 8, 2016

Woocommerce overridden not work after Administrator logged in

Leave a Comment

I've copied the folder plugin/woocommerce/template to theme/mytheme/woocommerceand designed a new template and just checked Woocommerce/System Status to make sure overridden is worked.

The template works fine but when the user or the admin logged in , the overridden code does not work and the template defaults to plugin/woocommerce/template and shows the default template

the problem happened for this particular pages:

Product-single.php

taxonomy-product_cat.php

archive-product.php

And this problem happen just when Administrator logged in

How can this problem be addressed?

I use woocommerce 2.5.5

1 Answers

Answers 1

Are you using a child theme, if so did you add woocommerce support in the functions.php file?

Did you rule out any other plugins you've installed that could be causing this issue?

Do you have any special settings through a plugin for the administrator?

Have you tried moving all the template files to see if would work? I strongly believe it's probably another necessary file missing or plugin that could be causing your problem.

Read More