最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Why is my custom post type slider only displaying the latest slide?

programmeradmin4浏览0评论

after a search throughout the already asked questions I couldn't come to a solution to my problem, this one is the closest I found: My custom post type displays the [latest post]

I had a slider built into the homepage, but I have noticed that after a while of it working fine, it now only displays the latest post type.

Here is the current code for the slider:

<div class="half slide-container">
            <ul class="slider">
                <?php
                    $slides = get_posts( array(
                        'numberposts' => 6,
                        'post_type' => 'slides',
                        'orderby' => 'post_date'
                    ) );
                    foreach( $slides as $post ) :
                        setup_postdata( $post );
                        $args = array(
                            'post_type' => 'attachment',
                            'numberposts' => null,
                            'post_status' => null,
                            'orderby' => 'post_date',
                            'order' => 'ASC',
                            'post_parent' => $post->ID
                        ); 
                    $attachments = get_posts( $args );
                ?>
                    <li data-background=".png">
                        <?php the_content(  ); ?>
                    </li>
                <?php endforeach; ?>
            </ul>
        </div>

I'm relatively new to .php, but I thought I had spotted a couple of syntax errors but the slider still remained broken.

I changed it to this to no avail:

<div class="half slide-container">
            <ul class="slider">
                <?php
                    $slides = get_posts( array(
                        'numberposts' => '3',
                        'post_type' => 'slides',
                        'orderby' => 'post_date'
                    ) );
                    foreach( $slides as $post ) :
                        setup_postdata( $post );
                        $args = array(
                            'post_type' => 'attachment',
                            'numberposts' => '3',
                            'post_status' => 'publish',
                            'orderby' => 'post_date',
                            'order' => 'ASC',
                            'post_parent' => $post->ID
                        ); 
                    $attachments = get_posts( $args );
                ?>
                    <li data-background=".png">
                        <?php the_content(  ); ?>
                    </li>
                <?php endforeach; ?>
            </ul>
        </div>

You can view this live on the website here: Polesworth Garage

after a search throughout the already asked questions I couldn't come to a solution to my problem, this one is the closest I found: My custom post type displays the [latest post]

I had a slider built into the homepage, but I have noticed that after a while of it working fine, it now only displays the latest post type.

Here is the current code for the slider:

<div class="half slide-container">
            <ul class="slider">
                <?php
                    $slides = get_posts( array(
                        'numberposts' => 6,
                        'post_type' => 'slides',
                        'orderby' => 'post_date'
                    ) );
                    foreach( $slides as $post ) :
                        setup_postdata( $post );
                        $args = array(
                            'post_type' => 'attachment',
                            'numberposts' => null,
                            'post_status' => null,
                            'orderby' => 'post_date',
                            'order' => 'ASC',
                            'post_parent' => $post->ID
                        ); 
                    $attachments = get_posts( $args );
                ?>
                    <li data-background="http://www.serps.co.uk/cdn/PG/background14.png">
                        <?php the_content(  ); ?>
                    </li>
                <?php endforeach; ?>
            </ul>
        </div>

I'm relatively new to .php, but I thought I had spotted a couple of syntax errors but the slider still remained broken.

I changed it to this to no avail:

<div class="half slide-container">
            <ul class="slider">
                <?php
                    $slides = get_posts( array(
                        'numberposts' => '3',
                        'post_type' => 'slides',
                        'orderby' => 'post_date'
                    ) );
                    foreach( $slides as $post ) :
                        setup_postdata( $post );
                        $args = array(
                            'post_type' => 'attachment',
                            'numberposts' => '3',
                            'post_status' => 'publish',
                            'orderby' => 'post_date',
                            'order' => 'ASC',
                            'post_parent' => $post->ID
                        ); 
                    $attachments = get_posts( $args );
                ?>
                    <li data-background="http://www.serps.co.uk/cdn/PG/background14.png">
                        <?php the_content(  ); ?>
                    </li>
                <?php endforeach; ?>
            </ul>
        </div>

You can view this live on the website here: Polesworth Garage

Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Oct 12, 2015 at 15:55 SamDemedaSamDemeda 11 bronze badge 2
  • Also - could someone point me to support / forum rules please? – SamDemeda Commented Oct 12, 2015 at 16:02
  • Check out help center for all rules, help and basic info, also, take the tour ;-) – Pieter Goosen Commented Oct 12, 2015 at 17:09
Add a comment  | 

1 Answer 1

Reset to default 0

Your slider looks fine. It just doesn't work because the JavaScript on the page is broken elsewhere - namely on your search facility:

Timestamp: 2015-10-12, 10:51:50 AM
Error: TypeError: tree[x] is undefined
Source File: http://www.polesworth-garage/
Line: 1200
发布评论

评论列表(0)

  1. 暂无评论