i just started learning Php, right now im trying to convert a HTML page to a Wordpress Theme. I have trouble trying to display images...
In my HTML page i have imgs like:
<img class="mainlogoclean" src="images/akbarlogoclean.png"/>
When i tried to change it with php my page just stop working:
<img class="mainlogoclean" src="<?php echo /images/akbarlogoclean.png ?>"/>
You will have to echo a string for it to work properly.
i.e. have /images/akbarlogoclean.png inside single/double quotes.
You can learn more about how echo works Here
The code could be written in following ways
<img class="mainlogoclean" src="<?php echo "/images/akbarlogoclean.png" ?>"/>
Or you could also try the shorthand version of using echo
<img class="mainlogoclean" src="<?="/images/akbarlogoclean.png" ?>"/>
Both of these give the following output
<img class="mainlogoclean" src="/images/akbarlogoclean.png"/>
Related
Hi guys wondering how I can manually add a link from Joomla intro article images to their corresponding article and also add a title tag to the link.
Ideally the way I want to do this is to for example wrap an achor tag around the image reference in the blog-item.php file (also want to achieve this for generic articles). And then within the anchor tag capture the related image alt tag and populate the title tag with that value.
Below is where I'm at. It's not currently working, not sure why as it should be pretty straight forward. I'm not a php developer, wondering what i'm missing.
Also already cleared both browser and joomla caches after my changes.
Any help would be appreciated, cheers guys
<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>" title="<?php echo htmlspecialchars($images->image_intro_alt); ?>">
<img
src="<?php echo htmlspecialchars($images->image_intro); ?>"
alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/>
</a>
To make your code work, add just before your code.
<?php $images = json_decode($this->item->images); ?>
and your code will start working.
Already tested and it worked.
I am trying to echo in php the image description in the data-caption of the clearing image gallery of Foundation3 but it is not working. Here is my code:
<li class="clearing-feature">
<a href="administration/galleri/kcfinder/upload/images/Galleri1/1.jpg">
<img data-caption="<?php echo $myDataBild1 ?>;" src="kcfinder/upload/images/Galleri1/1.jpg"></a>
</li>
This is not working. The image gallery is still working correctly but the caption in this picture is not showing. How can I correct this?
NOTE: The php $myDataBild1 is a txt file with text inserted via CKEditor and it is working just fine. Let me know if you need the code and the variable is shown if I echo it anywhere else.
Misplaced comma - also try by using addslashes.
<img data-caption="<?php echo addslashes($myDataBild1); ?>" src="kcfinder/upload/images/Galleri1/1.jpg"></a>
So,
My images are located in wp-content/themes/mytheme/images
Originally, when i converted my site from html/css the path looked like this:
<img src="images/myimage.png" alt="some text" />
That did not work and I have now tried two diffrent solutions:
<img src='<?php get_template_directory_uri(); ?>/images/myimage.png'>
and
<img src="<?php bloginfo(); ?>images/myimage.png">
Have i missed something? I am new to wordpress an php and would appreciate some help. Thanks!
You almost had it. You left off echo.
http://codex.wordpress.org/Function_Reference/get_template_directory_uri
Output the URI
<?php echo get_template_directory_uri(); ?>
The full result is:
<img src='<?php echo get_template_directory_uri(); ?>/images/myimage.png'>
I recommend you use Drupal if you haven't gotten too far with WP already. :)
Try
get_stylesheet_directory(). '/images';
/images/myimage.png">
This will return the images directory path in the currently selected theme, even if it's a child theme.
Function Reference/get stylesheet directory
Background: using zurb foundation's data-interchange, running in Concrete5.
Using php inside an img src path is easy enough.
<img src="<?php echo $this->getThemePath(); ?>/images/myImage.png" \>
But when I go further, passing parameters and such to use data-interchange, things get messy. I know it probably has something to do with quotes or parentheses and such. Help with this code?
<img src="<?php echo $this->getThemePath(); ?>/images/myImage.png" data-interchange="[<?php echo $this->getThemePath(); ?>/images/myImage.png, (default)], [<?php echo $this->getThemePath(); ?>/images/myImage_#2x.png, (retina)]">
Try removing src="<?php echo $this->getThemePath(); ?>/images/myImage.png". It shouldn't be necessary since you have that file specified as the default in the data-interchange parameter.
I've been able to put some code together and get a QR code to display on my site. Now I'm attempting to get the QR Code to open a larger version inside colorbox. This is the code I've got so far:
<a href="<?php echo $????; ?>" title="<?php echo $heading_title; ?>"
class="colorbox" rel="colorbox">
<img src="http://chart.apis.google.com/chart?chs=250x250&cht=qr&chld=L&chl=
<?php $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; echo $url; ?>"
alt="Product QR Code" width="80" height="80" style="float: right" /></a>
All the code for colorbox is on this page already as I have products that use this very function. The original code said echo $popup but when I use that it shows me the main product image so that's no good. What I can't figure out is what to do with echo in the href section so it calls the image again in the pop-up box but in a larger size?
I've tried using the same url as with the img src but it only returns garbage characters in the pop-up box and doesn't know to turn it into an image instead.
Thanks for your time!
When you assign colorbox, set the photo property to true. Example:
$('a.example').colorbox({photo:true});
Colorbox normally uses a regex to determine if a link is pointing to an image or not, but the URL you are using isn't going to pass that regex.