I'm struggling with a translation in the footer navigation. the translation for the navigation works fine but I can't figure out how to set the translation for text_1 & text_2. I would appreciate any help a lot!
This is my PHP for the language:
<?php
class l
{
public static function lang($name)
{
$l = array();
// Footer
$l['text_1'] = "Hello";
$l['text_2'] = "World";
return $l[$name];
}
public static function __callStatic($name, $arguments)
{
return self::lang($name);
}
}
?>
And this is what I try to translate (text_1 & text_2):
<?php
class footer_nav
{
public function get_footer_nav()
{
$lang = language::getLang();
if (isset($_GET['page']))
$page = $_GET['page'];
else
$page = 'home';
$ret = '
<a href="' . $lang . '/private" ';
if ($page == 'private')
$ret .= ('class="active"');
$ret .= '>' . l::confidence() . '</a>
<a href="' . $lang . '/rules" ';
if ($page == 'rules')
$ret .= ('class="active"');
$ret .= '>' . l::rules() . '</a>
<a href="' . $lang . '/reklama" ';
if ($page == 'reklama')
$ret .= ('class="active"');
$ret .= '>' . l::adv() . '</a>
<a href="' . $lang . '/contact" ';
if ($page == 'contact')
$ret .= ('class="active"');
$ret .= '>' . l::contacts() . '</a>
';
return $ret;
<div class="soc_box">
<p class="soc_box_txt">
' . l::text_1() . '<br />
' . l::text_2() . '
</p>
</div>
}
}
?>
You can take the divs out of the Php code like this:
?>
<div class="soc_box">
<p class="soc_box_txt">
' . l::text_1() . '<br />
' . l::text_2() . '
</p>
</div>
<?php
Just close php code with ?> add html code and start php code again with < ?php or:
echo '<div class="soc_box">';
echo '';
echo '';
echo '<p class="soc_box_txt">
\' . l::text_1() . \'<br />
\' . l::text_2() . \'
</p>';
echo ' </div>';
Related
I have function that returns html code
And I want to add foreach loop to return code
I try this code but I get an error
return '<section class="n-hero-section-two rebuild" ' . str_replace('\\', "", $bg_img) . '>
...
<div class="n-hero-two-box">
<div class="n-hero-two-main-text">
' . $main_section_tagline .'
' . $main_section_title . '
</div>
<div class="n-hero-two-form-cat">
...
<div id="search-headline" class="panel-collapse collapse in" role="tabpanel">
...
<ul class="live-filter live-filter-nd">'
// I want to add foreach here
foreach (array_combine($allprofessionsLinks, $allprofessions) as $allprofessionsLinks => $allprofessions) {
// echo '<option value="' . $allprofessionsLinks . '">' . $allprofessions . '</option>';
echo"<li>" . $allprofessions . "</li>";
}
'</ul>
</div>
</form>
...
</div>
</div>
</section>';
Add foreach result to string and add string to return
$live_search_result = '';
foreach (array_combine($allprofessionsLinks, $allprofessions) as $allprofessionsLinks => $allprofessions) {
$live_search_result = $live_search_result . "<li>" . $allprofessions . "</li>";
}
And add $live_search_result string to result
<ul class="my-custom-class">'
. $live_search_result .
'</ul>
I want to add CCS style which depends on php IF statement. I have found something: changing the style inside "if" statement, but somehow it doesn`t work, maybe because of WHILE statement in my code.
<?php
$possible_lang_list = mysqli_query($con,
'SELECT * FROM page WHERE title = "lang" ORDER BY name1 ASC');
while ($row = mysqli_fetch_array($possible_lang_list)) {
echo '
<div class="language" id="' . $row['name2'] . '">
<p>' . $row['name1'] . '</p>
</div>
';
}
?>
I want to display only div class="language" where $row['name2'] == $x, with possibility to display whole class "language" with JavaScript. Could anyone help?
I have tried:
while ($row = mysqli_fetch_array($possible_lang_list)) {
if ($row['name2'] == $x) {
?>
<div style="display:block;">
<?php } else {
?>
<div style="display:none;">
<?php
echo '
<div class="" id="' . $row['name2'] . '">
<p>' . $row['name1'] . '</p>
</div>
</div>';
}
}
now it is working:
while ($row = mysqli_fetch_array($possible_lang_list)) {
if ($row['name2'] == $x) {
?>
<div style="display:block;">
<?php } else {
?>
<div style="display:none;">
<?php }
echo '
<div class="" id="' . $row['name2'] . '">
<p>' . $row['name1'] . '</p>
</div>
</div>';
}
Try this code :
while ($row = mysqli_fetch_array($possible_lang_list))
{
if($row['name2'] == $x)
{
echo '<div class="language" id="' . $row['name2'] . '"><p>' . $row['name1'] . '</p>
</div>';
}
else
{
echo '<div class="" id="' . $row['name2'] . '"><p>' . $row['name1'] . '</p>
</div>';
}
}
Hope it will work
Assign a style element with a true/false ternary, like below. Then just output it!
<?php
while ($row = mysqli_fetch_array($possible_lang_list)) {
$class = ($row['name2'] == $x) ? 'language' : null;
echo '
<div class="'.$class.'" id="' . $row['name2'] . '">
<p>' . $row['name1'] . '</p>
</div>
';
}
And then:
I am styling a WordPress Theme and I would like to make sure that if the post title is longer than 60 characters it shows the first 6ß0 characters +
three points (...) at the end
In Native Php would like:
<?php
if (strlen($title) <= 60) {
echo %title
} else {
echo (substr($title, 60) . "..."
}
?>
My problem is that inside WordPress the syntax of variables is not $title but %title as you could see in the code:
<?php previous_post_link( '%link', '%title ' ); ?>
My questions are:
How would be the final IF inside WordPress
How would be in shorthand if/else (ternary) form?
Thanks
You achieve this by creating your custom post_nav function
<div class="prev-posts pull-left">
<?php
$prev_post = get_previous_post();
if ($prev_post)
{
$prev_title = strip_tags(str_replace('"', '', $prev_post->post_title));
if (strlen($prev_title) >= 60) //<-- here is your custom checking
{
$prev_title = (substr($prev_title, 0, 60)) . "...";
}
echo "\t" . '<a rel="prev" href="' . get_permalink($prev_post->ID) . '" title="' . $prev_title . '" class=" "><strong><<< "' . $prev_title . '"</strong></a>' . "\n";
}
?>
</div>
<div class="next-posts pull-right">
<?php
$next_post = get_next_post();
if ($next_post)
{
$next_title = strip_tags(str_replace('"', '', $next_post->post_title));
if (strlen($next_title) >= 60) //<-- here is your custom checking
{
$next_title = (substr($next_title, 0, 60)) . "...";
}
echo "\t" . '<a rel="next" href="' . get_permalink($next_post->ID) . '" title="' . $next_title . '" class=" "><strong>"' . $next_title . '" >>></strong></a>' . "\n";
}
?>
</div>
Hope this helps!
Here I am using this code with an xml file.
I would like to display more images not just one -> for example: slideshow, or a simple "image rotator/changer". How can I do this?
PHP:
<?php
if ($this->aktuelles) {
$id = 1;
foreach ($this->aktuelles as $aktuelle) {
if ($aktuelle->url == '') {$url = '';}
else {$url = $aktuelle->url; $target = 'target="_blank"'; $btn = '' . 'weiter lesen';}
//$text = substr($aktuelle->text, 0, 1150) . ' ...';
$text = $aktuelle->text;
echo '
<article class="clearfix">
<a class="linkimage" href="images/aktuelles/' . $aktuelle->image . '" data-rel="prettyPhoto"><img src="images/aktuelles/' . $aktuelle->image . '" alt="' . $aktuelle->title . '"/></a>
<h4 class="title">' . $aktuelle->title . '</h4>
<p>' . $text . '</p>
' . $btn . '
</article>
<hr>
';
$id++;
}
unset($id);
}
elseif ($this->aktuelle) {
$aktuelle = $this->aktuelle;
$title = $aktuelle->title;
$url = SITE_PATH . $aktuelle->url;
$text = $aktuelle->text;
$image = $aktuelle->image;
echo '
« Zurück<br><br>
<article class="clearfix">
<a class="linkimage" href="images/aktuelles/' . $image . '" data-rel="prettyPhoto"><img src="images/aktuelles/' . $image . '" alt="' . $title . '"/></a>
<h4 class="title">' . $title . '</h4>
<p>' . $text . '</p>
</article>
';
unset($aktuelle);
}
?>
Here is the xml code what i wrote:
<?xml version="1.0" encoding="UTF-8"?>
<aktuelles>
<aktuelle>
<title><![CDATA[THIS IS THE TITLE]]></title>
<image>image1.jpg</image>
<text>
<![CDATA[
This is the content<br>
</text>
<url></url>
</aktuelle>
</aktuelles>
There are a few things that won't translate on my website that are inside PHP. Since it's inside PHP, the normal qTranslate quick tag won't work. Is there a simple code that could help me translate these words? Should it go on the same page where the translations are located?
This is the code for the what I need translated inside the PHP (Location:, Venue:, etc):
<div class="event-text">
<h2 class="event-title">' . get_the_title($post->ID) . '</h2>
<ul class="event-meta">';
if ($event_location != null) {
echo '
<li><span>Location:</span>' . $event_location . '</li>';
}
if ($club != null) {
echo '
<li><span>Venue:</span>' . $club . '</li>';
}
if ($event_allday == 'yes'){
echo '<li><span>Length:</span>All Day</li>';
} elseif ($tstart) {
echo '<li><span>Length:</span>' . $tstart . '';
} if ($tend) {
echo ' – ' . $tend . '</li>';
}
echo '
<li>';
if (get_post_meta($post->ID, 'event_out', true) == 'yes') {
echo '<div class="event-cancel-out"><p>Sold Out</p></div><!-- end .event-cancel-out -->';
} elseif (get_post_meta($post->ID, 'event_cancel', true) == 'yes') {
echo '<div class="event-cancel-out"><p>Canceled</p></div><!-- end .event-cancel-out -->';
}elseif (get_post_meta($post->ID, 'event_free', true) == 'yes') {
echo '<div class="event-cancel-out"><p>Free Entry</p></div><!-- end #event-cancel-out -->';
} else {
echo '<div class="event-tickets"><a href="' . $event_ticket . '" >Buy Tickets</a></div><!-- end #event-tickets -->';
}
echo '</li>
</ul><!-- end ul.event-meta -->';
echo '
' . the_content() . '
</div><!-- end .event-text -->';
Yes, it is a theme file for Wordpress. I fixed these by changing to the following codes:
echo __("<li><span><!--:en-->Location: <!--:--><!--:ja-->場所:<!--:--></span>") . $event_location . '</li>';
echo '<div class="event-cancel-out"><p>' . __('<!--:en-->Sold Out<!--:--><!--:ja-->売り切れ<!--:-->') . '</p></div><!-- end .event-cancel-out -->';