113943 次阅读

代码访问随机日志

--
不记得是怎么找到这篇文章的,但是很庆幸,又找到了好东西.哈哈

原来在IM路人 的博客中看到了导航栏上的随机文章,感觉挺好的,但是不知道怎么弄的.
昨天晚上找到了个代码,在本地试验了一下.完全可以使用.所以就转过来了.

具体效果情点击侧栏Fantasy-time右侧的 随便看看.

代码来源泪未溅心先碎WordPress折腾小技巧1

代码如下,将代码放到functions.php中,然后用yourname.com/?random 就可以访问随机日志

function matt_random_redirect() {
    global $wpdb;

    $query = "SELECT ID FROM $wpdb->posts WHERE post_type = 'post' AND post_password = '' AND     post_status = 'publish' ORDER BY RAND() LIMIT 1";

    if ( isset( $_GET['random_cat_id'] ) ) {
        $random_cat_id = (int) $_GET['random_cat_id'];
        $query = "SELECT DISTINCT ID FROM $wpdb->posts AS p INNER JOIN $wpdb->term_relationships AS tr ON (p.ID = tr.object_id AND tr.term_taxonomy_id = $random_cat_id) INNER JOIN  $wpdb->term_taxonomy AS tt ON(tr.term_taxonomy_id = tt.term_taxonomy_id AND taxonomy = 'category') WHERE post_type = 'post' AND post_password = '' AND     post_status = 'publish' ORDER BY RAND() LIMIT 1";
    }

    if ( isset( $_GET['random_post_type'] ) ) {
        $post_type = preg_replace( '|[^a-z]|i', '', $_GET['random_post_type'] );
        $query = "SELECT ID FROM $wpdb->posts WHERE post_type = '$post_type' AND post_password = '' AND     post_status = 'publish' ORDER BY RAND() LIMIT 1";
    }

    $random_id = $wpdb->get_var( $query );

    wp_redirect( get_permalink( $random_id ) );
    exit;
}

if ( isset( $_GET['random'] ) )
    add_action( 'template_redirect', 'matt_random_redirect' );

貌似路人童鞋用的也是这个代码?

相关文章

已有 2364 条评论
  1. MarkWig

    [url=https://viagrawithoutprescription.com/]buying generic viagra[/url] [url=https://metformingeneric.com/]buy metformin[/url] [url=https://prednisolonetablets.com/]buy prednisolone online[/url] [url=https://ventolinwithoutprescription.com/]ventolin no prescription[/url] [url=https://buylisinoprilwithoutprescription.com/]lisinopril without prescription[/url]

    MarkWig 回复
  2. agehotad

    Encourage fpj.oypo.kelvin.mbioq.com.ruh.xr miscarriages cow blind-ending [URL=http://downtownrichmondassociation.com/viagra/]viagra no prescription[/URL] viagra http://downtownrichmondassociation.com/viagra/#viagra-buy viagra india [URL=http://umichicago.com/payday-loans-direct-lender/]payday loans[/URL] payday loans http://umichicago.com/payday-loans-direct-lender/#payday-loans-direct-lender payday loans no credit check direct lender [URL=http://golfeatoncanyongc.com/personal-loans-columbia-sc/]personal loans in charleston sc[/URL] unsecured loans online http://golfeatoncanyongc.com/personal-loans-columbia-sc/#personal-loans-san-antonio-tx personal loans columbia sc [URL=http://websolutionsdone.com/retin-a/]retina a[/URL] retin a http://websolutionsdone.com/retin-a/#where-can-i-buy-retin-a-online? purchase retin a online [URL=http://downtownrichmondassociation.com/cialis/]no prescription cialis[/URL] what is 100 mg cialis http://downtownrichmondassociation.com/cialis/#generic-cialis cialis moins cher [URL=http://listigator.com/canadian-pharmacy-price/]online pharmacy cialis[/URL] on line pharmacy http://listigator.com/canadian-pharmacy-price/#cialis-online-pharmacy pharmacy [URL=http://golfeatoncanyongc.com/personal-loans-in-charleston-sc/]easy personal loans online[/URL] personal loans columbus ohio http://golfeatoncanyongc.com/personal-loans-in-charleston-sc/#personal-loans personal loans columbus ohio [URL=http://scoutcampreviews.com/levitra-20mg/]generic levitra vardenafil 20mg[/URL] levitra buy http://scoutcampreviews.com/levitra-20mg/#levitra-20mg levitraonline subxiphoid carcinogens.

    agehotad 回复
  3. eihozaqavo

    The pyg.rlxp.kelvin.mbioq.com.erq.dn heading shrunk higher, [URL=http://sandiegoessentialguide.com/cash-advance-toledo-ohio/]cash advance loans bad credit[/URL] emergency cash advance http://sandiegoessentialguide.com/cash-advance-toledo-ohio/#cash-advance-toledo-ohio cash advances [URL=http://listigator.com/viagra-online/]viagra online[/URL] viagra 100mg http://listigator.com/viagra-online/#viagra-gel expired viagra [URL=http://myinxus.com/tadalafil-20-mg/]cheapest cialis dosage 20mg price[/URL] buy cialis http://myinxus.com/tadalafil-20-mg/#generic-cialis-5mg pharmacy cadia cialis [URL=http://24hloaneasy.com/]payday loans el paso[/URL] payday loans http://24hloaneasy.com/#payday-loans instant payday [URL=http://anger-management-action.com/payday-loans-ogden-utah/]california payday loans online[/URL] payday loans salt lake city http://anger-management-action.com/payday-loans-ogden-utah/#texas-payday-loans-online texas payday loans online [URL=http://gasmaskedlestat.com/buy-prednisone-online/]buy prednisone without prescription[/URL] buy prednisone 20 mg http://gasmaskedlestat.com/buy-prednisone-online/#prednisone-20mg online prednisone [URL=http://umichicago.com/payday-loan/]payday loans el paso[/URL] payday loans saskatoon http://umichicago.com/payday-loan/#payday-loan-usa unsecured personal loans for bad credit swellings continence.

    eihozaqavo 回复
  4. JaneWig

    [url=http://tetracyclinewithoutprescription.com/]tetracycline[/url]

    JaneWig 回复
  5. car insurance cheap

    [url=http://autoinsurance.us.com/]purchase auto insurance online[/url]

    car insurance cheap 回复
  6. EvaWig

    [url=https://buypropeciawithoutprescription.com/]propecia witout prescription[/url]

    EvaWig 回复
  7. JoeWig

    [url=https://ventolinwithoutprescription.com/]no prescription ventolin inhaler[/url] [url=https://buypropeciawithoutprescription.com/]propecia[/url] [url=https://cialisfromcanada.com/]cialis canada online pharmacy[/url] [url=https://phenergan25.com/]phenergan pill[/url] [url=https://buytadalafilwithoutprescription.com/]buy tadalafil without prescription[/url] [url=https://buylisinoprilwithoutprescription.com/]lisinopril[/url] [url=https://prednisolonetablets.com/]prednisolone[/url] [url=https://metformingeneric.com/]metformin 500mg er[/url] [url=https://tetracyclinewithoutprescription.com/]tetracycline[/url] [url=https://viagrawithoutprescription.com/]viagra without a prescription[/url]

    JoeWig 回复
  8. MiaWig

    [url=http://metformingeneric.com/]metformin[/url] [url=http://viagrawithoutprescription.com/]viagra prescription[/url] [url=http://prednisolonetablets.com/]buy prednisolone tablets[/url] [url=http://tetracyclinewithoutprescription.com/]tetracycline antibiotic[/url] [url=http://cialisfromcanada.com/]cialis generic cheap[/url]

    MiaWig 回复
  9. agudoeke

    Can jca.msxr.kelvin.mbioq.com.yru.gm eponymous [URL=http://downtownrichmondassociation.com/viagra/]buyviagraonline.com[/URL] viagra http://downtownrichmondassociation.com/viagra/#viagra viagra [URL=http://umichicago.com/payday-loans-direct-lender/]quick money loan[/URL] private money loans http://umichicago.com/payday-loans-direct-lender/#loans-online-fast payday loans no credit check direct lender [URL=http://golfeatoncanyongc.com/personal-loans-columbia-sc/]personal loan[/URL] personal loans in charleston sc http://golfeatoncanyongc.com/personal-loans-columbia-sc/#personal-loans-san-antonio-tx personal loans in charleston sc [URL=http://websolutionsdone.com/retin-a/]retin-a[/URL] retin a http://websolutionsdone.com/retin-a/#retin-a-cream-0.1 retin a cream 0.05 [URL=http://downtownrichmondassociation.com/cialis/]cialis cheap[/URL] cialis 20 mg online http://downtownrichmondassociation.com/cialis/#canadian-cialis cialis [URL=http://listigator.com/canadian-pharmacy-price/]pharmacy[/URL] pharmacy http://listigator.com/canadian-pharmacy-price/#canadian-pharmacy-cialis-20mg pharmacy [URL=http://golfeatoncanyongc.com/personal-loans-in-charleston-sc/]personal loans columbus ohio[/URL] personal loans http://golfeatoncanyongc.com/personal-loans-in-charleston-sc/#personal-loans-in-columbia-sc personal loans in charleston sc [URL=http://scoutcampreviews.com/levitra-20mg/]levitra price[/URL] levitra blood pressure http://scoutcampreviews.com/levitra-20mg/#levitra-blood-pressure levitra 20mg failures nystagmus.

    agudoeke 回复
  10. ozuzelogoxib

    An bws.pngm.kelvin.mbioq.com.ljq.cs ensures [URL=http://eatingaftergastricbypass.net/payday-loans-houston-tx/]payday loans houston tx[/URL] payday loans houston tx http://eatingaftergastricbypass.net/payday-loans-houston-tx/#payday-loans-houston-tx payday loan no credit check no broker [URL=http://scoutcampreviews.com/canadian-pharmacy/]canadian pharmacy cialis[/URL] online pharmacy no prescription http://scoutcampreviews.com/canadian-pharmacy/#pharmacy-online canadian pharmacy online drugstore [URL=http://listigator.com/cialis-generic/]cialis prices[/URL] generic cialis india http://listigator.com/cialis-generic/#cialis cialis tadalafil generic [URL=http://listigator.com/viagra-online/]viagra for men for sale[/URL] where to but viagra without dr. http://listigator.com/viagra-online/#on-line-viagra lowest price for viagra 100mg [URL=http://umichicago.com/payday-loan/]online payday loans ohio[/URL] direct payday loans no brokers http://umichicago.com/payday-loan/#payday-loan payday loan [URL=http://websolutionsdone.com/buy-clomid-online/]clomid[/URL] clomid on line http://websolutionsdone.com/buy-clomid-online/#buying-clomid clomid [URL=http://myinxus.com/lasix-online/]lasix[/URL] lasix online http://myinxus.com/lasix-online/#buy-furosemide lasix [URL=http://gasmaskedlestat.com/generic-levitra/]generic levitra[/URL] generic levitra http://gasmaskedlestat.com/generic-levitra/#prices-for-levitra-20-mg cheep levitra investigation: lamellar sitting neurotransmission.

    ozuzelogoxib 回复
  11. ezemufuyud

    The few.abwa.kelvin.mbioq.com.amo.nv opiate-sparing [URL=http://refrigeratordealers.com/pharmacy/]onlinepharmacy.com[/URL] canadian pharmacy online no script http://refrigeratordealers.com/pharmacy/#pharmacy walmart pharmacy cialis 20mg [URL=http://gasmaskedlestat.com/accutane/]generic accutane[/URL] accutane buy http://gasmaskedlestat.com/accutane/#accutane-for-sale the dangers of accutane [URL=http://downtownrichmondassociation.com/generic-cialis/]cialis canada[/URL] il cialis http://downtownrichmondassociation.com/generic-cialis/#metromeds.net-for-cialis-20mg generic cialis [URL=http://sci-ed.org/cialis/]cialis paypal accepted[/URL] cialis http://sci-ed.org/cialis/#cialis-for-sale generic cialis lowest price [URL=http://sci-ed.org/amoxicillin/]amoxil[/URL] order amoxicillin 500mg http://sci-ed.org/amoxicillin/#amoxicillin-online amoxicillin 500 mg [URL=http://sci-ed.org/zithromax/]azithromycin in children[/URL] buy azithromycin 250 mg http://sci-ed.org/zithromax/#azithromycin-gonorrhea zithromax 250 mg questions sides, trismus.

    ezemufuyud 回复
  12. abuvavueqeh

    Haemodynamic nkx.lvym.kelvin.mbioq.com.pcf.ea creates leukaemias, destruction [URL=http://golfeatoncanyongc.com/payday-loans-houston-tx/]easy loans for bad credit online[/URL] payday loans springfield mo http://golfeatoncanyongc.com/payday-loans-houston-tx/#payday-loans-canton-ohio payday loans in dallas [URL=http://downtownrichmondassociation.com/viagra-generic/]discount viagra[/URL] viagra generic http://downtownrichmondassociation.com/viagra-generic/#taking-viagra-with-cialis canadian viagra viagra overnight [URL=http://refrigeratordealers.com/cialis-canadian-pharmacy/]pharmacy[/URL] cialis canadian pharmacy http://refrigeratordealers.com/cialis-canadian-pharmacy/#on-line-pharmacy pharmacy [URL=http://sandiegoessentialguide.com/approved-cash-advance/]cash advance[/URL] approved cash advance http://sandiegoessentialguide.com/approved-cash-advance/#quick-cash-advance fast cash advance [URL=http://refrigeratordealers.com/buy-prednisone/]prednisone without a prescription[/URL] prednisone without a prescription http://refrigeratordealers.com/buy-prednisone/#prednisone-without-a-prescription prednisone no prescription [URL=http://listigator.com/prednisone/]prednisone without prescription.net[/URL] prednisone 20 mg http://listigator.com/prednisone/#prednisone-20-mg prednisone 20 mg [URL=http://palawan-resorts.com/online-pharmacy/]online pharmacy[/URL] pharmacy prices for levitra http://palawan-resorts.com/online-pharmacy/#pharmacy pharmacy placental former throat hepatic.

    abuvavueqeh 回复
  13. alikalq

    A eac.xhmo.kelvin.mbioq.com.jcr.vo noxious gene; addition, [URL=http://listigator.com/levitra/]levitra prices[/URL] levitra http://listigator.com/levitra/#levitra buy levitra online [URL=http://gasmaskedlestat.com/prednisone/]prednisone[/URL] by prednisone w not prescription http://gasmaskedlestat.com/prednisone/#prednisone-without-prescription by prednisone w not prescription [URL=http://memoiselle.com/cash-advance/]short term cash advance[/URL] cash advance http://memoiselle.com/cash-advance/#cash-advance-stockton-ca short term cash advance [URL=http://palawan-resorts.com/pharmacy/]pharmacy[/URL] pharmacy http://palawan-resorts.com/pharmacy/#pharmacy cialis canadian pharmacy [URL=http://golfeatoncanyongc.com/quick-payday-loans/]quick loans for bad credit[/URL] quick payday loans http://golfeatoncanyongc.com/quick-payday-loans/#quick-payday-loans quick payday loans [URL=http://websolutionsdone.com/levitra/]levitra[/URL] order levitra http://websolutionsdone.com/levitra/#levitra-cheap levitra sample generic vardenafil [URL=http://dockpartsusa.com/payday-loans-ogden-utah/]payday loans[/URL] payday loans http://dockpartsusa.com/payday-loans-ogden-utah/#smart-loan payday loans [URL=http://myinxus.com/generic-viagra/]sildenafil citrate for small dogs[/URL] viagra pills cost http://myinxus.com/generic-viagra/#viagra viagra thinking, theca-lutein water?

    alikalq 回复
  14. SamWig

    [url=https://cialisfromcanada.com/]online cialis canada[/url] [url=https://viagrawithoutprescription.com/]viagra without prescription[/url] [url=https://buylisinoprilwithoutprescription.com/]lisinopril without prescription[/url] [url=https://prednisolonetablets.com/]prednisolone[/url] [url=https://metformingeneric.com/]metformin[/url] [url=https://phenergan25.com/]buy phenergan[/url] [url=https://buypropeciawithoutprescription.com/]cheap propecia[/url] [url=https://tetracyclinewithoutprescription.com/]buy tetracycline online without prescription[/url] [url=https://ventolinwithoutprescription.com/]ventolin[/url] [url=https://buytadalafilwithoutprescription.com/]buy tadalafil without prescription[/url]

    SamWig 回复
  15. ozabzod

    Central lnm.niax.kelvin.mbioq.com.euu.fi attached co-enzymes [URL=http://techiehubs.com/generic-cialis-canada-pharmacy/]canadian pharmacy cialis[/URL] generic cialis canada pharmacy http://techiehubs.com/generic-cialis-canada-pharmacy/#cialis-canada-pharmacy pharmacy [URL=http://fitnesscabbage.com/levitra-generic/]sports and levitra[/URL] levitra generic http://fitnesscabbage.com/levitra-generic/#vardenafil-generic levitra [URL=http://wyovacationrental.com/cialis-20-mg-lowest-price/]cialis 20 mg lowest price[/URL] cialis 20 mg lowest price http://wyovacationrental.com/cialis-20-mg-lowest-price/#cialis-canadian cialis [URL=http://columbia-electrochem-lab.org/ventolin/]ventolin[/URL] buy ventolin online http://columbia-electrochem-lab.org/ventolin/#buy-ventolin-on-line ventolin [URL=http://sci-ed.org/ventolin/]spray ventolin[/URL] ventolin nebuliser http://sci-ed.org/ventolin/#ventolin-inhalers-to-buy ventolin nebuliser [URL=https://pharmacy24h.wixsite.com/levitra/]levitra 20 mg price[/URL] levitra generic 20 mg https://pharmacy24h.wixsite.com/levitra/#levitra-20-mg-walmart vardenafil [URL=http://scoverage.org/canadian-pharmacy-online/]pharmacy[/URL] cialis pharmacy http://scoverage.org/canadian-pharmacy-online/#viagra-pharmacy-uk cialis at canadian pharmacy [URL=http://theprettyguineapig.com/prednisone-online/]prednisone[/URL] deltasone and pregnancy category http://theprettyguineapig.com/prednisone-online/#prednisone-without-an-rx prednisone prednisone on line videos stand.

    ozabzod 回复
  16. MaryWig

    [url=https://tetracyclinewithoutprescription.com/]tetracycline prescription[/url] [url=https://viagrawithoutprescription.com/]100 mg viagra[/url] [url=https://metformingeneric.com/]metformin drug[/url] [url=https://buypropeciawithoutprescription.com/]purchase finasteride without a prescription[/url] [url=https://ventolinwithoutprescription.com/]ventolin[/url]

    MaryWig 回复
  17. IvyWig

    [url=https://tetracyclinewithoutprescription.com/]order tetracycline without a prescription[/url] [url=https://metformingeneric.com/]metformin buy online[/url] [url=https://cialisfromcanada.com/]cialis canada[/url] [url=https://phenergan25.com/]buying phenergan online[/url] [url=https://viagrawithoutprescription.com/]generic viagra best price[/url]

    IvyWig 回复
  18. oakidoji

    Regression uzg.imuw.kelvin.mbioq.com.zup.jx rota trams [URL=http://clearcandybags.com/online-pharmacy/]northwest pharmacy canada[/URL] online pharmacy http://clearcandybags.com/online-pharmacy/#generic-cialis-canada-pharmacy online pharmacy [URL=http://myinxus.com/levitra-20mg/]levitra online[/URL] levitra 20 mg http://myinxus.com/levitra-20mg/#usa-levitra levitra online [URL=http://sci-ed.org/buy-orlistat/]xenical[/URL] xenical oristat http://sci-ed.org/buy-orlistat/#lichenoid-eruption-associated-with-orlistat orlistat 120 mg [URL=http://wyovacationrental.com/100-mg-viagra-lowest-price/]viagra online uk[/URL] viagra http://wyovacationrental.com/100-mg-viagra-lowest-price/#viagra-100mg-canada viagra effects on men [URL=http://clearcandybags.com/levitra-20-mg-price/]buy levitra[/URL] levitra buy http://clearcandybags.com/levitra-20-mg-price/#buy-levitra levitra 20mg prices vardenafil [URL=http://sci-ed.org/diflucan/]buy fluconazole[/URL] diflucan http://sci-ed.org/diflucan/#fluconazole diflucan oral permission spores.

    oakidoji 回复
  19. eleletim

    These ctt.syxm.kelvin.mbioq.com.rqz.ol consultation, [URL=http://downtownrichmondassociation.com/levitra/]levitra[/URL] generic vardenafil 20mg http://downtownrichmondassociation.com/levitra/#levitra levitra 20mg [URL=http://davincipictures.com/cheap-viagra/]viagra[/URL] buy viagra http://davincipictures.com/cheap-viagra/#sildenafil-50-mg buy viagra [URL=http://refrigeratordealers.com/strattera/]atomoxetine[/URL] strattera buy online http://refrigeratordealers.com/strattera/#generic-strattera strattera discounts [URL=http://gasmaskedlestat.com/viagra-buy-in-canada/]who created extenze and viagra[/URL] discount viagra lowest prices http://gasmaskedlestat.com/viagra-buy-in-canada/#who-created-extenze-and-viagra viagra buy [URL=http://scoutcampreviews.com/buy-prednisone-online/]prednisone[/URL] prednisone with no prescription http://scoutcampreviews.com/buy-prednisone-online/#buy-prednisone-online prednisone 20mg [URL=http://wyovacationrental.com/levitra-20mg-best-price/]levitra[/URL] levitra cheap http://wyovacationrental.com/levitra-20mg-best-price/#levitra-20mg-best-price generic levitra revive excise, coagulability kitchen.

    eleletim 回复
  20. IvyWig

    [url=https://buylisinoprilwithoutprescription.com/]lisinopril no prescription[/url] [url=https://buypropeciawithoutprescription.com/]propecia[/url] [url=https://metformingeneric.com/]metformin without presription[/url] [url=https://phenergan25.com/]phenergan[/url] [url=https://ventolinwithoutprescription.com/]ventolin[/url]

    IvyWig 回复
发表新评论