Hello,

i'm having a little bit of an issue with a portion of code ... It's for a portfolio gallery.

$sliders_out = '<div class="fx"><ul class="slides">';
                    foreach($slides as $slide)
                    {
                        $local =  substr(str_replace(array(get_bloginfo('url'), '.jpg', '.png'), array('.', '', ''), $slide['slide_image']), 2);
                        $locals = array_merge(glob($local.'*1024*'), glob($local.'*768*'), glob($local.'*'));
                        rsort($locals);
                        if (isset($locals[0]))
                            $src = $locals[0];
                        else
                            $src = $locals[2];
                        $sliders_out .= '<li><img src="'.get_bloginfo('url').'/'.$src.'" /></li>';



                    }
                    $sliders_out .= '</ul></div>';

Altough the code works in random cases it outputs in the posts gallery images that are in the same folder as the rest of the pictures (uploaded in the same day as Wordpress puts them) but shouldn't be there

like wp-content/uploads/2014/12/11.jpg instead of wp-content/uploads/2014/12/1.jpg and 2014/12/8256509816_9642cdeaf7_h.jpg which has no corelation.

Any help is appreciated.

Normally, when we deal with wordpress, we don't navigate to the folders ourselves. If you wish for a slider, maybe you should consider the custom post type named 'sliders' by adding these code into functions.php

<?php
    //add "slider" custom post
    add_action( 'init', 'create_slider_post_types' );
    function create_slider_post_types() {
       register_post_type( 'slider',
           array(
               'labels' => array(
               'name' => __( 'slider' ),
               'singular_name' => __( 'slider' ),
               'add_new' => __( 'Add New' ),
               'add_new_item' => __( 'Add new slider' ),
               'edit' => __( 'Edit' ),
               'edit_item' => __( 'Edit slider' ),
               'new_item' => __( 'New slider' ),
               'view' => __( 'View slider' ),
               'view_item' => __( 'View slider' ),
               'search_items' => __( 'Search slider' ),
               'not_found' => __( 'No slider found' ),
               'not_found_in_trash' => __( 'No slider found in Trash' )
               ),
               'public' => true,
               'show_ui' => true,
               'publicly_queryable' => true,
               'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields' ),
               'rewrite' => array("slug" => "slider"),
               'taxonomies' => array('post_tag')
           )
       );
    }
?>

Thus, add the slide images as the thumbnail of the posts in you 'slider'.
Then, when we wish to retrieve the data, just use the

<?php
    query_posts("what_to_show=posts&post_type=testimonial&post_status=publish&order=DESC");
    while(have_posts()):the_post()
?>
<li><?php the_post_thumbnail(); ?></li>

to loop for the posted thumbnails. For the images size customization, you can refer https://codex.wordpress.org/Post_Thumbnails.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.