Hi, the images are being retrived using get_children() function which unfortunately does not allow to sort returned data.
If you really need this, then the only option i can think of is to open file wpadverts/templates/single.php and on line about 11 sort the $images variable.
Greg Winiarski, I can’t find $images variable in wpadverts/templates/single.php Is it still in this file?
I need this:
1. use by default the first uploaded image as the main image of an ad.
2. arrange images in ad by default in order that they were uploaded.
Can I ask you to create snippet with this features? I can pay for it.
No, it is now executed using adverts_single_rslides() the function is in wpadverts/includes/functions.php file.
You can replace it with your own using following code in your theme functions.php
add_action( "init", "replace_gallery_init", 1000 );
function replace_gallery_init() {
remove_action( "adverts_tpl_single_top", "adverts_single_rslides" );
add_action( "adverts_tpl_single_top", "replace_gallery_with_lightbox" );
}
function replace_gallery_with_lightbox( $post_id ) {
$images = get_children(array('post_parent'=>$post_id));
wp_enqueue_script( 'responsive-slides' );
if( empty( $images ) ) {
return;
}
?>
<div class="rslides_container">
<ul id="slides1" class="rslides rslides1">
<?php foreach($images as $tmp_post): ?>
<?php $image = wp_get_attachment_image_src( $tmp_post->ID, 'large' ) ?>
<?php if(isset($image[0])): ?>
<li>
<img src="<?php esc_attr_e($image[0]) ?>" alt="">
<?php if($tmp_post->post_excerpt || $tmp_post->post_content): ?>
<p class="caption">
<strong><?php esc_html_e($tmp_post->post_excerpt) ?></strong>
<?php esc_html_e($tmp_post->post_content) ?>
</p>
<?php endif; ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
<?php
}
In this code you can modify $images variable to display images the way you would like it to, but like i wrote in previous comment, right now it does not seem to be possible to sort using get_children() function.
Greg, thanks! What this code changes?
Greg, I found the solution.
Inside of <?php foreach($images as $tmp_post): ?>
I use new array $nimages = array();
and save image urls there. Then I reverse them by $reversed = array_reverse($nimages);
and echo them foreach ($reversed as $value) {echo "<li><img src='".$value."' alt=''></li>";}
I’m not a programmer so don’t publish the whole my code, I think you can do this better if you want. I just give an idea.
As for thumbnails “function adverts_get_main_image( $id )” I just change this line:
foreach(get_children(array('post_parent'=>$id, 'numberposts'=>1)) as $tmp_post) {
to this:
foreach(get_children(array('post_parent'=>$id)) as $tmp_post) {
and now the first uploaded image is showing as a thumbnail.