Joomla menu: putting text BEFORE image - php

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! ;)

Related

wordpress php can't combine string with code

add_filter('wp_nav_menu_objects', 'my_wp_nav_menu_objects', 10, 2);
function my_wp_nav_menu_objects( $items, $args ) {
// loop
foreach( $items as &$item ) {
// vars
$image = get_field('menu_item_image', $item);
// append image
if( $image ) {
$item->title .= '<img class="ttl" src="' . <?php echo
$image['url']; ?> . '" alt="' . <?php echo $image['alt']; ?> . '" />';
}
}
// return
return $items;
}
What am I doing wrong? New to PHP and WordPress functions. The problem seems to be in the append image section.
replace this:
$item->title .= '<img class="ttl" src="' . <?php echo
$image['url']; ?> . '" alt="' . <?php echo $image['alt']; ?> . '" />';
for this
$item->title .= '<img class="ttl" src="' .$image['url']. '" alt="' . $image['alt'] . '" />';
you cannot use this <?php echo $image['alt']; ?> inside echo '...'
Reference: http://php.net/manual/en/function.echo.php

How to add a "active" class to a carousel first element

I'm developing a News website in Wordpress, and I need to show in a bootstrap carousel the first three posts, my problem is that I need to add the "active" class only at the first of the three elements, but really don't know how to. Here's my code:
<?php
$args = array('numberposts' => '3');
$recent_posts = wp_get_recent_posts($args);
foreach ($recent_posts as $recent) {
echo '<div class="item active"><a href="' . get_permalink($recent["ID"]) . '" title=" ' . esc_attr($recent["post_title"]) . '" >' .$recent["post_date"] . ': <strong>' .$recent["post_title"] . '</strong></a></div>';
}
?>
I've already tried a answer found on this site (this one):
$isFirst = true;
foreach ($recent_posts as $recent) {
echo '<div class="item' . $isFirst ? ' active' : '' . '"><a href="' . get_permalink($recent["ID"]) . '" title=" ' . esc_attr($recent["post_title"]) . '" >' .$recent["post_date"] . ": <strong>" .$recent["post_title"] . '</strong></a></div>';
$isFirst = false;
?>
but it just printed me the "active" words.
Thanks for your help
You need to set $i so that you can count how many times you have gone through the loop and do some logic with it, like in my example below. Instead of having two lines of code that are nearly identical like I have done below though, you should be able to do the if conditional right around the class active. I didn't do that so you could clearly see the conditional and the count of the loops through the array.
<?php
$args = array('numberposts' => '3');
$recent_posts = wp_get_recent_posts($args);
$i = 0;
foreach ($recent_posts as $recent) {
if ($i == 0) {
echo '<div class="item active"><a href="' . get_permalink($recent["ID"]) . '" title=" ' . esc_attr($recent["post_title"]) . '" >' .$recent["post_date"] . ': <strong>' .$recent["post_title"] . '</strong></a></div>';
} else {
echo '<div class="item"><a href="' . get_permalink($recent["ID"]) . '" title=" ' . esc_attr($recent["post_title"]) . '" >' .$recent["post_date"] . ': <strong>' .$recent["post_title"] . '</strong></a></div>';
}
$i++;
}
?>

Displaying an image via acf in the theme header

I am using AFC Pro and created an options pafe so tjhat the user can upload a new header logo whenever he wants to.
The ACF field is called "headerlogo".
What I want now is that the Logo gets replaced by my theme automatically.
My Variables are:
$headerlogo = wp_get_attachment_image_src(get_field('headerlogo', 'option'), 'full');
$default_logo = '<img src="'echo .$headerlogo[0].'" alt="SITE Logo">';
they get called in:
echo '<a href="'. esc_url( home_url( '/' ) ) .'">
' . $default_logo . '
</a>';
But the Output is:
<a href="http://www.xxx.de/">
<img src="" alt="SITELogo">
</a>
What am I doing wrong here?
Thank in advance.
This should work:
<?php
$headerlogo = get_field('headerlogo');
if( !empty($headerlogo) ):
$default_logo = '<img src="'. $headerlogo['url'] . '" alt="' . $headerlogo['alt'] . '" />';
endif;
echo '' . $default_logo . '';
?>

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?

Apostrophes in php code

Can I have the following code:
foreach ( $categories as $category ) {
echo '<div class="wwd">
<img src="/images/' . $category->name . $category->term_id . '.jpg" alt="' . $categories->category_name . '" />
<div class="wwd-title">' . $category->name . '</div><br/>
</div>';
}
I am trying to add this code before /images/
<?php bloginfo('template_directory'); ?>
At present the code generates the img src="/images/..." but I want the sites url to go before the /images, when I have tried it I cant seem to get it to either work or display the correct path. The problem seems to with the apostrophe types used but I cant seem to figure out what should go where.
Thanks
Paul
the wordpress bloginfo function outputs the data to the browser. Instead use get_template_directory_uri to save the result to a variable:
$templateurl = get_template_directory_uri();
foreach ( $categories as $category ) {
echo '<div class="wwd">
<img src="' . $templateurl . '/images/' . $category->name . $category->term_id . '.jpg" alt="' . $categories->category_name . '" />
<div class="wwd-title">' . $category->name . '</div><br/>
</div>';
}
bloginfo will try to echo out the value of the parameter specified so you should try another method of just getting the information you want it. Say for example bloginfo returned your template directory you could do this:
foreach ( $categories as $category ) {
echo '<div class="wwd">
<img src="' . bloginfo('template_directory') . '/images/' . $category->name . $category->term_id . '.jpg" alt="' . $categories->category_name . '" />
<div class="wwd-title">' . $category->name . '</div><br/>
</div>';
}
The get_template_directory function might be more appropriate: http://codex.wordpress.org/Function_Reference/get_template_directory

Categories