0

I build a static page in my WordPress root folder. Now I'm trying to include a list of my categories with echo clpr_categories_list();.

Its not working because I some how have to tell the static page where to find my theme. How do I do this? Searched everywhere.

0

2 Answers 2

0

You need more than just telling the page where to find your theme. You will likely need to load WordPress.

You can do that with the following:

<?php 
define('WP_USE_THEMES', false);
require('./wp-load.php');
?>

Is the clpr_categories_list() a theme function? You could just WP's wp_list_categories() function to what you need. The function accepts quite a number of arguments to customize the outpout.

3
  • Yes clpr_categories_list();is a theme function. Tried your solution but not getting any output.
    – joloshop
    Commented Nov 26, 2018 at 21:19
  • Got me into the right direction thanks, partly working now.
    – joloshop
    Commented Nov 26, 2018 at 22:33
  • Glad to hear things are moving in the right direction!
    – butlerblog
    Commented Nov 26, 2018 at 23:04
0

Instead of building a separate page, build a custom TEMPLATE page. Then it will be inside your theme and already have access to all the functions. You do this by copying the page.php file from your theme into a new file and putting the template name up at the top in comments like this:

/* Template Name: Category Page */

Now you can create a fresh page and set the template of that page to "Category Page," which will now appear in the drop down for template selection.

You can strip out and add whatever you want as far as code goes, to get rid of menus and other things you may not want.

2
  • Thanks, I knew this however I have a reason to build a static page instead.
    – joloshop
    Commented Nov 26, 2018 at 22:33
  • Then you need to use the wp-load idea from the first answer, but you must use require_once to include the functions file of your (child) theme. If you come to the page from "outside" the WordPress framework like that, then theme or custom functions must be explicitly included. And I run multisite so I'm constantly using switch_to_blog to get the correct parameters. If you're on single site, you may still need to use switch_to_blog to get $wpdb to act right, for instance. I am only guessing though. I do nothing custom with single site.
    – Elkrat
    Commented Nov 27, 2018 at 14:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.