简体   繁体   中英

Wordpress include custom page

I'm sure this is a simple question. But how do I get Wordpress at startup to ignore trying to load a Page or Post and instead load my custom page? When in the Wordpress bootstrap process is it decided which php-page is going to load?

I will have the following url:

bt.local/wp/ads/1

And would like a php-page called ads.php to be loaded and load the ad with adid = 1.

What's the best way to solve this? (there's no Post called ads and there's no Page called Ads).

Thank you!

KR

Josef

<?php include('custompage.php'); ?> <?php include('custompage.php'); ?> ???

you can use the template_redirect action for that - example:

add_action('template_redirect', 'my_template_loader');


function my_template_loader() {
    if( get_query_var('adid') ) {
       locate_template(array("your-custom-page.php"), true);
    }
}

edit:

in addition to that you need some new rewrite rule to add your custom url - the basic information is here http://codex.wordpress.org/Function_Reference/WP_Rewrite

your rule could look something like that:

$newrules['ads/(\d*)$'] = 'index.php?pagename=ads&adid=$matches[1]';

this needs a 'placeholder' page called ads to be setup and in addition to that you have to register your new query var adid like that:

add_filter('query_vars', 'add_adid_var');
function parameter_queryvars($qvars) {
    $qvars[] = ' adid';
    return $qvars;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM