jQuery Popup not working with output from PHP - php

I'm looking to correct this script form popup each image with is corresponding texts. Actually it popup with all text in MySQL. Why isn't it showing the respective text for each image?
<?php
while ( $alaune = mysqli_fetch_assoc( $resultat6 ) ) {
if ( ! empty( $alaune ) ) {
echo '<div class="single_iteam"><img alt="" src="changements/une/images/' . $alaune["alaunePic"] . '" class="alaunePic">';
echo '<div class="slider_article">';
echo '<h2><a class="slider_tittle" href="#">' . $alaune["alauneTitre"] . '</a></h2>';
echo '<p class="alaunetexte truncate">' . $alaune["alauneTexte"] . '</p>';
?>
Lire la suite...
<?php echo '</div>';
echo '</div>';
}
}
echo '</div><div class="modal" id="modal-name"><div class="modal-sandbox"></div><div class="modal-box"><div class="modal-header"><div class="close-modal">✖</div>';
foreach ( $resultat6 as $alaune ) {
echo '<h1>' . $alaune["alauneTitre"] . '</h1><p>' . $alaune["alauneTexte"] . '</p>';
}
echo '</div>';
echo '<div class="modal-body"><br /><button class="close-modal"> Fermer </button></div></div></div>';
?>
Please have a look. Best regards.

Your second loop cannot iterate through the mysqli_result object. You need either to iterate again through results using mysqli_fetch_assoc or a better solution is to temporary store output of all modals in the array during while iteration and then after while loop, output it. Also, use integer variable to increment it during while loop and assign it as a suffix to modal id, that would differentiate modal for each record:
<?php
$modals = [];
$key = 1;
while ( $alaune = mysqli_fetch_assoc( $resultat6 ) ) {
if ( ! empty( $alaune ) ) {
echo '<div class="single_iteam"><img alt="" src="changements/une/images/' . $alaune["alaunePic"] . '" class="alaunePic">';
echo '<div class="slider_article">';
echo '<h2><a class="slider_tittle" href="#">' . $alaune["alauneTitre"] . '</a></h2>';
echo '<p class="alaunetexte truncate">' . $alaune["alauneTexte"] . '</p>';
?>
Lire la suite...
<?php echo '</div>';
echo '</div>';
$tempModal = '<div class="modal" id="modal-name-' . $key . '"><div class="modal-sandbox"></div><div class="modal-box"><div class="modal-header"><div class="close-modal">✖</div>' .
'<h1>' . $alaune["alauneTitre"] . '</h1><p>' . $alaune["alauneTexte"] . '</p></div>' .
'<div class="modal-body"><br /><button class="close-modal"> Fermer </button></div></div></div>';
$modals[] = $tempModal;
$key++;
}
}
echo '</div>';
foreach($modals as $modal){
echo $modal;
}
?>

Related

How to make the first accordion tab open and the rest closed in wordpress

I am having an issue in incrementing the class="accordion-collapse collapse show so that the first accordion tab should open and the closed. This is how I have doneclass="accordion-collapse collapse '.if($i++){.'show'.}.'" . I am do it in a while loop.
if ( $the_query->have_posts() ) {
echo '<div class="accordion" id="accordionPanelsStayOpenExample">';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<div class="accordion-item">';
echo ' <h2 class="accordion-header" id="panelsStayOpen-heading'.get_the_ID().'">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#panelsStayOpen-collapse'.get_the_ID().'" aria-expanded="true" aria-controls="panelsStayOpen-collapse'.get_the_ID().'">'
. get_the_title() . '
</button>
</h2>';
echo '<div id="panelsStayOpen-collapse'.get_the_ID().'" class="accordion-collapse collapse '.($i++.'show'.).'" aria-labelledby="panelsStayOpen-heading'.get_the_ID().'">
<div class="accordion-body">
'
.the_content() . '
</div>
</div>';
}
echo '</div>';
echo '</div>';
} else {
// no posts found
}
I am expecting the first according to open and the rest closed
Try this :-
EDITED.
<?php
$flag = true;
if ($the_query->have_posts()) {
echo '<div class="accordion" id="accordionPanelsStayOpenExample">';
while ($the_query->have_posts()) {
$the_query->the_post();
$show_class = $flag == true ? 'show' : '';
$collapsed = $flag == true ? '' : 'collapsed';
echo '<div class="accordion-item">';
echo ' <h2 class="accordion-header" id="panelsStayOpen-heading' . get_the_ID() . '">
<button class="accordion-button '.$collapsed.'" type="button" data-bs-toggle="collapse" data-bs-target="#panelsStayOpen-collapse' . get_the_ID() . '" aria-expanded="true" aria-controls="panelsStayOpen-collapse' . get_the_ID() . '">'
. get_the_title() . '
</button>
</h2>';
echo '<div id="panelsStayOpen-collapse' . get_the_ID() . '" class="accordion-collapse collapse ' . $show_class . ' " aria-labelledby="panelsStayOpen-heading' . get_the_ID() . '">
<div class="accordion-body">
'
. the_content() . '
</div>
</div>';
$flag = false;
}
echo '</div>';
echo '</div>';
} else {
// no posts found
}

Add 'Watermark' to images with php _code

I have a website where users may upload images...
I need to add my logo (watermark) to the images every single time to uploaded.
How can I do so?
Anybody have a good tutorial, article or example for this? Or know of any function in php which I would need to find the position of the watermark?
<?php
if(houzez_edit_property()) {
$property_images = get_post_meta( $property_data->ID, 'fave_property_images', false );
$featured_image_id = get_post_thumbnail_id( $property_data->ID );
$property_images[] = $featured_image_id;
$property_images = array_unique($property_images);
if (!empty($property_images[0])) {
foreach ($property_images as $prop_image_id) {
$is_featured_image = ($featured_image_id == $prop_image_id);
$featured_icon = ($is_featured_image) ? 'text-success' : '';
$img_available = wp_get_attachment_image($prop_image_id, 'thumbnail');
if (!empty($img_available)) {
echo '<div class="col-md-3 col-sm-4 col-6 property-thumb">';
echo wp_get_attachment_image($prop_image_id, 'houzez-item-image-1', false, array('class' => 'img-fluid'));
echo '<div class="upload-gallery-thumb-buttons">';
echo '<button class="icon icon-fav icon-featured" data-property-id="' . intval($property_data->ID) . '" data-attachment-id="' . intval($prop_image_id) . '"><i class="houzez-icon icon-rating-star full-star '.esc_attr($featured_icon).'"></i></button>';
echo '<button class="icon icon-delete" data-property-id="' . intval($property_data->ID) . '" data-attachment-id="' . intval($prop_image_id) . '"><span class="btn-loader houzez-loader-js"></span><i class="houzez-icon icon-remove-circle"></i></button>';
echo '</div>';
echo '<input type="hidden" class="propperty-image-id" name="propperty_image_ids[]" value="' . intval($prop_image_id) . '"/>';
if ($is_featured_image) {
echo '<input type="hidden" class="featured_image_id" name="featured_image_id" value="' . intval($prop_image_id) . '">';
}
echo '</div>';
}
}
}
}
?>
Use PHP GD Library. You can open saved image file, write text or overlay watermark image and save image again.

while looping w3-quarter in w3-row-padding

Here is the problem that while looping the php in while loop in w3-row-padding of w3 responsive layout . The layout breaks
Here is the source code
<?php
$r=0;
while($r<ceil($fetch_row_count/4))
{ ?>
<div class="w3-row-padding w3-padding-16 w3-center" style="clear:both" id="food">
<?php
while($row=mysqli_fetch_array($res))
{
?>
<div class="w3-quarter">
<img src="admin/uploads/<?php echo $row['image']; ?>" alt="noodles" style="width:50%">
<h3><?php echo $row['title']; ?></h3>
<p><?php echo $row['description']; ?> </p>
</div>
<?php
}
$r++;
}
?>
</div>
Thanks for reply and comments in advance
That bottom div was not being added for each of your padded containers.
The way the code is written you are adding a padded container and then adding your w3-quarter div for each of your result sets and then repeating that a bunch of times with what looks like to me the same set of data in each one.
What you are probably trying to accomplish is just making one padded div and then echo out your result set with the w3-quarter divs inside of it.
Here is your original way with the bottom div corrected:
<?php
$r=0;
while($r<ceil($fetch_row_count/4)) {
echo
'<div class="w3-row-padding w3-padding-16 w3-center" style="clear:both" id="food">';
while($row=mysqli_fetch_array($res)){
echo
'<div class="w3-quarter">' .
'<img src="admin/uploads/' . $row['image'] . '" alt="noodles" style="width:50%">' .
'<h3>' . $row['title'] . '</h3>' .
'<p>' . $row['description'] . '</p>' .
'</div>';
}
$r++;
echo
'</div>';
}
?>
Here is the way I think you are trying to do it: (Just guessing)
<?php
echo
'<div class="w3-row-padding w3-padding-16 w3-center" style="clear:both" id="food">';
$r = 0;
while($row=mysqli_fetch_array($res)){
echo
'<div class="w3-quarter">' .
'<img src="admin/uploads/' . $row['image'] . '" alt="noodles" style="width:50%">' .
'<h3>' . $row['title'] . '</h3>' .
'<p>' . $row['description'] . '</p>' .
'</div>';
$r++;
//I would not actually try to control how many results you add like this.
//I would get the results from a better formatted query.
if($r < ceil($fetch_row_count/4)){
break;
}
}
echo
'</div>';
?>

Cant display a list of all categories under a post_type

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.

Wordpress post visualization on homepage

i am not able to display the custom fields in a wordpress home page.
This is the code (fully working except for the part that show the custom field)
<?php
$thumbnails = get_posts('numberposts=3&cat=3');
foreach ($thumbnails as $thumbnail) {
if ( has_post_thumbnail($thumbnail->ID)) {
echo '<div class="contest-home"><a href="' . get_permalink( $thumbnail->ID ) . '" title="' . esc_attr( $thumbnail->post_title ) . '">';
echo get_the_post_thumbnail($thumbnail->ID, 'medium', array('class'=> "blur") );
echo '</a>';
echo '<h2><center>' . esc_attr( $thumbnail->post_title ) . '</center></h2>';
echo get_post_meta($post->ID, "RiassuntoHome", true);
echo '<p><b>Giorni restanti:</b> 30 giorni';
echo '<br><b>Premio:</b> 10.000 euro';
echo '</p><center><a class="st-btn slarge st-btn-green st-btn-slarge" href="' . get_permalink( $thumbnail->ID ) . '">Invia la Tua Idea</a></center></div>';
}
}
?>
<?php echo '<div class="clearfix"></div></div>' ?>
The object is $thumbnail, not $post:
echo get_post_meta($thumbnail->ID, "RiassuntoHome", true);

Categories