- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试做的是从转发器字段中获取图像,并在我的主页上填充导致发布的图像。
这对我来说通常很容易,但这里要注意的是,转发器字段中的每个帖子都有多个图像,这些图像位于高级自定义字段插件的灵活内容字段中。
目标是在主页上以完全随机的顺序从“square_image”字段中获取无限数量的图像,这些图像会指向他们的特定帖子。因此,如果有 15 个帖子,每个帖子有 15 个“square_images”,那么主页上将有 225 张图片以完全随机的位置链接到各自的帖子。
我想知道我是否需要在 while 循环中构建一个数组,以便我可以在最后获得最终的随机顺序,而不是仅以随机顺序从帖子 1 的前 15 张图像,然后是接下来的 15 张图像从帖子 2 开始以随机顺序开始,这不是我想要做的。
<?php get_header(); /* Template Name: Homepage Looper */ ?>
<div id="homepage">
<?php
// the query
$args = array(
'post_type' => 'projects',
'posts_per_page' => '-1',
'orderby' => 'rand',
);
$the_query = new WP_Query( $args );$count = 1; ?>
<?php if ( $the_query->have_posts() ) : ?>
<div class="row">
<!-- the loop -->
<?php
while ( $the_query->have_posts() ) : $the_query->the_post();
if( have_rows('the_page_content') ):
while ( have_rows('the_page_content') ) : the_row();
if(get_sub_field('images')) :
while(has_sub_field('images')) : the_row();
?>
<?php
$image = get_sub_field('square_image');
if ( !empty($image) ):
// vars
$url = $image['url'];
$title = $image['title'];
$alt = $image['alt'];
?>
<div class="col-xs-6 col-sm-4 col-md-3 col-lg-2 home-tile-holder">
<a href="<?php the_permalink(); ?>" rel="<?php the_title(); ?>">
<img src="<?php echo $url; ?>" alt="<?php echo $alt; ?>" class="img-responsive home-tile" />
<span class="title"><?php the_title(); ?><br><img src="<?php echo get_stylesheet_directory_uri(); ?>/img/magnify.png"></span>
</a>
</div>
<?php endif; ?>
<?php
if($count % 6 == 0) {echo '</div><div class="row">';}
$count++;
?>
<?php
endwhile; // while(has_sub_field('images')
endif; // get_sub_field('images')
endwhile; // have_rows('the_page_content')
endif; // have_rows('the_page_content')
endwhile; // $the_query->have_posts ?>
<!-- end of the loop -->
</div>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; // $the_query->have_posts ?>
</div>
<div id="single_project" style="position: absolute; margin-left:100%; width:100%;">
</div>
<?php get_footer(); ?>
ACF 导出低于
if(function_exists("register_field_group"))
{
register_field_group(array (
'id' => 'acf_project-fields',
'title' => 'Project Fields',
'fields' => array (
array (
'key' => 'field_534efd890cd30',
'label' => 'Hero Image',
'name' => 'hero_image',
'type' => 'image',
'instructions' => 'Upload the large version for this post that will be used as the hero image on the top of the page.',
'save_format' => 'url',
'preview_size' => 'thumbnail',
'library' => 'all',
),
array (
'key' => 'field_534efdb70cd31',
'label' => 'Page Content',
'name' => 'the_page_content',
'type' => 'flexible_content',
'instructions' => 'Build out the content for this project.',
'layouts' => array (
array (
'label' => 'Image Row',
'name' => 'image_row',
'display' => 'row',
'min' => '',
'max' => '',
'sub_fields' => array (
array (
'key' => 'field_534efdea0cd32',
'label' => 'Images',
'name' => 'images',
'type' => 'repeater',
'column_width' => '',
'sub_fields' => array (
array (
'key' => 'field_53716523cfc52',
'label' => 'Square Image',
'name' => 'square_image',
'type' => 'image',
'column_width' => '',
'save_format' => 'object',
'preview_size' => 'thumbnail',
'library' => 'all',
),
array (
'key' => 'field_53716532cfc53',
'label' => 'Full Size Image',
'name' => 'full_size_image',
'type' => 'image',
'column_width' => '',
'save_format' => 'object',
'preview_size' => 'thumbnail',
'library' => 'all',
),
),
'row_min' => 1,
'row_limit' => 6,
'layout' => 'table',
'button_label' => 'Add Image Set',
),
),
),
array (
'label' => 'Text + Images',
'name' => 'text_images',
'display' => 'row',
'min' => '',
'max' => '',
'sub_fields' => array (
array (
'key' => 'field_5356d3a6a8ac9',
'label' => 'Title',
'name' => 'title',
'type' => 'text',
'instructions' => 'Enter in the title of this project if you wish for it to show above the text.',
'column_width' => '',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_534eff4ae5d31',
'label' => 'Text Content',
'name' => 'text_content',
'type' => 'wysiwyg',
'column_width' => '',
'default_value' => '',
'toolbar' => 'full',
'media_upload' => 'yes',
),
array (
'key' => 'field_534eff32e5d30',
'label' => 'Images',
'name' => 'images',
'type' => 'repeater',
'column_width' => '',
'sub_fields' => array (
array (
'key' => 'field_53716549cfc54',
'label' => 'Square Image',
'name' => 'square_image',
'type' => 'image',
'column_width' => '',
'save_format' => 'object',
'preview_size' => 'thumbnail',
'library' => 'all',
),
array (
'key' => 'field_53716557cfc55',
'label' => 'Full Size Image',
'name' => 'full_size_image',
'type' => 'image',
'column_width' => '',
'save_format' => 'object',
'preview_size' => 'thumbnail',
'library' => 'all',
),
),
'row_min' => '',
'row_limit' => 3,
'layout' => 'table',
'button_label' => 'Add Image Set',
),
),
),
array (
'label' => 'Images + Text',
'name' => 'images_text',
'display' => 'row',
'min' => '',
'max' => '',
'sub_fields' => array (
array (
'key' => 'field_534effafb045d',
'label' => 'Images',
'name' => 'images',
'type' => 'repeater',
'column_width' => '',
'sub_fields' => array (
array (
'key' => 'field_53716567cfc56',
'label' => 'Square Image',
'name' => 'square_image',
'type' => 'image',
'column_width' => '',
'save_format' => 'object',
'preview_size' => 'thumbnail',
'library' => 'all',
),
array (
'key' => 'field_53716576cfc57',
'label' => 'Full Size Image',
'name' => 'full_size_image',
'type' => 'image',
'column_width' => '',
'save_format' => 'object',
'preview_size' => 'thumbnail',
'library' => 'all',
),
),
'row_min' => '',
'row_limit' => 3,
'layout' => 'table',
'button_label' => 'Add Image Set',
),
array (
'key' => 'field_5356d3dba8aca',
'label' => 'Title',
'name' => 'title',
'type' => 'text',
'instructions' => 'Enter in the title of this project if you wish for it to show above the text.',
'column_width' => '',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_534effafb045c',
'label' => 'Text Content',
'name' => 'text_content',
'type' => 'textarea',
'column_width' => '',
'default_value' => '',
'placeholder' => '',
'maxlength' => '',
'rows' => '',
'formatting' => 'br',
),
),
),
),
'button_label' => 'Add Row',
'min' => '',
'max' => '',
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'projects',
'order_no' => 0,
'group_no' => 0,
),
),
),
'options' => array (
'position' => 'normal',
'layout' => 'no_box',
'hide_on_screen' => array (
0 => 'the_content',
1 => 'excerpt',
2 => 'custom_fields',
3 => 'discussion',
4 => 'comments',
5 => 'format',
6 => 'featured_image',
7 => 'send-trackbacks',
),
),
'menu_order' => 0,
));
}
最佳答案
在初始帖子循环中创建一个图像数组,随机化该数组,然后通过图像数组循环输出 html。
<?php
$args = array(
'post_type' => 'projects',
'posts_per_page' => '-1',
'orderby' => 'rand',
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
$images = array();
while ( $the_query->have_posts() ) : $the_query->the_post();
if( have_rows('the_page_content') ):
while ( have_rows('the_page_content') ) : the_row();
if( have_rows('images') ) :
while( have_rows('images') ) : the_row();
$image = get_sub_field('square_image');
if ( !empty($image) ):
// add image properties and related data to main images array
$images[] = array(
'url' => $image['url'],
'title' => $image['title'],
'alt' => $image['alt'],
'postdata' => array(
'id' => get_the_ID(),
'title' => get_the_title(),
'permalink' => get_permalink()
)
);
endif;
endwhile; // while(have_rows('images'))
endif; // have_rows('images')
endwhile; // have_rows('the_page_content')
endif; // have_rows('the_page_content')
endwhile; // $the_query->have_posts
wp_reset_postdata();
endif; // $the_query->have_posts
// Loop through the images array and output html for each image
shuffle($images); // Randomize the order of the images
$count = 1;
foreach($images as $img) :
?>
<div class="row">
<div class="col-xs-6 col-sm-4 col-md-3 col-lg-2 home-tile-holder">
<a href="<?php echo $img['postdata']['permalink']; ?>" rel="<?php echo $img['postdata']['title']; ?>">
<img src="<?php echo $img['url']; ?>" alt="<?php echo $img['alt']; ?>" class="img-responsive home-tile" />
<span class="title"><?php $img['postdata']['title']; ?><br><img src="<?php echo get_stylesheet_directory_uri(); ?>/img/magnify.png"></span>
</a>
</div>
<?php if($count % 6 == 0) echo '</div><div class="row">';?>
<?php $count++; ?>
<?php endforeach; ?>
</div>
关于php - ACF - 通过帖子循环,然后通过灵活的内容,然后通过转发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23898728/
我正在为我的按钮使用 onClick 功能。我的按钮代码如下所示: Button 1 Button 2 我的 JS 函数如下所示: function fadeNext(selectedId, spee
首先,我想提一下,我理解每个人在不提供至少一些试验或错误的情况下提出问题的感受,但这纯粹是一种知识需求,话虽如此,我会去提前问。 我一直无法弄清楚如何将保存在 MySQL 表中的 600-1000 个
我想做的事情有点令人困惑,而且我英语不太好,所以我先把代码贴在这里,这样你就可以很容易地理解: 以下是表单内容: Testing for Stackoverflow Option1
我学习 SDL 二维编程已有一段时间了,现在我想创建一个结合使用 SDL 和 OpenGL 的程序。我是这样设置的: SDL_Init(SDL_INIT_VIDEO); window = SDL_Cr
我创建了 2 个 data-* 标签。数据类别和数据标签。单击 href 标签后,我想复制该数据类别和数据标签以形成输入。我的代码是:
我想用 CSS 换行。我正在使用内容。 td:before { content: "Test\A Test2"; } 它不工作。如何正确
这个问题已经有答案了: Java Class that implements Map and keeps insertion order? (8 个回答) 已关闭 6 年前。 我有一个 HashMap
我正在尝试使用 JMeter 执行端到端测试。测试涉及写入SFTP文件夹并从另一个SFTP文件夹读取写入操作生成的文件。 我能够使用 JMeter SSH SFTP 插件连接到 SFTP 文件夹,并能
您好,我有带有标准服务器端 Servlet 的 GWT 客户端。 我可以从 GWT 客户端上传文件并在服务器端读取其内容 我可以将其作为字符串发送回客户端 但是 我有 GWT FormPanel与操作
我在 Plone 4.3.9 中创建了一个自定义类型的灵巧性,称为 PersonalPage,必须只允许在特定文件夹中使用 成员文件夹/用户文件夹 . 在他的 FTI 中,默认情况下 False .
在新(更新)版本的应用程序中更改小部件布局的最佳做法是什么?当新版本提供更新、更好的小部件时,如何处理现有小部件? 最佳答案 我认为您必须向用户显示一个弹出窗口,说明“此版本中的新功能”并要求他们重新
在我的应用程序中,我使用支持 View 寻呼机和 PagerTabStrip。进入查看寻呼机我有一些 fragment ,进入其中一个我正在使用支持卡片 View 。运行应用程序后,所有卡片 View
我有以下布局文件。基本上我有谷歌地图,在左上角我有一个 TextView,我需要在其中每 15 秒保持一次计数器以刷新 map 。布局很好。
我使用如下结构: HashMap > > OverallMap 如果我这样做: OverallMap . clear ( ) clear() 丢弃的所有内容(HashMap 对象、Integer 对
我在数据库中有 1000 张图像。在页面加载时,我随机显示 60 张图片,当用户滚动时,我通过 AJAX 请求添加 20 张图片。 第一种方法 我所做的是将所有图像加载到一个容器中,然后隐藏所有图像并
我正在使用 woocommerce 创建一个网上商店。 我想在每个产品上添加一个包含产品信息的表格,例如颜色、交货时间等等。 但是当我添加这张表时。本产品消失后的所有内容。 我的表的代码: td {
This question already has an answer here: What does an empty value for the CSS property content do?
因此,我正在与我的 friend 一起为 Google Chrome 开发一个扩展程序,对于大多数功能(即日历、设置等),我们打开一个模式,这样我们就不必重定向到另一个页面。当您在内容之外单击时,我们
我将可变高度的 CSS 框设置为在更大的 div 中向左浮动。现在我想添加一个标题,其中文本在框的左侧垂直显示(旋转 90 度),如下面的链接所示(抱歉还不能发布图片)。 http://imagesh
相关页面位于 www.codykrauskopf.com/circus 如果您查看我页面的右侧,在半透明容器和浏览器窗口边缘之间有一个间隙。我看了看,出于某种原因,wrap、main、content
我是一名优秀的程序员,十分优秀!