I have a woo commerce website and I am using a plugin called 'print products pdf'. We wish to use this to print product data onto A6 cards that will be attached to the products in our showroom.
The data it pulls from the site is the brand logo, product title, the regular price and the sales price.
The regular price and the sales price however floats a set distance below the product title. If the product title is two lines big the prices are higher in the page. If the product title is 4 lines big than the prices are lower in the page.
I wish to remove this link and set the prices section to a set distance from the bottom of the page and lock it there. That way it doesn't matter how long the title is or anything else above it, it will be set a distance from the bottom and will not move.
Here are two examples, one with a short product title and one with a long title - see how the prices are in a different location? I wish to set them in the location they are in the second example (lower down the page):
https://simsgardenmachinery.co.uk/product/stihl-ap-500-s-battery/?print-products=pdf
https://simsgardenmachinery.co.uk/product/stiga-park-500-w-out-front-ride-on-with-100cm-qf-electric-lift-deck/?print-products=pdf
Please see below css code. I am not a coder but have a loose understanding so as much info on what to change/where will be greatly appreciated.
Thank you!
Here is the css code that is edited in 'Theme file editor'
<?php
add_filter('woocommerce_print_products_mpdf_config', function($config) {
$config['format'] = 'A6';
return $config;
}, 10, 1);
add_filter('woocommerce_print_products_product_final_html', function($html, $product_id, $data) {
$product = wc_get_product($product_id);
if(!$product) {
return 'product not found';
}
$brand = $product->get_attribute('pa_brand');
$brandImageUrl = false;
if($brand) {
$brandTerm = get_term_by('name', $brand, 'pa_brand');
if($brandTerm && isset($brandTerm->term_id)) {
$brandTermImage = get_term_meta($brandTerm->term_id, 'image', true);
if(isset($brandTermImage['url']) && !empty($brandTermImage['url'])) {
$brandImageUrl = $brandTermImage['url'];
} elseif(!empty($brandTermImage)) {
$brandImageUrl = $brandTermImage;
}
}
}
if($brandImageUrl) {
$brandImage = '<img class="brand-image" src="' . $brandImageUrl . '" alt="">';
}
$productName = $product->get_name();
$productRegularPrice = strip_tags( wc_price( $product->get_regular_price() ) );
$productSalePrice = strip_tags( wc_price( $product->get_sale_price() ) );
$productShortDescription = $product->get_short_description();
$productQrCode = '<barcode class="qr-code" type="QR" size="0.5" code="' . $product->get_permalink() . '"></barcode>';
$html = '
<style>
.frame {
padding: 15px 20px;
font-size: 14px;
}
.brand-image-container {
margin-left: auto;
margin-right: auto;
padding-top: 50px;
padding-right: 20px;
padding-bottom: 5px;
padding-left: 20px;
width: 200px;
}
.product-name {
text-align: center;
font-size: 36px;
line-height: 35px;
font-weight: bold;
}
.product-name-container {
height: 200px;
padding-top: 30px;
}
.product-regular-price-container {
font-size: 22px;
}
.product-sale-price-container {
text-align: center;
text-transform: uppercase;
font-weight: bold;
}
.product-sale-price-title {
font-size: 34px;
line-height: 60px;
}
.product-sale-price {
font-size: 60px;
line-height: 30px;
color: #76af40;
}
.product-short-description table {
padding: 0;
}
.product-short-description td,
.product-short-description {
font-size: 12px;
line-height: 20px;
padding: 0;
text-align: left;
}
.product-regular-price-container {
text-align: center;
color: red;
}
</style>
<div class="frame">
<div class="brand-image-container">
' . $brandImage . '
</div>
<div class="clear"></div>
<div class="product-name-container">
<h1 class="product-name">' . $productName . '</h1>
</div>
<div class="product-regular-price-container">
RRP: ' . $productRegularPrice . '
</div>';
if(!empty($productSalePrice)) {
$html .= '
<div class="product-sale-price-container">
<div class="product-sale-price-title">
Sims Price
</div>
<div class="product-sale-price">
' . $productSalePrice . '
</div>
</div>';
}
$html .=
'</div>
<pagebreak></pagebreak>
<div class="frame">
<div class="qr-code-container">
' . $productQrCode . '
</div>
<div class="clear"></div>
<div class="product-name-container">
<h1 class="product-name">' . $productName . '</h1>
</div>
<div class="product-short-description-container">
<div class="product-short-description-title">Key Features:</div>
<div class="product-short-description">' . $productShortDescription . '</div>
</div>
</div>
';
return $html;
}, 10, 3);
Related
I'm currently trying to make a blog. When I try to make a "preview" of the body of the post. The first post seems to be fine, but the second post goes over its div. I tried changing what tags to use and css formatting but it stays like that.
My code:
HTML
<div class="module">
<div class="blog">
<div class="recents">
<h2>Recent Posts</h2>
<br><br>
<?php
$sql = "select title, body, created_at FROM posts";
$result = mysqli_query($link, $sql);
$query = mysqli_query($link, $sql) or die(mysqli_error($link));
while ($row = mysqli_fetch_assoc($query)) {
$title = $row['title'];
$body = $row['body'];
$created_at = $row['created_at'];
if (strlen($body) > 500) {
$body = substr($body, 0, 500);
}
echo "<h3>" . $title . "</h3><br>";
echo "<p>" . $body . "</p>";
echo "<small>" . $created_at . "</small>";
echo "<br><br>";
}
?>
</div>
<div class="categories">
<h3>Categories</h3>
</div>
</div>
CSS
html {
font-family: 'IBM Plex Serif', serif;
}
.module {
background-color: #fffff7;
box-shadow: 3px 10px 18px #888888;
padding-top: 70px;
padding-left: 130px;
border: 1px solid;
width: 1080px;
margin-left: 380px;
height: 821px;
}
.blog {
display: flex;
flex-direction: row;
text-align: left;
}
.recents {
flex-grow: 2;
width: 570px;
}
.categories {
flex-grow: 1;
}
Any help would be appreciated.
It is because there are no spaces
to fix this try this:
word-wrap: break-word;
I'm developing a webpage that has many forms with some text close to form. This form and text are generated by a function, but I get this
As you can see the forms and the text are not aligned with forms and text below. I would like to have this:
(this work because I put spaces manually). This is how I create forms.
function add_form($product,$name,$productp)
{
$productpt = "X";
echo $name;
echo '<input type="text" name="'. $product. '" id="'. $product. '" style="font-size:12pt;height:30px"/> x'.$productp. '€
price:'.$productpt.'€<br>';
}
echo '<form method="post" name="form1" id="form1" autocomplete="off">'; //start form
echo '<div class="leftpane">'; //start leftpane
echo '<h1>';
echo '<font size="6" color="red"> ALIMENTS </font><br>';
//ADD ELEMENTS IN MY MENU
//The first argument is the form name and id, the second is the name that will be printed(to the left of the form), the third argument is the price.
$menu[] = new Menu("pasta", "Pasta", 2);
$menu[] = new Menu("spaghetti", "Spaghetti", 1.50);
$menu[] = new Menu("pizza", "Pizza", 5);
$menu[] = new Menu("chicken_wings_x4", "Chicken Wings X4", 4.50);
$menu[] = new Menu("cheeseburger", "Cheeseburger", 6);
$menu[] = new Menu("Sandwich", "Sandwich", 2);
$menu[] = new Menu("hamburger", "Hamburger", 4.50);
$menu[] = new Menu("stuff", "stuff", 15.50);
//FOR EACH ELEMENT CREATE A FORM
for($i=0; $i<count($menu); $i++){
add_form($menu[$i]->form_name, $menu[$i]->name, $menu[$i]->price);
}
echo '</h1>';
echo '</div>'; //Close leftpane
...Do Others stuff in middlepane and in rightpane
To be clearer in html, for example the first form will be:
<input type="text" name="pasta" id="pasta" style="font-size:12pt;height:30px"/> x2€ price:X€<br>
I thought to divide in 3 parts my leftpane and to place $name to the left, the form to the middle and the price to the right. But the problem is that i create form in function, so I do not know how to do it.
This is my css:
<style>
input[type=text] {
width: 10%;
margin: 7.5px 0;
box-sizing: border-box;
}
input[type=submit].class1 {
width: 50%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
input[type=submit].class2 {
width: 50%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
body, html {
width: 100%;
height: 100%;
margin: 0;
}
.container {
width: 100%;
height: 100%;
}
.leftpane {
width: 33%;
height: 100%;
float: left;
border-collapse: collapse;
}
.middlepane {
width: 33%;
height: 100%;
float: left;
border-collapse: collapse;
}
.rightpane {
width: 33%;
height: 100%;
position: relative;
float: right;
border-collapse: collapse;
}
form {
display: inline-block;
}
h1 {
font-size: 19.5px;
}
</style>
I would suggest you to use a table. https://www.w3schools.com/html/html_tables.asp
Or you could wrap every section into a div-container and define its width.
I think your output code would really benefit from some additional HTML structure with classes that allow you to control their layout in a consistent way with CSS. I would update the add_form() function:
function add_form($product,$name,$productp) {
$productpt = "X";
echo '<div class="form-wrap">';
echo '<span class="form-name">' . $name . '</span>';
echo '<input type="text" name="'. $product. '" id="'. $product. '"/> <span class="form-label">x'.$productp. '€</span> <span class="form-price">price:'.$productpt.'€</span>';
echo '</div>';
}
Then with the output having more targetable HTML structure you can do this with CSS:
.form-wrap input {
font-size: 12pt;
height: 30px
}
.form-name {
display: inline-block;
width: 100px;
margin-right: 20px;
}
.form-label {
display: inline-block;
margin-left: 5px;
margin-right: 20px;
}
<div class="form-wrap">
<span class="form-name">Something</span>
<input type="text" name="something" id="somethingId" />
<span class="form-label">x1€</span>
<span class="form-price">price:1€</span>
</div>
<div class="form-wrap">
<span class="form-name">Another one</span>
<input type="text" name="anotherone" id="somethingId2" />
<span class="form-label">x2€</span>
<span class="form-price">price:2€</span>
</div>
<div class="form-wrap">
<span class="form-name">Number Three</span>
<input type="text" name="thirdone" id="somethingId3" />
<span class="form-label">x3€</span>
<span class="form-price">price:3€</span>
</div>
Try this.
function add_form($product,$name,$productp)
{
$productpt = "X";
echo "<table><tr>";
echo "<td width='20%'>" . $name . "</td>";
echo "<td width='20%'><input type='text' name='". $product . "' id='" . $product . "' style='font-size:12pt;height:30px;' /></td>";
echo "<td width='20%'>x" . $productp . "€</td>";
echo "<td width='20%'>price:" . $productpt . "€</td>";
echo "</tr></table>";
}
Following along a tutorial when I got stuck with the CSS portion, the Wordpress site seems to be unresponsive to the changes I make in the CSS code. I'll post what I have:
//file abraham-admin.php
<h1>Abraham Theme Options</h1>
<?php settings_errors(); ?>
<?php
$firstName = esc_attr( get_option( 'first_name' ) );
$lastName = esc_attr( get_option( 'last_name' ) );
$fullName = $firstName . ' ' . $lastName;
$description = esc_attr( get_option( 'user_description' ) );
?>
<div class="abraham-sidebar-preview">
<div class="abraham-sidebar">
<h1 class="abraham-username"><?php print $fullName ?></h1>
<h2 class="abraham-description"><?php print $description ?></h2>
<div class="icons-wrapper">
</div>
</div>
</div>
<form method="post" action="options.php" class="abraham-general-form">
<?php settings_fields( 'abraham-settings-group'); ?>
<?php do_settings_sections( 'z_abraham'); ?>
<?php submit_button(); ?>
</form>
//file enqueue.php
function abraham_load_admin_scripts() {
wp_register_style('abraham_admin', get_template_directory_uri() . '/css/abraham_admin.css', array(), '1.0.0', 'all');
wp_enqueue_style('abraham_admin');
}
add_action( 'admin_enqueue_scripts', 'abraham_load_admin_scripts');
//file abraham_admin.css
.abraham-general-form,
.abraham-sidebar-preview { display: inline-blog; float: left; }
.abraham-sidebar-preview { width: 200px; background-color: #3f3f3f; padding: 20px; text-align: center; margin-right: 20px}
.abraham-sidebar { display: block; text-align: center; }
h1.abraham-username,
h2.abraham-description { font-weight: 100; color: #ffffff; }
h1.abraham-username { font-size: 24px; margin: 0 0 10px; }
h2.abraham-description { font-size: 13px; margin: 0 0 20px; }
Any help is appreciated. Thanks!
I figured out how to limit my post words. The problem I am having is that my css code almost centers the 3 posts but it still favors the left side a little. These will not be the colors that I will be using they are just helping me with layout. If anyone could help in anyway it would be greatly appreciated!
Here is the php code
<section id="blog">
<div class="container-fluid">
<div class="row">
<div id="blog_title">
Featured Posts
</div><!--END BLOG TITLE-->
<div id="featured_posts">
<?php
// output RSS feed to HTML
output_rss_feed('http://www.bmcsquincy.com/featured_posts/feed', 20, true, true, 200);
// Check http://www.systutorials.com/136102/a-php-function-for-fetching-rss-feed-and-outputing-feed-items-as-html/ for description
// RSS to HTML
/*
$item_cnt: max number of feed items to be displayed
$max_words: max number of words (not real words, HTML words)
if <= 0: no limitation, if > 0 display at most $max_words words
*/
function get_rss_feed_as_html($feed_url, $max_item_cnt = 10, $show_date = true, $show_description = true, $max_words = 0, $cache_timeout = 7200, $cache_prefix = "/tmp/rss2html-")
{
$result = "";
// get feeds and parse items
$rss = new DOMDocument();
$cache_file = $cache_prefix . md5($feed_url);
// load from file or load content
if ($cache_timeout > 0 &&
is_file($cache_file) &&
(filemtime($cache_file) + $cache_timeout > time())) {
$rss->load($cache_file);
} else {
$rss->load($feed_url);
if ($cache_timeout > 0) {
$rss->save($cache_file);
}
}
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
);
$content = $node->getElementsByTagName('encoded'); // <content:encoded>
if ($content->length > 0) {
$item['content'] = $content->item(0)->nodeValue;
}
array_push($feed, $item);
}
// real good count
if ($max_item_cnt > count($feed)) {
$max_item_cnt = count($feed);
}
$result .= '<ul class="feed-lists">';
//ADDED THIS FOR POST AMOUNT
$max_item_cnt = 3;
$max_words = 25;
for ($x=0;$x<$max_item_cnt;$x++) {
$title = str_replace(' & ', ' & ', $feed[$x]['title']);
$link = $feed[$x]['link'];
$result .= '<li class="feed-item">';
$result .= '<div class="feed-title"><strong>'.$title.'</strong></div>';
if ($show_date) {
$date = date('l F d, Y', strtotime($feed[$x]['date']));
$result .= '<small class="feed-date"><em>Posted on '.$date.'</em></small>';
}
if ($show_description) {
$description = $feed[$x]['desc'];
$content = $feed[$x]['content'];
// find the img
$has_image = preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $content, $image);
// no html tags
$description = strip_tags($description, '');
// whether cut by number of words
if ($max_words > 0) {
$arr = explode(' ', $description);
if ($max_words < count($arr)) {
$description = '';
$w_cnt = 0;
foreach($arr as $w) {
$description .= $w . ' ';
$w_cnt = $w_cnt + 1;
if ($w_cnt == $max_words) {
break;
}
}
$description .= " ...";
}
}
// add img if it exists
//ADDED THE P IN DESCRIPTION LINE TO FOR A BREAK BY IMAGE
if ($has_image == 1) {
$description = '<p> <img class="feed-item-image" src="' . $image['src'] . '" /></p>' . $description;
}
$result .= '<div class="feed-description">' . $description;
//ADDED THE P IN THIS TO LINE BREAK CONTINUE READING
$result .= '<p> Continue Reading »</p>'.'</div>';
}
$result .= '</li>';
}
$result .= '</ul>';
return $result;
}
function output_rss_feed($feed_url, $max_item_cnt = 10, $show_date = true, $show_description = true, $max_words = 0)
{
echo get_rss_feed_as_html($feed_url, $max_item_cnt, $show_date, $show_description, $max_words);
}
?>
</div><!--END FEATURED POSTS-->
<div class="col-md-12 col-sm-12 col-xs-12" id="blog_btn_section">
<div id="btn_see_work" class="col-md-12 text-center"><a class="button btn btn-default btn-md wp5 delay-3s" id="btn-intro" href="./contact.php" target="_top">SEE MORE
</a>
</div><!--END BUTTON-->
</div><!--END COL SPAN-->
</div><!--END ROW-->
</div><!--END CONTAINER-->
</section><!--END SECTION BLOG-->
Here is my CSS that is giving me alignment troubles
#blog {
background-color: yellow;
color: #dbdbdb;
width: 100%;
padding-top: 50px;
padding-bottom: 50px;
margin: 0px auto 0px auto;
}
#blog_title {
text-align: center;
font-family: pathwaygothic;
font-size: 2em;
color: green;
padding-bottom: 50px;
}
#blog_btn_section {
padding-top: 50px;
}
#featured_posts {
background-color: pink;
max-width: 1200px;
margin: 0px auto 0px auto;
padding: 5px;
}
#featured_posts ul {
display: inline-block;
margin: 0px auto 0px auto;
text-align: center;
padding: 0px;
}
#featured_posts li {
list-style-type: none;
text-align: left;
padding: 30px;
float: left;
font-family: pathwaygothic;
font-size: 1em;
background-color: purple;
max-width: 1200px;
margin-left: 25px;
}
.feed-lists {
background-color: aqua;
width: 100%;
}
.feed-title a {
color: red;
}
.feed-date {
color: aqua;
}
.feed-description {
width: 300px;
}
.feed-lists li {
background-color: green;
}
.feed-item-image:hover {
opacity: .5;
background-color: #333333;
transition: 0.5s ease;
}
Okay so I have found after some long research a code that I will include here that adds prev/next url at bottom of page. What I am doing is making a portfolio that in the future I will add pages and remove, so I needed a php code that would run pages using the footer.php and go to next in line. Example it would show page1.php, page2.php, page3.php, page4.php and so on. That all works great in the code I have. What I would like now is to put a variable name on each page of what that portfolio piece will be then have it echo next to the previous and next button. I can get it to work, but it shows the existing name on each prev/next button.
If I am not making sense just tell me and I will explain it differently. I hope someone can help, been trying to get my portfolio done for some time now! :)
Here is my header.php
<html>
<head>
<title>PAGINATION TEST</title>
<link rel="stylesheet" type="text/css" href="./css/style.css" />
</head>
<nav>
<div id="nav_menu">
<ul>
<li>HOME</li>
<li>ABOUT</li>
<li>CONTACT</li>
</ul>
</div>
</nav>
<body>
Here is my page1.php
<?php //THIS IS THE PREVIOUS/NEXT LINK TITLE FOR EACH PORTFOLIO PAGE
session_start();
$_SESSION['link-title'] = "wonder woman";
?>
<?php include('header.php') ?>
<div id="main_body">
PAGE 1
</div>
<?php include('footer.php') ?>
Here is my footer.php
<?php
session_start(); //this NEEDS to be at top of the page before any output etc
?>
<?php
$pinfo = pathinfo($_SERVER["SCRIPT_FILENAME"]);
$reqpath = dirname($_SERVER["REQUEST_URI"]);
$linkname = ($_SESSION['link-title']);
if(preg_match("/(.*?)(\d+)\.php/", $pinfo["basename"], $matches)) {
$fnbase = $matches[1];
$fndir = $pinfo["dirname"];
$linkTitle = $linkname;
$current = intval($matches[2]);
$next = $current + 1;
$prior = $current - 1;
$next_file = $fndir . DIRECTORY_SEPARATOR . $fnbase . $next . ".php";
$prior_file = $fndir . DIRECTORY_SEPARATOR . $fnbase . $prior . ".php";
$next_link = $linkTitle . $next;
$prev_link = $linkTitle . $prior;
if(!file_exists($next_file)) $next_file = false;
if(!file_exists($prior_file)) $prior_file = false;
if($prior_file) {
$link = $reqpath . DIRECTORY_SEPARATOR . basename($prior_file);
// echo "Prior";
}
if($prior_file && $next_file) {
// echo " / ";
}
if($next_file) {
$link = $reqpath . DIRECTORY_SEPARATOR . basename($next_file);
// echo "Next";
}
if($prev_link) {
$prevTitle = $prev_link;
}
if($next_link) {
$Title = $next_link;
}
}
?>
<div id="pagination_container">
<div id="previous_link">
<!-- PREVIOUS -->
<?php if($prior_file) {
$link = $reqpath . DIRECTORY_SEPARATOR . basename($prior_file);
echo "PREVIOUS";
// echo $_SESSION['link-title'];
echo $prevTitle;
}
?>
</div>
<div id="next_link">
<!-- NEXT -->
<?php if($next_file) {
$link = $reqpath . DIRECTORY_SEPARATOR . basename($next_file);
echo $Title;
// echo $_SESSION['link-title'];
echo "NEXT";
}
?>
</div>
</div>
<div id="footer">
copyright blah blah
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</body>
</html>
here is my css
body,html {
padding: 0;
margin: 0;
overflow-x: hidden;
}
#nav_menu {
background-color: pink;
width: 100%;
height: 80px;
}
#nav_menu ul {
text-align: right;
}
#nav_menu li {
list-style-type: none;
display: inline-block;
padding-right: 20px;
padding-top: 30px;
}
#main_body {
width: 100%;
background-color: #dbdbdb;
height: 400px;
padding: 20px;
color: #333333;
}
#pagination_container {
width: 100%;
background-color: pink;
display: flex;
}
#previous_link {
width: 50%;
background-color: purple;
color: white;
display: flex;
float: left;
text-align: left;
padding-top: 50px;
padding-bottom: 50px;
padding-left: 20px;
}
#previous_link:hover {
color: white;
transition: 0.5s all;
}
#previous_link:link {
color: white;
text-decoration: none;
}
#next_link {
width: 50%;
background-color: purple;
color: white;
text-align: right;
padding-top: 50px;
padding-bottom: 50px;
padding-right: 20px;
border-left: 1px solid #dbdbdb;
}
#next_link a:visited {
color: white;
}
#next_link a:link {
color: white;
text-decoration: none;
}
#next_link a:hover {
color: blue;
transition: 0.5s all;
}
#next_link:hover {
background-color: pink;
transition: 0.5s all;
}
#footer {
text-align: center;
padding-top: 20px;
}
Here is page2.php for example of how it works now
<?php //THIS IS THE PREVIOUS/NEXT LINK TITLE FOR EACH PORTFOLIO PAGE
session_start();
$_SESSION['link-title'] = "superman";
?>
<?php include('header.php') ?>
<div id="main_body">
PAGE 2
</div>
<?php include('footer.php') ?>