Gallery with photos from a specific directory [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm trying to make a photo gallery on a website, I want it to display every photo from a certain directory. I figured a PHP loop work for this (don't really like Javascript). Is there a way I can show every picture from a directory inside my HTML code using PHP?

Try This code it worked for me
<?php
$imgdir = 'source/'; //Pick your folder
$allowed_types = array('png','jpg','jpeg','gif'); //Allowed types of files
$dimg = opendir($imgdir);//Open directory
while($imgfile = readdir($dimg))
{
if( in_array(strtolower(substr($imgfile,-3)),$allowed_types) OR
in_array(strtolower(substr($imgfile,-4)),$allowed_types) )
/*If the file is an image add it to the array*/
{$a_img[] = $imgfile;}
}
echo "<ul>";
$totimg = count($a_img); //The total count of all the images
//Echo out the images and their paths incased in an li.
for($x=0; $x < $totimg; $x++){echo "<li><img src='" . $imgdir . $a_img[$x] . "' /></li>";}
echo "</ul>";
?>

Related

Like selected file name in PHP [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have a file image with the name :
35210001.jpg
And I want to move the file to another folder.
What is the solution to handle the "LIKE" in PHP like Query in MySQL because the filename indicator obtained from the request to move is only :
3521
This is mycode :
$name = "35210001.jpg";
$date = date("YmdHis");
File::move('C:/xampp/htdocs/test/test_media/' . $name, public_path('test_move' . $date . '.jpg')); public_path('test_move' . $date . '.jpg'));
What you are looking for is the glob function, here is the doc
Exemple from doc :
foreach (glob("*.txt") as $filename) {
echo "$filename occupe " . filesize($filename) . "\n";
}

How can I limit the attached images shown to just one? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Given I'm using the following code:
$images = get_attached_media('image' ); // get attached media
foreach ($images as $image) {
$ximage = wp_get_attachment_image_src($image->ID,'medium');
echo '<img src="' .$ximage[0] . '" />';
}
How can I limit it to just show the first attached image only, rather than all of them?
If you only want to show first image from array, remove the foreach loop and do this:
$images = get_attached_media('image' );
// get first element from array
$image = reset($images );
$ximage = wp_get_attachment_image_src($image->ID,'medium');
echo '<img src="' .$ximage[0] . '" />';

Trying to make this entire line of code into a hyperlink [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
echo <a href = 'test.php'> "CategoryID: " . $row["CategoryID"]. " - Category Name: ".$row["CategoryName"]. </a> "<br>";
This is what i have an is not working properly.
This:
echo "<a href = 'test.php'>CategoryID: {$row['CategoryID']} - Category Name: {$row['CategoryName']}</a><br />";
I am using the { and } as they allow you to include an array in a string and ignore the concatenation which I find harder to read.
I find it funny that you can loop through a MySQL array but can't echo a simple string :P
Some links (teach a man to fish...):
W3Schools
PHP documentation
Codecademy
Tutorials Point
Try this:
<?php
$link = "";
$link = sprintf("<a href = 'test.php'>CategoryID: %d - Category Name: %s </a><br />", $row['CategoryID'], $row['CategoryName']);
echo $link;
?>
Assuming that $row['CategoryID'] is an integer and $row['CategoryName'] is a string.

How will make variable to do_shortcode value? i want to change shortcode value like (category="others") how it possible? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to make variables of these red block parts
(screenshot).
PHP code:
echo do_shortcode('[product_category category="others" per_page="12" columns="4"]');
You can directly insert variable values in a "" delimited string in PHP.
$cat = "some_category";
$per = 20; // some number
$col = 10; // some number
echo do_shortcode("[product_category category=\"$cat\" per_page=\"$per\" columns=\"$col\"]");
If you still want to use a '' delimited string, you need to append values together.
echo do_shortcode('[product_category category="' . $cat . '" per_page="' . $per . '" columns="' . $col . '"]');

joomla 2.5 navigation menu subtitle [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Hi I am web designer and I would like to know how to set menu subtitle? It is easily possible with yoo themes but I need to know how it is done without using YooTheme templates. I think there is need of little modification in mod_menu but I don't know what exactly. I googled all day and can't find a solution.
There are certainly better solutions but i've done it this way:
Insert a charakter in the name of your menu-item. For example a "|".
It should look like this: Title | Subtitle. At this position you can divide the name.
Now you have to override the file default_component.php in modules/mod_menu/tmpl.
Add this lines:
$parts = explode("|", $linktype);
// the "|" is the divider
if(isset($parts[1])){
$linktype = $parts[0].'<span>'.$parts[1].'</span>';
}else{
$linktype = $parts[0];
};
after:
$class = $item->anchor_css ? 'class="'.$item->anchor_css.'" ' : '';
$title = $item->anchor_title ? 'title="'.$item->anchor_title.'" ' : '';
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;
}
Now you have a span around the subtitle and it's possible to style it.

Categories