简体   繁体   中英

WordPress slider code returning no results

I'm new to WordPress and I have the following PHP code on my theme's homepage which I'm struggling to understand. The code makes a query for images to be used on a slider however the query is returning no results even though I've tried adding images wherever I could in the backend including creating posts with featured images but still nothing is showing up.

<div class="swiper-wrapper">

    <?php $ij=0;
        $slider = array('post_type'=>'slide','order'=>'ASC');
        $slider_query = new wp_query($slider);
        while($slider_query->have_posts()): $slider_query->the_post();
            $feat_imag1 = wp_get_attachment_url(get_post_thumbnail_id($slider_query->ID));                
    ?>

    <div class="swiper-slide" style="background-image:url(<?php echo $feat_imag1; ?>)"></div>
    <?php $ij++;  endwhile;?>

</div>

My question is what is this block of code related to within the admin panel? I've read that post_type=>'slide' is not standard so is this for some 3rd party slide plugin? If so would you know the name of it?

There is no post type called 'slide' by default. It seems developer created it for slider. You can read more about creating custom post types here

The above said code in your theme's home page means if there are slide(s) with images( featured image or attachments) , they will be populated with wp_query Take a look at how wp_query works from here

Assuming that your project is in development stage you can try view/add/edit the slides in these path

To view slides:

localhost/project-name/wp-admin/edit.php?post_type=slide

To add slide

localhost/project-name/wp-admin/post-new.php?post_type=slide

In short the other developer created a custom post type called slide and listed them using wp_query for showing slider. If there is no slides/images there will be no output for that given code.

So try adding some slides and look for slider in home page.

Look for 'slide' in your theme functions.php file.

If you are unable to find the slider after these steps, please share us screenshot of your active plugins list.

Happy coding!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM