How to modify widget's innerHTML in Woocommerce - php

I'm trying to show that one of the categories is on sale by displaying "ON SALE! -50%" text in category list widget.
I obviously can't and won't modify category name to include this text.
Here's the website: https://demo.wpdesk.org/michalkleszko23gmailcom/

Maybe the fastest way how to do it is to write a short javascript, which will edit text. So, if yours widget has id="block-5" (according to the demo), you just add replacing script into the next custom HTML widget under the yours category widget.
<script>
document.getElementById('block-5').innerHTML = document.getElementById('block-5').innerHTML.replace("Albums", "Albums <div style=\"color:red\">ON SALE! -50%</div>");
</script>

Related

Adding html inside function

I need to add a symbol (→) inside a function. The function is supposed to display a product tag on the woocommerce single product page and link back to the specific tag archive. the last part of the function is
echo '<h2>'.$text.'</h2>';
and I need the arrow to be displayed righ after the term slug. How do I insert it?
You can add it as a html entity →
echo '<h2><a href="'.esc_url($link).'" title="'.$text.'" class="" '.$term->slug.'>→'.$text.'</a></h2>';
Hope I understand it correctly "displayed righ after the term slug" that you want it displayed before the text.
Here's the entity table for future references: https://www.w3schools.com/charsets/ref_utf_arrows.asp

how to (line) break output at specific keyword?

Situation: PHP-based CMS (OpenCart 2.0.3.1) -> category page -> outputs the product names via:
<?php echo $product['name']; ?>
Problem: need to wrap a portion of the product name, to the next line. For example, what currently displays as 20-inch Blue Widget For Golfers should display as
20-inch Blue
Widget for Golfers
So every product that has the word "Widget" (or "AnotherKeyword" in it), should have a <br> before it.
How can this be done?
P.S. Changing the product name itself to include a <br> or <br> doesn't work, since OpenCart displays whatever is in the Product Name field literally, ignoring HTML. (Unless someone can point me in the direction of "how to echo the $product[name] but actually process the HTML in it").
As suggested, you can first replace in php "Widget" with a br in front and then via jquery wrap all this way:
<script>
$(".name a").text(function () {
$(this).wrap('<pre />');
})
</script>

Adding Wordpress function into shortcode

I have a shortcode [table id=table /]
I want to do something like this <?php echo do_shortcode('[table id="'.$post->post_name.'"/]'); ?>
I want the slug to appear as the table id.
What am I doing wrong?
Given that you mentioned in the comments that you're trying to use this shortcode in a widget - widgets don't parse shortcodes by default.
To make most widgets parse shortcodes (most being those with text fields that apply the widget_text filter), you can add the following to your theme's functions.php:
add_filter("widget_text", "do_shortcode");
You can then refer to this shortcode directly in your widget text like you would expect you can:
[table id=... /]
EDIT:
If you have any trouble running shortcodes that are on their own line, it may be because they get wrapped in <p></p> tags automatically by Wordpress. To stop this happening, add this filter before the one added above:
add_filter("widget_text", "shortcode_unautop");
The shortcode_unautop() function simply stops shortcodes from being wrapped in paragraph tags like is Wordpress' default behaviour in most text fields.

How to set slider only on Homepage in Drupal 7.31?

I set my slider only on Homepage with tag in Drupal 7.31 but it black div is taking same div space on other page but slider is not coming. Help me.
I'm using "Bartik" theme.
If you want to display specific content on your drupal homepage than add following code in your page.tpl.php file or you can do it using create Block region position.
<?php
if (drupal_is_front_page()) {
// your slider code goes here
}
?>
If your content is a block, go in the settings of your block and choose the option : display only on listed pages, in listed page add the value <front>

WordPress Category Question

I cannot figure out how to use the wp_list_categories function to do what I need it to:
<?php if(is_category() or is_page('realisations') or is_single()) { ?>
<ul id="subpage">
<?php wp_list_categories('child_of=3&title_li=<h4>Les secteurs</h4>'); ?>
</ul>
<?php }; ?>
I have it set up so that all of the project categories are child categories of the a main category (child_of=3) This is to avoid conflicts with the news section of the site.
The problem is that I need the category the post is in to highlight when viewing the single.php page template, but I don't know how to accomplish that. When on a category page the category view highlights correctly because I styled the class that WordPress adds into the generated list .current-cat.
I answered my own question! This wonderful plugin has the function that I didn't need to write myself: http://www.screenshine.net/blog/1474_wordpress-plugin-show-active-category
It sets a filter to add into the wp_list_categories() function, the only thing I dislike about it is that it sets a css class on the anchor instead of the list item, which is inconsistent with WordPress functionality. It works in a pinch though, which is what I am in. You can stick it in your functions.php to prepackage the plugin and do minor edits.

Categories