Support » Fixing WordPress » PHP won't work outside of WordPress

  • I am trying to use php in my website and it works with wordpress but shows a White Screen of Death (or error 500 in some cases) if I try to use PHP anywhere else in the site (e.g. regular static pages)

    All pages are .php
    There are NO errors with the scripts, no script works

    i am sick of having to use Javascript to achieve 1/10 of what php can do.
    The link below is a php script and contains no HTML it is a pure php file:
    http://pantsonandoutthedoor.com/reviews/test.php
    below is the source of the above file

    <?php
    	// include our wordpress functions
    	// change relative path to find your WP dir
    	define('WP_USE_THEMES', false);
    	require('./wp-config.php');
    	$wp->init();
    	$wp->parse_request();
    	$wp->query_posts();
    	$wp->register_globals();
    	$posts = get_posts(array(
    	'numberposts' => 5,
    	'offset' => 0,
    	'orderby' => 'post_date',
    	'order' => 'DESC',
    	'post_type' => 'post',
    	'post_status' => 'publish'
    	));
    	$json = array();
    	$json['err'] = false;
    	 if ($posts) {
    	 foreach ($posts as $post) {
    	 $ray = array();
    the_post();
    $ray['id'] = $post->ID;
    $ray['date'] = $post->post_date;
    $ray['timestamp'] = strtotime($post->post_date);
    $ago = days_ago($ray['date'], date('n/j/Y g:i a'));
    $ray['ago'] = ($ago == "") ? false : $ago;
    $ray['contents'] = shorten_string(strip_tags($post->post_content), 40);
    $ray['link'] = $post->guid;
    $ray['title'] = $post->post_title;
    $ray['link'] = '<a href="'.$post->guid.'">'.$post->post_title.'</a>';
    // New if <= 5 days ago
    $ray['isNew'] = date('U') - $ray['timestamp'] <= 60 * 60 * 24 * 5;
    $json['posts'][] = $ray;
    }} header('Content-type: application/json;');
    echo json_encode($json);
    ?>

Viewing 1 replies (of 1 total)
  • Why not create a new page template, strip that from things you don’t need (with a custom header/sidebar/footer) and then you can do whatever you want.

    Why create a blank page and try to import all its functions when this can be done through WP ?

Viewing 1 replies (of 1 total)
  • The topic ‘PHP won't work outside of WordPress’ is closed to new replies.