Mintstone https://mintstone.com/ Website Development Thu, 23 Jan 2020 22:41:20 +0000 en-CA hourly 1 https://wordpress.org/?v=6.8.3 Highlight Search Text https://mintstone.com/highlight-search-text/ Thu, 23 Jan 2020 22:24:28 +0000 https://mintstonestage.wpengine.com/?p=2092 With Genesis it’s super easy to highlight searched-for text on a webpage, which can be helpful to users hunting for information in text-heavy websites. 1) Create a customized version of search.php in your child theme, adding a couple of custom filters: remove_action( ‘genesis_loop’, ‘genesis_do_loop’ ); add_action( ‘genesis_loop’, ‘mint_do_search_loop’ ); function mint_do_search_loop() { $s = isset( […]

The post Highlight Search Text appeared first on Mintstone.

]]>
With Genesis it’s super easy to highlight searched-for text on a webpage, which can be helpful to users hunting for information in text-heavy websites.

1) Create a customized version of search.php in your child theme, adding a couple of custom filters:
remove_action( ‘genesis_loop’, ‘genesis_do_loop’ );
add_action( ‘genesis_loop’, ‘mint_do_search_loop’ );

function mint_do_search_loop() {
$s = isset( $_GET[“s”] ) ? $_GET[“s”] : “”;
$args = (array(
‘s’ => $s,
‘post_type’ => array(‘post’,’page’),
‘posts_per_page’ => 6,
‘orderby’ => ‘title’,
‘order’ => ‘ASC’,
));

$query = new WP_Query( $args );
if ( $query->have_posts() ) {
// remove post info.
remove_action( ‘genesis_entry_header’, ‘genesis_post_info’, 12 );

// remove post image
remove_action( ‘genesis_entry_content’, ‘genesis_do_post_image’, 8 );

// remove post content nav.
remove_action( ‘genesis_entry_content’, ‘genesis_do_post_content_nav’, 12 );
remove_action( ‘genesis_entry_content’, ‘genesis_do_post_permalink’, 14 );

// modify the links to pass the search params through to the page
add_filter( ‘get_the_content_more_link’, ‘mint_read_more_link’ );
add_filter( ‘genesis_post_title_output’, ‘mint_post_title_output’);

// remove entry footer.
remove_action( ‘genesis_entry_footer’, ‘genesis_entry_footer_markup_open’, 5 );
remove_action( ‘genesis_entry_footer’, ‘genesis_entry_footer_markup_close’, 15 );
remove_action( ‘genesis_entry_footer’, ‘genesis_post_meta’ );

// custom genesis loop with the above query parameters and hooks.
genesis_custom_loop( $args );
}
}

function mint_read_more_link() {
$s = isset( $_GET[“s”] ) ? $_GET[“s”] : “”;
return ‘<a class=”more-link” href=”‘ . get_permalink() . ‘?sp=’.$s.'”> …Read More</a>’;
}

function mint_post_title_output( $title ) {
$s = isset( $_GET[“s”] ) ? $_GET[“s”] : “”;

return  ‘<h1 class=”entry-title”><a class=”more-link” href=”‘ . get_permalink() . ‘?sp=’.$s.'”>%s</a></h2>’;

}

2) The parameters can now be handled in the page template using the following:
$searchParam = ”;
if ( isset($_GET[‘sp’]) ) {
$searchParam = $_GET[‘sp’];
}
//highlight the output:
$text=get_the_content();
if($searchParam){
if (strpos(strtolower($text), strtolower($searchParam)) !== false){
//highlight
$highlight = ‘‘.$searchParam.’‘;
$text = str_replace($searchParam,$highlight,$text);
}
}
echo $text;

3) Finally, a miniscule amount of css:
.search-highlight{
background-color:yellow;
}

The post Highlight Search Text appeared first on Mintstone.

]]>
Loading Gravity Forms dynamically in Popups https://mintstone.com/loading-gravity-forms-dynamically-in-popups/ Tue, 04 Dec 2018 19:53:09 +0000 https://mintstonestage.wpengine.com/?p=1985 Came across a tricksy little issue recently trying to submit a Gravity Form that needed to be loaded dynamically onto a popup (used the WP Popup Maker + Remote Content plugins for that) So here’s the fix… (all code can go in child theme functions.php) First off you might need to enqueue the Gravity Form […]

The post Loading Gravity Forms dynamically in Popups appeared first on Mintstone.

]]>
Came across a tricksy little issue recently trying to submit a Gravity Form that needed to be loaded dynamically onto a popup (used the WP Popup Maker + Remote Content plugins for that)

So here’s the fix… (all code can go in child theme functions.php)

First off you might need to enqueue the Gravity Form scripts on the page for the relevant form ID (#3 in this case):

e.g.
add_action( ‘genesis_after_header’ , ‘add_gform_scripts’ );
function add_gform_scripts() {
gravity_form_enqueue_scripts( 3, true);
}

Then you add the relevant popup maker stuff. Won’t document all that here though..

You should set ajax to true in the shortcode that goes into the popup.

Now for the crucial bit! Because the form in the popup has been dynamically loaded instead of being associated with a post/page you need to override the action for the ajax submit to work. Here’s how:

add_filter(“gform_form_tag”, “form_action_override”, 10, 2);
function form_action_override($form_tag, $form){
if ( $form[‘id’] == 3 ) {
$form_tag = preg_replace(“|action='(.*?)’|”, “action=’/'”, $form_tag);
}
return $form_tag;
}

Now when the form submits you get the confirmation message loading into the popup. Which should make you happy!

 

 

The post Loading Gravity Forms dynamically in Popups appeared first on Mintstone.

]]>
Output a Genesis Simple Sidebar Title https://mintstone.com/output-a-genesis-simple-sidebar-title/ Tue, 04 Dec 2018 19:27:07 +0000 https://mintstonestage.wpengine.com/?p=1984 If your Genesis site uses different sidebars on different pages then Genesis Simple Sidebars makes this really simple. But when you need to display the sidebar title before rendering the sidebar itself, here’s how you grab it: function add_custom_sidebar_heading() { $sidebarID= genesis_get_custom_field( ‘_ss_sidebar’ ); $sidebars = Genesis_Simple_Sidebars()->core->get_sidebars(); if ( array_key_exists( $sidebarID, (array) $sidebars ) ) […]

The post Output a Genesis Simple Sidebar Title appeared first on Mintstone.

]]>
If your Genesis site uses different sidebars on different pages then Genesis Simple Sidebars makes this really simple.

But when you need to display the sidebar title before rendering the sidebar itself, here’s how you grab it:

function add_custom_sidebar_heading() {
$sidebarID= genesis_get_custom_field( ‘_ss_sidebar’ );
$sidebars = Genesis_Simple_Sidebars()->core->get_sidebars();
if ( array_key_exists( $sidebarID, (array) $sidebars ) ) {
$sidebar = stripslashes_deep( $sidebars[ $sidebarID ] );
$sidebarTitle = $sidebar[‘name’];
}
echo ‘<div class=”custom-sidebar-title”>
<div class=”custom-sidebar-title-wrap”>
<h1 class=”sidebar-title”>’.$sidebarTitle.'</h1>
</div>
</div>’;
}
add_action( ‘genesis_before_sidebar_widget_area’, ‘add_custom_sidebar_heading’ );

 

The post Output a Genesis Simple Sidebar Title appeared first on Mintstone.

]]>
Implementing WooCommerce Product Search for all products in a multisite https://mintstone.com/implementing-woocommerce-product-search-for-all-products-in-a-multisite/ Thu, 30 Aug 2018 22:09:53 +0000 https://mintstonestage.wpengine.com/?p=1926 This is pretty straightforward to achieve using a few lines of code within the archive-product.php page template. Remember to override this correctly you’ll need to copy the file from it’s default location /wp-content/plugins/woocommerce/templates/archive-product.php into /wp-content/themes/your_theme/woocommerce/archive-product.php, then open this version of the file & edit it as follows: Scroll down to line 47 (at the time […]

The post Implementing WooCommerce Product Search for all products in a multisite appeared first on Mintstone.

]]>
This is pretty straightforward to achieve using a few lines of code within the archive-product.php page template.

Remember to override this correctly you’ll need to copy the file from it’s default location /wp-content/plugins/woocommerce/templates/archive-product.php into /wp-content/themes/your_theme/woocommerce/archive-product.php, then open this version of the file & edit it as follows:

Scroll down to line 47 (at the time of blogging!!)

//insert network search code here...

if ( is_search() ) {
do_action( 'woocommerce_before_shop_loop' );
woocommerce_product_loop_start();

$searchfor = get_search_query();
$query_string=esc_attr($query_string);
$blogs = get_sites();
foreach ( $blogs as $blog ):
switch_to_blog($blog->blog_id);
$search_query = new WP_Query($query_string);
while ( $search_query->have_posts() ) {
$search_query->the_post();
do_action( 'woocommerce_shop_loop' );
wc_get_template_part( 'content', 'product' );
}
restore_current_blog();
endforeach;

woocommerce_product_loop_end();
do_action( 'woocommerce_after_shop_loop' );
}
else{
//end of network search code =)
if ( woocommerce_product_loop() ) {

Finally you’ll need to add a closing curly bracket (brace) to line 92, right before this line of code
/**
* Hook: woocommerce_after_main_content.

The post Implementing WooCommerce Product Search for all products in a multisite appeared first on Mintstone.

]]>