0
<?php
$rows = get_field('quote');
//$rows now contains all the quotes that have been added.
$rand_row = $rows[ array_rand($rows) ];
//Puts all the rows from $rows in an array and randomly selects a single row.
$rand_row_quote = $rand_row['quote'];
$rand_row_auteur = $rand_row['naam_auteur'];
//Gets the values from the subfields.
$quote = get_field($rand_row_auteur, $rand_row_quote);
//Puts the values in a single variable.
echo $quote;
//Echo's the values of each row.
?>
위의 코드를 Wordpress의 ACF (Advanced Custom Fields)에 추가했습니다. 나는 각각 quote와 naam_auteur
(영어로 작성자 이름)이라고 불리는 몇 개의 하위 필드를 만들었습니다. 이들은 quote
이라는 필드에 들어 있습니다.Wordpress randomize quote 함수가 출력을 표시하지 않습니다.
위의 PHP 코드를 입력하여 작성자와 내 임의 인용문을 표시하지만 비어 있습니다.
의견이나 제안이 있으십니까? 내 문제를 해결
아래 코드는 여기에 있습니다 :
는<?php
$rows = get_field('quotes');
$row_count = count($rows);
$i = rand(0, $row_count - 1);
?>
<p>Quotes van de fans:</p>
<h2><?php echo $rows[ $i ]['quote']; ?></h2>
<h3><?php echo $rows[ $i ]['naam_auteur']; ?></h3>
내 코드에서 실수를 저질렀 음을 알게 해주셔서 감사드립니다. 내 질문을 편집하여 최종 코드를 추가합니다. 도와 주셔서 감사합니다. –