【发布时间】:2016-12-20 04:30:53
【问题描述】:
我在 WordPress 网站上使用高级自定义字段插件。我有一个转发器字段,每页显示 25 个以上的引号。每个页面都有独特的报价。
我目前必须从 25 个池中提取一个随机引用的代码就像我登录时所假设的那样工作。当我注销时,它会提取一个随机引用,但不会将其切换为不同的页面刷新就像我登录时一样。
我正在使用这里的随机行代码: https://gist.github.com/wesrice/1924934
<?php
if (is_singular('post')) {
$repeater2 = get_field( 'quote_info', 11 );
$random_rows2 = array_rand( $repeater2, 1 );
if( is_array( $random_rows2 ) ){
foreach( $random_rows2 as $random_row2 ){
echo '<div class="newquote">
<div class="newinnerwrapperquote">"' . $repeater2[$random_row2]['bottom_quote_text'] . '"</div>';
echo '<div class="newquoteby">' . $repeater2[$random_row2]['bottom_quote_author'] . '</div></div>';
}
} else {
echo '<div class="newquote">
<div class="newinnerwrapperquote">"' . $repeater2[$random_rows2]['bottom_quote_text'] . '"</div>';
echo '<div class="newquoteby">' . $repeater2[$random_rows2]['bottom_quote_author'] . '</div></div>';
} wp_reset_query();
} else {
$repeater = get_field( 'quote_info' );
$random_rows = array_rand( $repeater, 1 );
if( is_array( $random_rows ) ){
foreach( $random_rows as $random_row ){
echo '<div class="newquote">
<div class="newinnerwrapperquote">"' . $repeater[$random_row]['bottom_quote_text'] . '"</div>';
echo '<div class="newquoteby">' . $repeater[$random_row]['bottom_quote_author'] . '</div></div>';
}
} else {
echo '<div class="newquote">
<div class="newinnerwrapperquote">"' . $repeater[$random_rows]['bottom_quote_text'] . '"</div>';
echo '<div class="newquoteby">' . $repeater[$random_rows]['bottom_quote_author'] . '</div></div>';
}
}
?>
第一个 if 语句是它是否在 WordPress 帖子而不是页面上。我希望我解释得很好。
【问题讨论】:
-
随机猜测..缓存
标签: php wordpress advanced-custom-fields