CSS class not updating HTML content - html

I have an eCommerce store on WordPress. We just migrated from Opencart to WordPress and have been having issues regarding the product description.
All our products have different CSS in the description and we were hoping it could be done the way its done in opencart (where css tags start with style tag and followed by HTML classes which are referred in HTML tags).
An example of the code from OpenCart is pasted below to give an idea:
I tried doing the same thing that I did for opencart but that doesn't seem to work in the product description editor on wordpress. It's just taking the HTML tags and totally ignoring the css tags.
<style>
body {
font-family: Open Sans, Arial, Helvetica, sans-serif
}
#topDiv {
font-family: Arial, Helvetica, sans-serif
}
.tt1 {
color: #000;
font-size: 16px;
font-size: calc(100% + 24 * (100vw - 320px) / 1600);
font-size: calc(16px + 24 * (100vw - 320px) / 1600);
line-height: 1.2;
font-weight: 700
}
</style>
<div class="tt1">Pair Seamlessly</div>
It's just displaying "Pair Seamlessly" without any formatting that should be coming from the css tag

I haven't done a lot of work in wordpress, but from what I know I believe there is specific file where you put all your CSS. Here's an article that might help. How to Find WordPress CSS File

Because all of your products rely on the same file (e.g. single-product.php or something similar) all the css you write for this file will be applied to al of your products. The easiest thing you can do is to give your products an ID. You can achieve this by passing the_ID(); into your while loop. Each product will have his own ID, so every product can have its own styling.
So basically you'll get something like this:
<ul class="products">
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => -1
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) :
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="product" id="product-<?php the_ID(); ?>">This is your product</div>
<?php endwhile;
else :
echo __( 'No products found' );
endif;
wp_reset_postdata();
?>
Now you can style your products like for example this way
#product-1 {
background-color:red;
}
Styles should be applied in its own stylesheet, which should be enqueued in functions.php
The following documentation should give you enough guidance in how to do so:
https://developer.wordpress.org/reference/functions/wp_enqueue_style/

I found the answer. Insert the following code to your child's theme functions.php file:
add_action( 'woocommerce_after_add_to_cart_button', 'css_for_products', 30 );
function css_for_products() {
global $product;
if ($product->id == 784 or $product->id == 832 )
{
wp_enqueue_style( 'sample-code', 'https://www.yoursite.com/css/custom.css',false);
}
Where custom.css is the css file that will be uploaded to the above location. Add more conditions for different products.

Related

Wordpress make entire blog post clickable

Currently my blog posts have a small "view more" link at the bottom. Ideally, I would like to change it so that you can click anywhere in the <article class="blog-post"> and it will link you to the relevant article.
I have figured out how to do it so the excerpt is clickable, but cannot convert it to for the entire article
Code for the excerpt -
function clickable_excerpt( $post ) {
return ''. $post .'';
}
add_filter( 'get_blog_post', 'clickable_excerpt' );
Find class="grid-item" in your theme code, i found it at content.php and then add onclick javascript on article tag, like below
<article id="post-<?php the_ID(); ?>" <?php post_class('grid-item'); ?> onclick="document.location='<?php the_permalink(); ?>'">
also don't forgot to add CSS
article.grid-item {cursor: pointer;}
Try this:
add_filter( 'the_content', 'filter_content' );
function filter_content( $content ) {
if ( is_singular('post') ) {
$content = '. $content .';
}
return $content;
}
Better if you can do it directly in your theme single page template, this link help you to identificate the correct page in your theme:
https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post

Convert responsive WordPress <ul> menu to <select> for small screens sans JS

I'm trying to build a responsive header for my WordPress theme on my site. Depending on the screen resolution, I'd like to go from a typical WordPress unordered list menu (larger screens), to a custom select dropdown menu (phone screens). I'd like to do this without relying on any additional JS so please no JavaScript or jQuery solutions.
While researching how to do this, I found a few useful resources, such as this question from the WordPress stack exchange site. The problem with this answer is that you'll notice it doesn't include the actual <select> tag around the <option> tags, so nothing appears on the site, although if you view the source code you will see that the options are being generated inside of a <ul> tag. I read through this one too but it relies on jQuery, which is not what I want.
I have made a 2nd menu called "select-menu-nav" and I plan on simply toggling the CSS display property for this menu and the "main-menu" with media queries depending on the width of the screen.
Here is the pertinent code -
HTML:
<header>
<div id="logo-area">
<img id="logo" src="<?php bloginfo('template_directory'); ?>/assets/imgs/db-logo.png" alt="Digital Brent Logo">
<h2 id="site-title">Digital<br/>Brent.com</h2>
</div>
<div id="nav-area">
<?php
$walker = new alpha_nav_walker;
wp_nav_menu( array( 'theme_location' => 'main-nav', 'walker' => $walker) );
wp_nav_menu( array( 'theme_location' => 'select-main-nav', 'walker' => new alpha_dropdown_nav) );
?>
</div>
<div id="news-area">
</div>
<div id="search-area">
<?php get_search_form(); ?>
</div>
</header>
CSS:
#media(max-width: 1100px){
#menu-main-menu{
display: none;
}
#menu-small-screen-menu{
display: block;
}
}
Custom Navigation Function (dropdown):
class alpha_dropdown_nav extends Walker_Nav_Menu{
public function start_lvl(&$output, $depth){}
public function end_lvl(&$output, $depth){}
public function start_el(&$output, $item, $depth, $args){
$item->title = str_repeat(" ", $depth * 4) . $item->title;
parent::start_el(&$output, $item, $depth, $args);
$output = str_replace('<li', '<option', $output);
}
public function end_el(&$output, $item, $depth){
$output .= "</option>\n";
}
}
^ Note: This is the second usage of a custom menu walker function in the same file. The two functions are different (the first is referenced in the main menu call in the header) but I don't know if that's a problem, or if it's bad practice or not.
How can I replace the <ul> tag being generated around the option tags with a <select>?
Additionally, I welcome any feedback on my methodology. If anyone knows a way to do this that is more efficient, or considered better practice, I would be happy to learn a more effective way of doing this. Thanks!
I think this article includes exactly what you need!
WordPress menus display as unordered lists by default. You might want to display them as a select menu though. Below is an example of creating a menu ‘walker’ that will render it as a select menu. When you are displaying your menu using wp_nav_menu(), include 'walker' => new Walker_Nav_Menu_Dropdown() to tell WordPress to use this type of formatting rather than the default.
functions.php
<?php
// Nav Menu Dropdown Class
include_once( CHILD_DIR . '/lib/classes/nav-menu-dropdown.php' );
/**
* Mobile Menu
*
*/
function be_mobile_menu() {
wp_nav_menu( array(
'theme_location' => 'mobile',
'walker' => new Walker_Nav_Menu_Dropdown(),
'items_wrap' => '<div class="mobile-menu"><form><select onchange="if (this.value) window.location.href=this.value">%3$s</select></form></div>',
) );
}
add_action( 'genesis_before_header', 'be_mobile_menu' );
nav-menu-dropdown.php
class Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu {
function start_lvl(&$output, $depth){
$indent = str_repeat("\t", $depth); // don't output children opening tag (`<ul>`)
}
function end_lvl(&$output, $depth){
$indent = str_repeat("\t", $depth); // don't output children closing tag
}
/**
* Start the element output.
*
* #param string $output Passed by reference. Used to append additional content.
* #param object $item Menu item data object.
* #param int $depth Depth of menu item. May be used for padding.
* #param array $args Additional strings.
* #return void
*/
function start_el(&$output, $item, $depth, $args) {
$url = '#' !== $item->url ? $item->url : '';
$output .= '<option value="' . $url . '">' . $item->title;
}
function end_el(&$output, $item, $depth){
$output .= "</option>\n"; // replace closing </li> with the option tag
}
}
Good luck! :)

Remove div class post nocolsidepost - wordpress

My wordpress theme (Anglepane) is creating a second (unwanted) post at the bottom of my page.
I have used Firefox page inspector and isolated the problem with the div tag "nocolsidepost", and I have gone through the 20+ theme files (css etc) and deleted this tag whereever I find it, but the second posts still remain!! - I can delete it on the fly with Firefox page inspector, but not in the actual code
Could anyone please explain how to solve this
Website is http://historyofliverpool.com and the section I want to remove it the bottom block with the previous / next links on it
I don't know the structure of the code in the theme but it can be in multiple parts of the code.
TwentyThirteen and TwentyFourteen themes (the ones bundled with Wordpress) use a separate function to show the pagination or the Prev/Next buttons. If your theme has this function (usually in function.php file) you will have to search for it and delete/modify all the lines that print something. For example, here is the function from TwentyThirteen theme:
function twentythirteen_paging_nav() {
global $wp_query;
// Don't print empty markup if there's only one page.
if ( $wp_query->max_num_pages < 2 )
return;
?>
<nav class="navigation paging-navigation" role="navigation">
<h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentythirteen' ); ?></h1>
<div class="nav-links">
<?php if ( get_next_posts_link() ) : ?>
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentythirteen' ) ); ?></div>
<?php endif; ?>
<?php if ( get_previous_posts_link() ) : ?>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentythirteen' ) ); ?></div>
<?php endif; ?>
</div><!-- .nav-links -->
</nav><!-- .navigation -->
<?php
}
On the other side, the theme can easily implement the corresponding code directly in the archive.php, index.php and other category.php/tag.php files. It is similar to the function used above, the only difference is the function wrapper (the first is a function, the second not).
Or, simpler (but less proper) way to achieve this is to add a display:none; to the element above. But, to achieve this, you will have to find the code that generates it, to add there an id, and in the CSS use the id like this:
#your-id-here{
display:none;
}

switching between regular html and jQuery mobile site acting strange [duplicate]

I have a wordpress site, that need to show pages using swipe, I choose to use Jquery Mobile, and I get it working fine. Now, we have 2 languages on site, using wpml plugin. And my Swipe Code works well, except when we use Change language button swipe fails.
Details on issue.
We have only 3 Text Only page in our website, in 2 language. And in Footer we have link to change language. Also client hate to have Ajax page loading, so what I did is I create three Div with data-role=page and put data-next, data-prev as #div-$postid. So the navigation works absolute fine. I put footer outside from data-role=page.
Now, when I click change button in footer, it load the english page [I saw it using Fiddler] and then take first data-role=page from server and replace /slide its content. However since it only pick the first data role, all other english page doesn't get in HTML [it just update DOM and doesn't navigate to english version]. so swipe fails as other english pages are not in dom.
Also, footer is not changing, so what I want is: can we simple force a Link to navigate instead of going swipe way? Jquery Mobile is enforcing swipe on all A tags, I do not want swipe to works anything outside data-role=page.
Hope I make sense.
Edit here is code: [not sure if this code will help at all]
<?php
get_header();
global $post;
$args = array('post_type' => 'mobile_slide','showposts' => '-1', "order" => "DESC");
$the_query = new WP_Query($args);
if($the_query->have_posts()){
while($the_query->have_posts()) { $the_query->the_post();
$prev =get_previous_post();
$next =get_next_post();
if($prev) {
$prev = "#page-" . $prev->ID; //get_permalink($prev->ID);
} else {
$prev='';
}
if($next) {
$next = "#page-".$next->ID; //get_permalink($next->ID);
} else {
$next='';
}
if (has_post_thumbnail( $post->ID ) ) {
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'slider_image' ); ?>
<div id="page-<?php echo $post->ID; ?>" data-dom-cache="true" data-transition="slide" class="page" data-role="page" data-prev="<?php echo $prev; ?>" data-next="<?php echo $next; ?>" style="background-image:url('<?php echo $image[0]; ?>'); background-position:center center; background-color:#000; background-repeat:no-repeat; ">
<?php } else { ?>
<div id="page-<?php echo $post->ID; ?>" data-dom-cache="true" data-transition="slide" class="page" data-role="page" data-prev="<?php echo $prev; ?>" data-next="<?php echo $next; ?>">
<?php } ?>
<div class="post_box">
<h2><blockquote><?php the_title(); ?></blockquote></h2>
<div class="post_entry">
<?php the_content(); ?>
</div>
</div><!-- post_box -->
</div>
<?php }
} ?>
<?php get_footer(); ?>
This is all I have, except that get_footer use Ul li based list where on LI change based on language variable, to show different images for either language.
To stop Ajax from loading pages/links, add to link anchor data-rel="external" or data-ajax="false". This will load page normally without any transition.
Reference: jQuery Mobile - Links
For those who have similar problem, I fix it by using following:
1) I add a "noswipe" class to A Tag so I can refer it in Jquery
2) I add following code
$(function(){
$(".noswipe").click(function(){
window.location.href= $(this).attr("href");
return false;
});
});
The above code simply enforce to skip the Mobile's parsing and calling and works for my case.

How to change font in innerHTML new window?

I have to change font in the new window of window.open() because I want to print in receipt printer. I already change the True Type Font Subtitution but it doesn't work . So how can I add css for the new open window ??
here's my code :
<img src="barcode.png" id="barcode">
<script type="text/javascript">
function printImg() {
ImageLink=document.getElementById("barcode").src;
pwin=window.open('','','width=0,height=0');
pwin.document.write("<center><h>My Store<h><br>Ekiosk</center><br>Date : <?php echo date('Y/m/d'); ?><br>Time : <?php echo date('H:i:s'); ?><br>Customer Name: <?php echo $cust['firstname']; ?> <?php echo $cust['lastname']; ?> <br>Total : <?php echo $cust['total']; ?><br><center><img src='" + ImageLink + "'/><br>Thanks For Shopping !</center>");
pwin.print();
pwin.close();
}
</script>
Can anyone help me to change font into font receipt ?
Add a CSS file
<link href="your.css" ... />
Just like you're doing with your pwin.document.write sentence
You should also write a full valid html code in the document.write, including html, title, head and body tags, and put the link inside the head tag, like you use to do in any other page.