0

所以这可能是一件非常愚蠢/容易的事情,但我无法解决这个问题。如果没有找到帖子,我想要实现的是在 WP 循环之后显示信息。所以我有这段代码:

 @php
            $args = array (
            'post_type' => 'jobs',
            'order' => 'ASC',
            'posts_per_page' => '-1',
            //'paged' => '1',
            );

            $loop = new WP_Query( $args );


            while ( $loop->have_posts() ) : $loop->the_post(); 
            @endphp


            <div class="col-lg-12" data-postID='{!! get_the_ID() !!}' >
                <div>
                    <a href="{!! the_permalink() !!}">
  
                        <div class="jobButton">
                            {!! the_title() !!}
                            <div class="arrow">
                            </div>
                        </div>
                    
                    </a>               
                </div>
            </div>
            

            @php
            endwhile; 

            wp_reset_postdata(); 
 @endphp 

它有效。但是当我尝试使用类似的东西时:

@noposts <content here> @endnoposts

或者

@if ($loop->have_posts()) <content here> @endif

它使 Wordpress 崩溃.. 怎么做?

4

1 回答 1

0

你试过这样

@php
            $args = array (
            'post_type' => 'jobs',
            'order' => 'ASC',
            'posts_per_page' => '-1',
            //'paged' => '1',
            );

            $loop = new WP_Query( $args );

if($loop->have_posts()):
            while ( $loop->have_posts() ) : $loop->the_post(); 
            @endphp


            <div class="col-lg-12" data-postID='{!! get_the_ID() !!}' >
                <div>
                    <a href="{!! the_permalink() !!}">
  
                        <div class="jobButton">
                            {!! the_title() !!}
                            <div class="arrow">
                            </div>
                        </div>
                    
                    </a>               
                </div>
            </div>
            

            @php
            endwhile; 
else:
  echo "No post found";
  endphp;
            wp_reset_postdata(); 
 @endphp 
于 2020-12-07T15:35:25.060 回答