我还没有能够在网上任何地方找到这方面的任何信息,但在我的Wordpress网站上,我的引用是在PHP的几个数组中生成的......
我想请求生成的报价,并将所述报价与我网站的链接一起推文......我对此非常陌生(基本上根本无法编码)我已经开始通过代码学院的PHP课程,但它并没有真正坚持下去,所以任何建议都会非常感激。有人提供我如何做到这一点?
这是我的Wordpress页面-jimmy.php的样子:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
class Jimmy {
public $a = array(
array("The world","The mind","Hidden meaning","Good health",),
array("relies on","depends on","embraces","requires","results from"),
array("your own","infinite","self-righteous","unbridled","unique","innumerable"),
array("responsibility","creativity","life","possibilities","observations")
);
public $life1 = array("Dogs","Cats","Mice","Rats","Lobsters","Crows");
public $life2 = array("the savior","the hero","the man","as mules","as birds","givers in the transcendental","something to watch out for!");
public function getQuote() {
$rn = rand(0, 100);// slight chance of making an animal based quote
if ($rn < 2) {
return $this->life1[array_rand($this->life1)] . " are " . $this->life2[array_rand($this->life2)];
} else {
$oa = array();
if (isset($_SESSION)){// store the variables in the session, reload them if need be
$i = 0;
foreach ($this->a as $ar){
$i++;
$is = "s".strval($i);
if (!isset($_SESSION[$is])){
$_SESSION[$is] = $ar;
} elseif(empty($_SESSION[$is])){
$_SESSION[$is] = $ar;
}
shuffle($_SESSION[$is]);
$oa[] = array_pop($_SESSION[$is]);
}
} else {
foreach ($this->a as $ar) {
$oa[] = $ar[array_rand($ar)];
}
}
return implode(" ", $oa);
}
}
}
get_header();
?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
// Start the loop.
while ( have_posts() ) : the_post();
// Include the page content template.
get_template_part( 'template-parts/content', 'page' );
$blah = new Jimmy();
$var = $blah->getQuote();
echo '<div class="quote anim-typewriter">"'.$var.'"</div>';
// If comments are open or we have at least one comment, load up the
comment template.
if ( comments_open() || get_comments_number() ) {comments_template();}
// End of the loop.
endwhile;
?>
</main><!-- .site-main -->
<?php get_sidebar( 'content-bottom' ); ?>
</div><!-- .content-area -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
</pre>
...谢谢