Translate Wordpress block with <?php _e( - php

I have made some block custom in my wordpress theme. I did have to edit the shortcode.php file to add a price table. The thing I just realize is that I need those words ( From , /DAY , Book ) being translated though the .po file of my theme. So I have tried to add this line to replace the word ( "From" for example ). But I have a error code, I guess I don't have a good syntax here but can't find the right one. Can you Help?
Here is the original code
/*CUSTOM PRICE*/
}elseif($type === 'content_block_custom_price'){
$result = '<div class="featurecustom text-center">';
$result .= '<div class="thumbnail">
<img src="'.AUTORENT_IMAGE.''.$img.'" alt="">
</div>
<p class="titlecustom">'.$title.'</p>
<p class="fromprice"> From</p>
<span class="pricenumber">'.$pricetype.'<sup>€</sup></span><span class="fromprice">/ DAY</span>
<hr>
<p class="customdescription">'.$des.'</p>
<div class="bookingbutton" style="vertical-align:middle"><span>BOOK </span></div>
';
$result .= '</div>';
return $result;
/* CUSTOM PRICE*/
Here is the bad code i try to have my word translate
/*CUSTOM PRICE*/
}elseif($type === 'content_block_custom_price'){
$result = '<div class="featurecustom text-center">';
$result .= '<div class="thumbnail">
<img src="'.AUTORENT_IMAGE.''.$img.'" alt="">
</div>
<p class="titlecustom">'.$title.'</p>
<p class="fromprice"> <?php _e('From','themename'); ?></p>
<span class="pricenumber">'.$pricetype.'<sup>€</sup></span><span class="fromprice"><?php _e('/DAY','themename'); ?></span>
<hr>
<p class="customdescription">'.$des.'</p>
<div class="bookingbutton" style="vertical-align:middle"><span><?php _e('Book','themename'); ?> </span></div>
';
$result .= '</div>';
return $result;
/* CUSTOM PRICE*/
Post solved problem question : One I have new entries such as "Book" " FROM" and "/DAY", I guess I will have to creat them into the poedit file? Or will they be automatically added?
Thanks :)

Here is the good code (just inserting the gettex like this '. __("From","theme name").':
/*CUSTOM PRICE*/
}elseif($type === 'content_block_custom_price'){
$result = '<div class="featurecustom text-center">';
$result .= '<div class="thumbnail">
<img src="'.AUTORENT_IMAGE.''.$img.'" alt="">
</div>
<p class="titlecustom">'.$title.'</p>
<p class="fromprice"> '. __("From","theme name").'</p>
<span class="pricenumber">'.$pricetype.'<sup>€</sup></span><span class="from price">'. __("/DAY","theme name") .'</span>
<hr>
<p class="customdescription">'.$des.'</p>
<div class="bookingbutton" style="vertical-align:middle"><span>'. __("Book","themename"); .' </span></div>
';
$result .= '</div>';
return $result;
/* CUSTOM PRICE*/
For translation of themes & plugins there is a very effective and easy free plugin: Loco Translate
This plugin is going to scan your theme for new items to translate…

Related

How can I show my blog posts through filters with php - Wordpress?

it's my first time modifying a blog from the theme editor (theme: Astra) and I managed to list my articles through filters with javascript (show / hide). However, it is not the correct way to do it. I found that I can do it with meta_query() or tax_query(), but I haven't managed to do it. To make the post list, I did it with WPQuery.
Thanks for your time!
As seen in the image, this is where you should apply the filters, search and by category
`<div class="container_b padding-botomm-lista">
<div id="OdontologiaBlock" class="row_b">
<div class="column100-b">
<?php
$query3 = new WP_Query('cat=7&order=DESC&orderby=date');
if ( $query3->have_posts() ) {
while ( $query3->have_posts() ) {
$query3->the_post();
print "
<div class='column30 margin'>
<div class='col-img'>";
the_post_thumbnail();
print "
</div>
<div class='col-container'>
<span class='catspan'>";
$category = get_the_category();
echo $category[0]->cat_name;
print "
</span>
<h5>
<a class='color-link-post' target='_blank' href='";
the_permalink();
print " '>";
the_title();
print " </a>
</h5>
<span class='datespan'>";
echo get_the_date('d/m/Y');
print "
</span>
</div>
</div>";
}
}
/* Restore original Post Data */
wp_reset_postdata();
?>
</div>
</div>
</div>`

Image doesn't display using PHP

I'm trying to display the contents from database. Following query is working fine, but the problem is image does not show anymore.
<?php
session_start();
// Include config file
require_once "../auth/dbconnection.php";
$output='';
$sql='select `image`,`title`,`sub_title`,`username`,`blog_id`,`body`,`published` from `blog` WHERE user_id=? ';
$stmt=$conn->prepare( $sql );
$stmt->bind_param( 's',$_SESSION['user_id'] );
$res=$stmt->execute();
if( $res ){
$stmt->store_result();
$stmt->bind_result($image,$title,$sub_title, $username, $blog_id,$body,$published);
while( $stmt->fetch() ){
$filepath="../assets/img/blog_images/";
$title= substr($title,0,30);
$body= substr($body,0,500);
$date= date('dS F Y', strtotime($published));
$output .= '
<div class="col-sm-6 col-md-6 col-lg-4">
<div class="blog grid-blog">
<div class="blog-image">
<a href="#">';
$output .= ' <img style="height:190px; width:330px;" class="img-fluid" src="data:image/png;base64, %s" alt="" />'; base64_encode(file_get_contents($filepath.$image) ) ;
$output .= ' </a>
</div>
<div class="blog-content">
<h3 class="blog-title"> '.$title.' </h3>
<p> <code> '.$body.' </code> </p> <br>
<i class="fa fa-long-arrow-right"></i> Read More
<div class="blog-info clearfix">
<div class="post-left">
<ul>
<li><i class="fa fa-calendar"></i> <span>'.$date.'</span></li>
</ul>
</div>
<div class="post-right"><i class="fa fa-heart-o"></i>21 <i class="fa fa-eye"></i>8 <i class="fa fa-comment-o"></i>17</div>
</div>
</div>
</div>
</div>';
}
echo $output;
}else{
echo 'No any post found';
}
?>
Can anyone guide me how can fix the issue, i would like to appreciate if someone guide me regarding this. Thank You.
I assume that you omit sprintf function.
This should work.
sprintf('<img src="data:image/png;base64, %s" alt="" />', base64_encode(file_get_contents($filepath.$image));
You could put the image binary in separate variable to be easy to use
$binary = "data:image/png;base64," . base64_encode(file_get_contents($filepath . $image));
and use it like this
$output .= '<img style="height:190px; width:330px;" class="img-fluid" src="' . $binary . '" alt="" />';

Div tag around php code

I'm trying to configure my database data that is being pulled with php to look like my homepage.
I can't figure out what I need to do.
This is for a project for school, and I have very limited knowledge on php.
Here is my php script.
<?php
include('mysql_connect.php');
$dbh = con();
foreach($dbh->query("SELECT * FROM `Product` WHERE `ProductType` = 'memory' ",PDO::FETCH_ASSOC) as $row){
$Pname = $row['ProductName'];
$description = $row['description'];
$price = $row['ProductPrice'];
$ID = $row['ProductID'];
echo <div class="row">;
echo <div class="col-sm-4 col-lg-4 col-md-4">;
echo <div class="thumbnail">;
<img src="/var/www/html/Pictures/gigb75m_home.jpg" alt="">
echo "<div class="caption">";
echo "<h4 class="pull-right">$price</h4>";
echo "<h4>$Pname</h4>";
echo "<p>$description</p>";
echo "<p>$ID</p>";
}
?>
</div>
</div>
</div>
Here is my index that has my desired results.
<div class="row">
<div class="col-sm-4 col-lg-4 col-md-4">
<div class="thumbnail">
<img src="/var/www/html/Pictures/gigb75m_home.jpg" alt="">
<div class="caption">
<h4 class="pull-right">$74.99</h4>
<h4>GIGABYTE GA-B75M
</h4>
<p>Micro ATX, LGA 1155, Intel B75 Express Chipset, 2200MHz DDR3 (O.C.), SATA III (6Gb/s), 7.1-CH Audio, Gigabit LAN, USB 3.0 - GA-B75M-D3H</p>
</div>
</div>
</div>
Picture of homepage: http://imgur.com/g72Wrxk
Any help/guidance is greatly appreciated, this is driving me crazy.
Use '.' for string concatinations.
For example:
echo '<h4 class="pull-right">' . $price . '</h4>';
You have to use single quote to echo content in your PHP script like this for instead :
echo '<div class="row">';
The single quotes are used to explain that it's a string to show. You have to do the same for your other echo part.
Or you can escape the HTML part from the PHP and replace by vars inside it like this :
<?php
include('mysql_connect.php');
$dbh = con();
echo '<div class="row">';
foreach($dbh->query("SELECT * FROM `Product` WHERE `ProductType` = 'memory' ",PDO::FETCH_ASSOC) as $row){
$Pname = $row['ProductName'];
$description = $row['description'];
$price = $row['ProductPrice'];
$ID = $row['ProductID'];
?>
<div class="col-sm-4 col-lg-4 col-md-4">
<div class="thumbnail">
<img src="/var/www/html/Pictures/gigb75m_home.jpg" alt="">
<div class="caption">
<h4 class="pull-right"><?php echo $price; ?></h4>
<h4><?php echo $Pname; ?></h4>
<p>$description</p>
<p>$ID</p>
</div>
</div>
</div>
<?php
}
?>
</div>
Also you have to be careful about the row system of bootstrap to echo col-md-4 inside a row, you can add 3 items like this per row. So you have to close and reopen a row each time you fetch 3 elements to get a correct HTML structure.
You didn't supplied any information about your database, yet the first problem that's visible is your echo's
To output HTML through PHP you have to output pure strings.
An example for that would be ""
In PHP when you want to connect different kinds of inputs like variables and "" or '' etc you connect them with a dot.
For example:
$string = ' hello3';
echo "Hello 1 ".' hello2 '.$string;
The outcome will be:
Hello 1 hello2 hello3
I hope you got it the hang of it.

Declare inline background image in functions.php

I'm not sure if this can be done as I cannot find anything to help me anywhere no matter how hard i try. I'm using Ajax to load to in posts on the press of the button. the posts that are loaded in are formatted by my function inside my functions.php. That all works perfetly,the issue i'm having is the background-image: property needs to be inline css so that it can pull the image from my custom field. This all works perfectly in the template file, however. no matter what I try the functions.php rejects my inline style for background image no matter what I try.
Here's my If statement in it's entirety:
if ($loop -> have_posts()) : while ($loop -> have_posts()) : $loop -> the_post();
if ($_SESSION["load_type"] == 'home')
{
$out .= '<div class="small-6 large-3 columns end thumb">
<div class="grid">
<figure class="effect-zoe">
'.get_the_post_thumbnail( get_the_ID(), $size, $attr ).'
<figcaption>
<h2>'.get_the_title().'</h2>
<hr class="light">
<p class="description">'.get_the_content().'</p>
</figcaption>
</figure>
</div>
</div>';
}
else
if ($_SESSION["load_type"] == 'category')
{
$out .= '<div class="small-6 large-6 columns end thumb under">
<div id="case">
<div class="th" id="element" >
<a class="fill-div" href="'. get_permalink($post->ID) .'"></a>
</div>
</div>
<div class="brief">
'.get_the_title().'
<p class="suppy">Supplier</p>
<p>'.get_the_excerpt().'</p>
<a class="more-btn" href="'. get_permalink($post->ID) .'">More</a>
</div>
</div>';
}
else
if ($_SESSION["load_type"] == 'product')
{
$out .= '<div class="small-6 large-3 columns">
<div class="small-6 large-12 columns end no-pad morepro" style="background-image: url(''.the_field(product_image).'')">
<a class="fill-div" href="'. get_permalink($post->ID) .'"></a>
</div>
<h2 class="product-load">'.get_the_title().'</h2>
</div>';
}
endwhile;
endif;
wp_reset_postdata();
die($out);
and heres the part of it that I'm having trouble with and crashes the whole site every time I try to load in a background-image:
if ($_SESSION["load_type"] == 'product')
{
$out .= '<div class="small-6 large-3 columns">
<div class="small-6 large-12 columns end no-pad morepro" style="background-image: url(' '.the_field(product-image).' ')">
<a class="fill-div" href="'. get_permalink($post->ID) .'"></a>
</div>
<h2 class="product-load">'.get_the_title().'</h2>
</div>';
}
enter code here
Can anyone see where I'm going wrong?
Change the following
style="background-image: url(' '.the_field(product-image).' ')"
into the
style="background-image: url('.the_field("product-image").')"
This should work if:
Your "product-image" is custom defined size (if its constant use it without quotes) - or edit your question and explain what it is.
the_field() function need to "return" value and not to echo it. I am mentioning this because by wordpress codex usually use "the_something()" function will not return value, it will just display something. If you want to to return a value it is usually "get_the_something()". It is important because it will break your json object (if that is what you are using on js side)
Example: the_content() vs get_the_content(), or get_the_title() vs the_title() etc...
Quotes within background-image should be optional by this.
if ($_SESSION["load_type"] == 'product'){
$image = the_field(product_image);
$out .= '<div class="small-6 large-3 columns">
<div class="small-6 large-12 columns end no-pad morepro" style="background-image: url('"'.$image.'"')">
<a class="fill-div" href="'. get_permalink($post->ID) .'"></a>
</div>
<h2 class="product-load">'.get_the_title().'</h2>
</div>';
}
and see if it works

PHP link not working - cannot find the mistake

I built a CMS system using CKEditor and KCFinder that store information od a databse via textarea/php. So far so good!
The issue comes to when I want to store and display images that link to themselves. The way I am storing images is exactly the same: There is a textarea where I insert an image via KCFinder/CKEditor. The image is uploaded to the server and the path stored at the database. Later I try to pick up that path from the database to display the image (that part also works) and because I want the image to link to itself, I try to use the same method to insert the url on the link. Problem? The link is missing.
Can anyone point me the error and suggest any solution? I would be so thankful!
Code:
<?php
$sql = "SELECT * FROM php_maskiner ORDER BY timestamp DESC";
$result = mysql_query($sql) or print ('<div class="alert alert-standard fade in">
<a class="close" data-dismiss="alert" href="#">×</a>
<strong>Can't read the database!</strong>
</div>' . $sql . "<br />" . mysql_error());
while($row = mysql_fetch_array($result)) {
$title = stripslashes($row['title']);
$entry = stripslashes($row['entry']);
$images = html_entity_decode($row['images']);
$img_url = $row['images'];
$img_pack = '<div class="mask3 span3">
<a rel="prettyPhoto" href="' . $img_url . '">' . $images . '</a>
</div>';
?>
<article class="span12 post">
<?php echo $img_pack; ?>
<div class="inside">
<div class="span8 entry-content">
<div class="span12">
<h2><?php echo $title; ?></h2>
<p><?php echo $entry; ?></p>
</div>
</div>
</div>
</article>
<?php
}
?>
UPDATE:
I think that this might be a problem caused by CKEditor. In the database the image path is store as: . This is in my understanding what is being outputted. How do I do to output only "/nysida/admin/kcfinder/upload/images/1307594_10243178.jpg"?
Your first mistake is still using the mysql_ extensions to access your databases. You must use PDO (if available):
Example (for mysql):
try {
$DBH = new PDO('mysql:host=localhost;dbname=yourdb;charset=utf8', 'user', 'password');
$DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$STH = $DBH->prepare('SELECT * FROM php_maskiner ORDER BY timestamp DESC');
$STH->execute();
$STH->setFetchMode(PDO::FETCH_OBJ);
while($row = $STH->fetch()) {
$title = $row->title;
$entry = $row->entry;
$images = $row->images;
$img_url = $row->images;
$img_pack =
'<div class="mask3 span3">
<a rel="prettyPhoto" href="'.$img_url.'"><img src="'.$images.'"></a>
</div>';
}
$DBH = null;
} catch (PDOException $e) {
echo '<div class="alert alert-standard fade in">
<a class="close" data-dismiss="alert" href="#">×</a>
<strong>Can\'t read the database!</strong>
</div><br />'.$e;
}
And later in your code:
<?php echo
'<article class="span12 post">
'.$img_pack.'
<div class="inside">
<div class="span8 entry-content">
<div class="span12">
<h2>'.$title.'</h2>
<p>'.$entry.'</p>
</div>
</div>
</div>
</article>';
?>
And regarding the original question: make sure $img_url is not null.

Categories