How to post figures on a new line in php? - php

I want to control when to put figures on a new line in php. I can keep posting figures like so:
<A HREF="./images_local/figname.gif">
<img height=196 width=128 src="./images_local/figname.gif"/></A>
<A HREF="./images_local/figname2.gif">
<img height=196 width=128 src="./images_local/figname2.gif"/></A>
<A HREF="./images_local/figname3.gif">
<img height=196 width=128 src="./images_local/figname3.gif"/></A>
But they all post left to right, until they run out of space, at which point they begin a new line. How do I control when to start posting those figures on a new line?
Thanks.

It is a simple HTML issue and has nothing to do with php, but even if you code HTML in php you could just use the <br> tag for line break.
By the way, it is considered a good practice to keep all HTML tags (<a>) and attributes (href="") in lower case. It just makes your code more readable and consistent with proper HTML markup recommendations. :)

as mentioned above, the <br> works just fine, alternatively you can list your images with :
<ul><li><A HREF="./images_local/figname.gif"></li>
<li><img height=196 width=128 src="./images_local/figname.gif"/></A>
<A HREF="./images_local/figname2.gif">
<img height=196 width=128 src="./images_local/figname2.gif"/></A>
<A HREF="./images_local/figname3.gif">
<img height=196 width=128 src="./images_local/figname3.gif"/></A></li>
</ul>
etc

Related

Prestashop: problem with logo, I don't see it in front end

website: www.e-veloce.com
I don't see logo.
I tried to change src in header.tpl to
<a href="{$base_dir}" title="{$shop_name|escape:'html':'UTF-8'}">
<img class="logo img-responsive" src="https://www.e-veloce.com/presta/img/logo.jpg" alt="{$shop_name|escape:'html':'UTF-8'}"{if $logo_image_width} width="{$logo_image_width}"{/if}{if $logo_image_height} height="{$logo_image_height}"{/if}/>
</a>
after that, I don't see logo
logo.jpg file is in presta/img/logo.jpg - so it looks good
Any ideas ?
It happens after I made SSL certification.
You have indicated an incorrect path, simply delete /presta/. Based on your code, this should work:
<a href="{$base_dir}" title="{$shop_name|escape:'html':'UTF-8'}">
<img class="logo img-responsive" src="https://www.e-veloce.com/img/logo.jpg" alt="{$shop_name|escape:'html':'UTF-8'}"{if $logo_image_width} width="{$logo_image_width}"{/if}{if $logo_image_height} height="{$logo_image_height}"{/if}/>
</a>
Use this:
src="{$base_dir_ssl}img/logo.jpg"; // https://www.e-veloce.com/img/logo.jpg
src="{$base_dir_ssl}presta/img/logo.jpg"; // https://www.e-veloce.com/presta/img/logo.jpg
I found solution. You need to do:
<img class="logo img-responsive" src="img/logo.jpg" alt="Veloce - Chemia od nas, dla Ciebie" width="367" height="54">
so i cut src with https:// only to img/logo.jpg.
Problem is popular, I hope that solution will help someone in future

How Do I Customize the HTML Markup of Images Inserted into WordPress Posts?

I have searched high and low for a solution to this. I want to change the markup of an uploaded image in WordPress from this:
<div id="attachment_906" style="width: 590px" class="wp-caption aligncenter">
<img class="size-full wp-image-906 " title="Image Alignment 580x300" alt="Image Alignment 580x300" src="http://localhost/sandbox/wp-content/uploads/2013/03/image-alignment-580x300.jpg" width="580" height="300">
<p class="wp-caption-text">Look at 580×300 getting some <a title="Image Settings" href="http://en.support.wordpress.com/images/image-settings/">caption</a> love.</p>
</div>
To something more like this:
<figure class="center">
<img class="gallery-img" src="http://lorempixel.com/300/500/">
<figcaption>
<span>A slightly longer caption for the image, which is significantly smaller than the last one. pretty neat!</span>
</figcaption>
</figure>
I understand that much of the markup in the original post needs to stay, but is there any way to customize any of this? Even if I could get the same basic structure (a wrapper, the image, a caption wrapper, the caption) I could take it from there with CSS.
Since I'm developing a theme, I need the options to work with the native WordPress tools. If that isn't the case, I can't work with it.
I had hoped that there would simply be a filter or action that I could apply to do this, but I have had no luck in finding such a thing.
Thanks in advance!
You need to use the image_send_to_editor filter. https://developer.wordpress.org/reference/hooks/image_send_to_editor/
That could look something like this in any one of your active theme or plugin's php files (like functions.php);
function filter_image_send_to_editor($content) {
$content .= '<figure class="center">(Generate your markup here)</figure>';
return $content;
}
add_filter('image_send_to_editor', 'filter_image_send_to_editor');
You'll have to write your own code inside that function, of course.

I want to remove certain parent- and child-divs in all my wordpress posts with php or some other script

Is there a quick way, via script maybe, to remove a certain pair of div's out of all my wordpress posts? For example:
I want to go from this:
<div class="single_textimage">
<div class="youtube_play"><iframe src="-,-"></iframe></div>
<div class="single_textimage_text">Some text.</div>
<div class="single_textimage_copyright">Some text.</div>
</div>
To this:
<div class="youtube_play"><iframe src="-,-"></iframe></div>
AND
From this:
<div class="single_textimage">
<img class="aligncenter size-full wp-image-1700" src="-,-" />
<div class="single_textimage_text">Some text.</div>
<div class="single_textimage_copyright">Some text.</div>
</div>
To this:
<img class="aligncenter size-full wp-image-1700" src="-,-" />
So I want the divs: single_textimage, single_textimage_text and single_textimage_copyright to go.
I hope there is an easy script, or difficult for that matter. Via "php", "mysql" or "jquery" for example, that I can put in test.php in the root or something...
I hope I supplied you with enough information. If I haven't made myself clear enough, please reply. :)
Seems to me like you should be able to take those out of whatever template your using - probably in a PHP include, but I don't really use WordPress, so I wouldn't know where without seeing all your files. If you're bent on using jQuery instead of modifying the template, I would throw in some CSS too, to hide the elements that will be removed:
.single_textimage, .single_textimage_text, .single_textimage_copyright{
display:none;
}
Then you can take the elements you want to keep out of their parent DIVs, and place them right after (or before):
$('.youtube_play, .wp-image-1700').each(function(){
$(this).parent().after($(this));
});
Then you can remove the elements you don't want from the page:
$('.single_textimage, .single_textimage_text, .single_textimage_copyright').remove();
Here's a fiddle: https://jsfiddle.net/3uztorzL/
I would use this search and replace utility to update all of the content in the DB:
https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
You'll need a regex to replace <div class="single_textimage_text">Some text.</div> (assuming the "some text" is different in each post). The utility supports regex replace. This may do it:
<div class="single_textimage_text">(.*?)</div>
Make sure you make a backup before you do the replace.

php prevent items from loading, and load with trigger

I'm rather new to programming, but I'm trying to find a way to do what is described below.
<body>
<div class="gallery">
<img src="photo_1.jpg">
<img src="photo_2.jpg">
<img src="photo_3.jpg">
<!-- trigger for user to load items that weren't downloaded on page load -->
<img src="photo_4.jpg">
<img src="photo_5.jpg">
<img src="photo_6.jpg">
</div>
</body>
I'm trying to find PHP functions that would, ideally, only load the first 3 img embeds within a certain class/ID, and have a clickable trigger to request the remaining img embeds from the server.
I don't know if this is how the typical message board software(such as vBulletin) handles things with "spoiler tags" .. as in whether or not it actually prevents loading, or just hides the content from view. Something like that, if it actually prevents loading, is what I'd like to know about.
First, this has nothing to do with PHP.
The only way to prevent a page from loading the image is to not include the tags on the page.
You could accomplish this a couple ways:
Place the last three photos inside a hidden container and use a Javascript click event to display them when wanted, but that still loads the images when the page is loaded.
Or, you can use an AJAX call to retrieve the items only on demand. Unless they are really large images I would think the first option the best.
<div class="gallery">
<img src='photo1.jpg'/>
<img src='photo2.jpg'/>
<img src='photo3.jpg'/>
<a href="#" onClick='document.getElementById("hidden-gallery").display="visible"'>show more</a>
<div id="hidden-gallery" class="hidden-gallery" style="display:none">
<img src='photo4.jpg'/>
<img src='photo5.jpg'/>
<img src='photo6.jpg'/>
</div>
</div>
I recognize that embedding CSS styles and Javascript the way I did is not the preferred method but it is there just for the examples sake.

img src won't work with php variables

<a href="'.$productLink.'" alt="'.$productName.'">
<img src="'.$productImg1URL.'" alt="'.$productName.' '.$productType.' ">
</a>
Hello the img src is actually in a different directory /images
I know this is probably super easy but Ive spent an hour on it and nothing. The page works but doesn't show the directory. Please help the rookie. I took out the < in front of the a href and img src couldn't make the page display
There are two ways of doing this:
Firstly, outside of a code block:
<?php
// code here
?>
<a href="<?= $productLink ?>" alt="<?= $productName ?>">
<!-- or -->
<img src="<?echo $productImgURL; ?> alt="<?php echo $productName . ' ' . $productType ?>">
</a>
The first form is called the short open tag and has to be enabled in your php.ini which it almost always is.
Or if you're doing this inside a code block:
<?php
echo <<<END
<a href="$productLink" alt="$productName">
<img src="$productImgLURL" alt="$productName $productType">
</a>
END
The <<<END is a heredoc and I usually prefer it to using a big string within double quotes, which requires escaping contained double quotes.
Job #1 when you have a problem with code that is generating HTML, is look at the output source and compare it with what you expect. I've had problems like this before and they usually vanished when I stopped thinking about the PHP code, and looked at the actual output.
What is the content of $productImg1URL - and if the images that it's referencing are in the URL starting /images/ - does that start $productImg1URL. If it's just the name of an image, but without the path - you have to put that into place.

Categories