user5854440 user5854440 - 3 months ago 14
PHP Question

Wordpress functions not working in custom theme

So I'm super new to Wordpress. I set up a Wordpress local server on MAMP yesterday and I'm trying to build my own theme currently. Trouble is, whenever I try to do

the loop
, I'm not getting any content. my code works if I just use php, but the problem is custom Wordpress functions aren't usable (i.e.
have_posts()
)

A couple other posts have suggested requiring
wp-blog-header
, but that hasn't worked either. Here's my code:

<?php

define('WP_USE_THEMES', false);
require('../../../wp-blog-header.php');

if(have_posts()) :
echo 'testing'

else :
echo 'testing'
endif;


?>


Nothing currently displays on my screen.

wp-blog-header.php
is located here:
wordpress -> wp-blog-header.php


My custom theme is located here:
wordpress -> wp-content -> themes -> firstTheme -> index.php


All tips are appreciated.

Answer

Well, you're writing PHP and your code contains

if(have_posts()) :
    echo 'testing'
else : 
    echo 'testing'
endif;

I'm not sure how can this be valid in PHP. I'd expect

if(have_posts())
    echo 'testing';
else
    echo 'testing';

See also if and else syntax in PHP.

Comments