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
Related
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 . '';
?>
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?
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! ;)
I have been trying to create a page on wordpress that displays all categories with images, title and links of all categories of a particular post_type.
I have added the following code to my functions.php file:
function show_categories($excl=''){
$categories = get_the_category($post->ID);
if(!empty($categories)){
$exclude=$excl;
$exclude = explode(",");
foreach ($categories as $cat) {
if(!in_array($cat->cat_ID)) {
echo '<div class="product-category">';
// echo '<p>' . $cat->category_description . '</p>';
echo '<a href="' . get_category_link( $cat->term_id ) . '" />';
echo '<img src="';
echo z_taxonomy_image_url($cat->term_id, 'products') . '" />';
echo '</a>';
echo '<h2><a href="' . get_category_link( $cat->term_id ) . '" class="cat-link"';
echo '/>' . $cat->cat_name . '</a></h2>';
echo '<a href="' . get_category_link( $cat->term_id ) . '" class="more-info" >Info</a>';
echo '</div>';
}
}
}
}
Now the problem is: It only displays the categories of the latest post. If the latest post is included to all categories, all categories will show up, if not it will only show the categories relevant to the latest post.
I call this function on the file archive-products.php like this:
<?php show_categories(); ?>
Any ideas?
This is the page: http://giannacamilotti.com/products/
I found a solution, the code below worked!
function show_categories($excl=''){
$args=array(
'post_type' => 'Products'
);
$categories = get_categories($args);
if(!empty($categories)){
$exclude=$excl;
$exclude = explode(",");
foreach ($categories as $cat) {
echo '<div class="product-category ' . $cat->cat_name . ' ">';
echo '<a href="' . get_category_link( $cat->term_id ) . '" />';
echo '<img src="';
echo z_taxonomy_image_url($cat->term_id, 'products') . '" />';
echo '</a>';
echo '<h2><a href="' . get_category_link( $cat->term_id ) . '" class="cat-link"';
echo '/>' . $cat->cat_name . '</a></h2>';
echo '<a href="' . get_category_link( $cat->term_id ) . '" class="more-info" >Info</a>';
echo '</div>';
}
}
}
Please let me know if anyone has a better and cleaner solution.
So I am using Wordpress and I have to have a specific logo on a specific page. From research I have to use conditional logic to swap the existing logo with another depending on the current page. Everything I have tried seems to just break the theme.. Any help on guiding me in the correct direction? So basically every page except page_id=79 would have the same logo in the header.
<a id="logo" href="<?php echo home_url(); ?>">
<?php
if(!empty($options['use-logo'])) {
$default_logo_id = (!empty($options['retina-logo'])) ? 'id="default-logo"' : null;
echo '<img '.$default_logo_id.' alt="'. get_bloginfo('name') .'" src="' . $options['logo'] . '" />';
if(!empty($options['retina-logo'])) echo '<img id="retina-logo" alt="'. get_bloginfo('name') .'" src="' . $options['retina-logo'] . '" />';
} else { echo get_bloginfo('name'); }
?>
</a>
<?php if ( is_page(79) ) { ?>
What to displayed on page 79.
<?php } else { ?>
What will be displayed everywhere else.
<?php } ?>
This should work.
Try using get_queried_object_id();
<a id="logo" href="<?php echo home_url(); ?>">
<?php
if(!empty($options['use-logo']) && get_queried_object_id() != 79) {
$default_logo_id = (!empty($options['retina-logo'])) ? 'id="default-logo"' : null;
echo '<img '.$default_logo_id.' alt="'. get_bloginfo('name') .'" src="' . $options['logo'] . '" />';
if(!empty($options['retina-logo'])) echo '<img id="retina-logo" alt="'. get_bloginfo('name') .'" src="' . $options['retina-logo'] . '" />';
} else { echo get_bloginfo('name'); }
?>
</a>
The url of your logo image is contained within $options['logo']. You should be able to modify this in the admin section of your WordPress installation (try looking in "Appearance -> Header").