在Wordpress动态侧边栏中:第三个循环后的任何循环都不起作用

时间:2016-02-27 20:07:50

标签: php wordpress loops foreach sidebar

我有自定义帖子类型(single-result.php)和相关的自定义侧边栏(sidebar-results.php)。在侧边栏中,我有四个使用高级自定义字段的循环:

  1. 指向"分割"的链接,用于抓取已粘贴到ACF文本字段的网址(它是外部链接)
  2. 指向"路线"的链接,与#1
  3. 相同
  4. 指向相关结果页面的链接,该页面使用ACF的关系字段抓取链接
  5. 指向相关系列结果页的链接,与#3
  6. 相同

    真正奇怪的是,前三个项目将始终返回其链接,但第四个项目将失败并显示"否则"文本。即使我混淆了所有项目的顺序,它总是第四个。如果我添加第五项,则第四项和第五项不起作用。太奇怪了!

    有什么想法吗?

    这是侧边栏代码:

    
    
    <div class="col-lg-3 col-md-3 col-sm-3 hidden-xs sidebar md-mrg-top"> <!-- begin sidebar RIGHT -->
        <div class="sidebar-widgets">
    	  	<?php if ( ! dynamic_sidebar( 'results' ) ): ?>
    
    
    	  	
    	    <div class="text-center">
    	    	<!-- WinSplits link, from ACF text field -->
    	    	<p class="md-mrg-top">
    	    	<?php
    			$key = 'winsplits_link_results';
    			$themeta = get_post_meta($post->ID, $key, TRUE);
    			if($themeta == '') {
    			echo 'Check back soon for splits';
    			}
    			else {
    				echo '<a href="';
    				echo the_field('winsplits_link_results');
    				echo '">WinSplits';
    				echo '</a>';
    			}
    			?>
    			</p>
    
    
    			<!-- RouteGadget link, from ACF text field -->
    			<p>
    			<?php
    			$key = 'routegadget_link_results';
    			$themeta = get_post_meta($post->ID, $key, TRUE);
    			if($themeta == '') {
    			echo 'Check back soon for routes';
    			}
    			else {
    				echo '<a href="';
    				echo the_field('routegadget_link_results');
    				echo '">RouteGadget';
    				echo '</a>';
    			}
    			?>
    			</p>
    
    
    			<!-- Link to related season standings results page, from ACF relationship field -->
    			<p>
                <?php
    
                    $posts = get_field('related_season', $post->ID);
                    
                    if( $posts ) {
    
                        foreach( $posts as $post ):
                            setup_postdata($post);
                            echo '<a href="' . get_the_permalink() . '">';
                            echo get_the_title();
                            echo '</a>';
                        endforeach;
                        wp_reset_postdata();
    
                    } else {
                        echo "No related related_season";
                    }
                ?>
                </p>
                
    			
    
    			<p> <!-- Link to team or individual results page, from ACF relationship field -->
                <?php
    
                    $posts = get_field('team_or_individual', $post->ID);
                    
                    if( $posts ) {
    
                        foreach( $posts as $post ):
                            setup_postdata($post);
                            echo '<a href="' . get_the_permalink() . '">';
                            echo get_the_title();
                            echo '</a>';
                        endforeach;
                        wp_reset_postdata();
    
                    } else {
                        echo "No team/indi link";
                    }
                ?>
                </p>
    
                
    
    
    
    		</div>
    
    
    	    <?php endif; ?> <!-- belongs to dynamic sidebar -->
    	</div>
    </div> <!-- close sidebar right -->
    &#13;
    &#13;
    &#13;

0 个答案:

没有答案