简体   繁体   English

数组只显示页面上的第一项

[英]Array is only showing first item on page

I inherited a WordPress website with some Laravel code where a modal is supposed to show on multiple pages, but is only showing on the first page.我继承了一个 WordPress 网站,其中包含一些 Laravel 代码,其中模式应该显示在多个页面上,但只显示在第一页上。 Looking at the code below, It's obvious why it's only shows on the first page since the ID is 0:查看下面的代码,很明显为什么它只显示在第一页,因为 ID 为 0:

<?php 
$display_ids = get_field('display_ids', 'options');
$id =  get_the_ID(); 
?>

@if ($display_ids != null)
  @if (get_field('toggle_sm', 'options') && $display_ids[0]->ID == $id)
    @include('specials-modal')
  @endif
@endif

I'm trying to figure out how to select an entire range of id's(pages) so it shows on multiple pages.我试图弄清楚如何 select 整个范围的 id(页面),以便它显示在多个页面上。 There are about 30 in all.总共大约有30个。 Would using range help?使用范围有帮助吗?

I also tried this, but didn't work at all:我也试过这个,但根本没有用:

<?php 
$display_ids = get_field('display_ids', 'options');
$id =  get_the_ID(); 
?>

@if (get_field('toggle_sm', 'options') && in_array($id, $display_ids) == "true")
@include('specials-modal')
@endif

The problem was in this code - $id = get_the_ID().问题出在这段代码中 - $id = get_the_ID()。

It's supposed to be $id = get_post().它应该是 $id = get_post()。 I figured this out by doing a print_r and checking out what was really showing up for the page ID, which is found out by using get_post().我通过执行 print_r 并检查页面 ID 真正显示的内容来解决这个问题,这是通过使用 get_post() 发现的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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