Randomize gị WordPress akụkọ mfe

aha mkpado

M na-achọ ngwa mgbakwunye ma ọ bụ ụfọdụ koodu ka ịkpọgharịa isi na ebe obibi anyị na DK New Media to have some fun and dress up the home page a bit. The problem was that I have a theme applied that has specific fields for the tag line and description of the site, and I didn't feel like tearing it apart for this modification.

dknewmedia-n'akwụkwọ akụkọ

Iji mee nke a site na iji mgbakwunye na isi okwu ga-achọ iji ihe dị egwu Advanced Custom Fields ngwa mgbakwunye na Repeater Field Add-na – this is how we'd do it for clients. For our site, though, we often take shortcuts and this little code snippet works just as well!

Basically, you just enter as many headlines into a field and separate them with some character (I use the “|” symbol). Then you can utilize PHP's explode function which puts all the headlines into an array and then use PHP's shuffle function to shuffle the order of the array, and then display the first result. You only display the first result… this way if you only have one result it will still be displayed properly!

N'ime isiokwu anyị ebe egosiri isi okwu, anyị na-edochi ederede ederede na koodu ndị a:


Ọ bụrụ na ị chọrọ inwe fancy, ị nwere ike ịgafe a dị ka a omenala gbanwere na nchịkọta Google ma nwalee isi okwu nke kacha mma!

Kedu ihe ị chere?

Ebe a na-eji Akismet iji belata spam. Mụta otu esi etinye usoro data gị.