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] . '" />';
Related
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";
}
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>";
?>
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 . '"]');
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 7 years ago.
Improve this question
I am trying to add a <div> to my php, but everything I've found on google hasn't worked for me. I don't know what I'm doing wrong. Any ideas on how to add a <div> in a php function for styling purposes only?
<?php
//get_additional is a custom function
ob_start();
echo get_additional('Cosmos','Trades');
echo nl2br("\n");
//I want the div to start here
$buffered = ob_get_clean();
echo $buffered;
$times = $buffered;
$imgurl = 'Images/cat.png';
for($i=0;$i<$times;$i++){
echo '<img src="'.$imgurl.'" />';
}
?>
You need to echo it.
Like you've already used once in your code, echo '<img src="'.$imgurl.'" />';
Now coming back to your code:
<?php
//get_additional is a custom function
ob_start();
echo get_additional('Cosmos','Trades');
echo nl2br("\n");
//I want the div to start here
echo '<div class = "blah">
// whatever you want to do here
</div>';
$buffered = ob_get_clean();
echo $buffered;
$imgurl = 'Images/cat.png';
for($i=0;$i<$times;$i++){
echo '<img src="'.$imgurl.'" />';
}
?>
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.