Simple php image changer with xml data - php

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>

Related

add CCS style which depends on php IF statement inside mysqli_fetch_array

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:

WordPress: echoing just the first 60characters of the post title

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!

Returning Art Canvas name and Size inside a query

Hi Guys I need some help here on a project that I am currently working on this is the index function on a controller in my Web App that I have made for a client that everything is working fine but I need to return the title and size of the canvas with the image here is my controller code
public function index(){
$query_result = $this->Art_m->get_art();
error_log(count($query_result));
$canvas = '';
$counter = 0;
foreach($query_result as $row) {
$title = $row['canvas_name'];
$image = $row['canvas_image'];
$size = $row['canvas_size'];
error_log($title . $image . $size);
if($counter == 0){
$canvas .= '<div class="item">
<a rel="prettyPhoto" class="thumbnail" href="' . base_url() . 'data/uploads/canvases/' . $image . '" alt="' . $title . '">
<img src="' . base_url() . 'data/uploads/canvases/' . $image . '" alt="' . $title . '"/>
</a>
</div>';
} else {
$canvas .= '<div class="item">
<a rel="prettyPhoto" class="thumbnail" href="' . base_url() . 'data/uploads/canvases/' . $image . '" alt="' . $title . '">
<img src="' . base_url() . 'data/uploads/canvases/' . $image . '" alt="' . $title . '"/>
</a>
</div>';
}
$counter++;
}
$data['canvas'] = $canvas;
$data['title'] = 'Ali Cockburn Abstract Art';
$data['art'] = $this->Art_m->get_art();
$data['content'] = 'art_view';
$this->load->view('templates/site/template',$data);
}
The code works perfectly, but how do I echo out the $title and $size above the <a> tag inside of a <p> tag? Can someone please assist?

Joomla menu: putting text BEFORE image

I'm building a website with a vertical drop-down menu. One of the menu items should contain an image and the menu title.
Joomla puts the image before the text, in the following way:
<li class="item-153 current active"><a class="menu_immagine" href="whatever" ><img src="whatever.png" alt="whatever" /><span class="image-title">whatever</span></a></li>
What I'd like to do is putting the text before the image, like this:
<li class="item-153 current active"><span class="image-title">whatever</span><a class="menu_immagine" href="whatever" ><img src="whatever.png" alt="whatever" /></a></li>
How can I do this in Joomla?
Thank you very much for your help...
Thanks to Lodder, I made a template override. Then I modified the file myTemplate/html/mod_menu/default_component.php.
I changed this
if ($item->menu_image)
{
$item->params->get('menu_text', 1) ?
$linktype = '<img src="' . $item->menu_image . '" alt="' . $item->title . '" /> <span class="image-title">' . $item->title . '</span> ':
$linktype = '<img src="' . $item->menu_image . '" alt="' . $item->title . '" />';
}
else {
$linktype = $item->title;
}
to this:
if ($item->menu_image)
{
$item->params->get('menu_text', 1) ?
$linktype = '<span class="image-title">' . $item->title . '</span> <img src="' . $item->menu_image . '" alt="' . $item->title . '" /> ':
$linktype = '<img src="' . $item->menu_image . '" alt="' . $item->title . '" />';
}
else
{
$linktype = $item->title;
}
That's it! That was so easy, after all, that's a matter of knowing how to do it! ;)

Why does my translation not work & how can I fix it?

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>';

Categories