{"id":437,"date":"2006-06-03T13:19:52","date_gmt":"2006-06-03T18:19:52","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=437"},"modified":"2011-04-10T05:45:17","modified_gmt":"2011-04-10T10:45:17","slug":"random-quotes-in-wordpress","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=437","title":{"rendered":"Random quotes in wordpress"},"content":{"rendered":"<p>For <a href=\"http:\/\/www.houblog.com\/\">ubu roi<\/a> and anyone else who is interested in a few of the tricks used on this site, here are a few bits of code that might help you out.  Sadly, you can&#8217;t really do this stuff as plugins, which means you have to edit the code yourself.  This will either be very easy or a little confusing, depending on how comfortable you are with PHP.  Also, this code is only going to be useful if you&#8217;re using wordpress.  <\/p>\n<p>First, the random quote.  Create a quotes file named &#8220;quotes.txt&#8221; and put it in the \/wp-content filder.  The file should have three lines for every quote:  The first is the quote itself, the second is the person being quoted (leave blank if you dan&#8217;t want this) and the third is a required blank line.  Mine looks like <a href=\"http:\/\/www.shamusyoung.com\/lexicon\/wp-content\/quotes.txt\">this<\/a>.  Now, somewhere in the PHP code for your site (I suggest at the top of the header.php) place this code:<\/p>\n<pre><tt><b>\r\n&lt;?php \r\n\/*----------------------------------------------------------------------------- \r\nPull out a random quote from the quote file and display it. \r\n-----------------------------------------------------------------------------*\/ \r\nfunction random_phrase () \r\n{ \r\n$quotes = file (\"wp-content\/quotes.txt\");\r\n$num = rand (0, intval (count ($quotes) \/ 3)) * 3;\r\necho $quotes[$num] . \"&lt;br&gt;\" . $quotes[$num + 1];\r\n}\r\n?&gt;\r\n<\/b><\/tt><\/pre>\n<p>Almost done.  Now just put this little bit of code where you want the quote to appear:<\/p>\n<p><code><b>&lt;?php random_phrase (); ?&gt;<\/b><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For ubu roi and anyone else who is interested in a few of the tricks used on this site, here are a few bits of code that might help you out. Sadly, you can&#8217;t really do this stuff as plugins, which means you have to edit the code yourself. This will either be very easy [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66],"tags":[],"class_list":["post-437","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/437","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=437"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/437\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}