in Thesis Archives - WP Smith
post

Useful WordPress, Genesis, & Thesis Directory and URL (HTTP) PHP Constants

When creating WordPress plugins, themes, or tweaking plugins, themes, functions.php, you will often need to reference files and folders throughout the WordPress installation. Since WordPress 2.6 (if they are pre-2.6, then use die();), users have had the ability to move this directory anywhere they want, so you always want to avoid hardcoding so that the code is re-usable, especially with plugins. WordPress has defined a set of PHP CONSTANTS (by the way, constants are always UPPERCASE) to store the path to the wp-content and plugins directories. You can use these CONSTANTS in your plugins, child themes or functions.php for any paths you need regardless of where the actual directory might exist on the server.

  • WP_CONTENT_URL: Full URL to wp-content
  • WP_CONTENT_DIR: The server path to the wp-content directory
  • WP_PLUGIN_URL: Full URL to the plugins directory
  • WP_PLUGIN_DIR: The server path to the plugins directory
  • WP_LANG_DIR: The server path to the language directory

You can set your own CONSTANT_DIR by (as a reminder, constants are always UPPERCASE):

[php]define(‘CONSTANT_DIR’, ABSPATH . ‘wp-content’); //sets DIR[/php]

You can set your own CONSTANT_URL by (as a reminder, constants are always UPPERCASE):

[php]define(‘CONSTANT_URL’, get_option(‘siteurl’).’/wp-content/’); //sets URL[/php]

For GENESIS Users, some CONSTANTS of interests are:

  • STYLESHEETPATH: /…/…/…/…./…/…/wp-content/themes/child_theme
  • TEMPLATEPATH: /…/…/…/…./…/…/wp-content/themes/genesis
  • PARENT_URL: get_bloginfo(‘template_directory’): e.g., http://domain.com/wp-content/themes/genesis
  • CHILD_URL: get_bloginfo(‘stylesheet_directory’): e.g., http://domain.com/wp-content/themes/child_theme
  • PARENT_THEME_VERSION: refers to the Genesis version running
  • PARENT_THEME_NAME = ‘Genesis’
  • GENESIS_LANGUAGES_URL (sets to Genesis Library for Child Themes)

For THESIS (1.8) Users, some CONSTANTS of interests are:

  • THESIS_CUSTOM = STYLESHEETPATH: /…/…/…/…./…/…/wp-content/themes/thesis_18/custom
  • THESIS_CUSTOM_FOLDER: get_bloginfo(‘stylesheet_directory’) . ‘/custom': e.g., http://domain.com/wp-content/themes/thesis_18/custom
  • THESIS_LAYOUT_CSS: THESIS_CUSTOM . ‘/layout.css: e.g., http://domain.com/wp-content/themes/thesis_18/layout.css
  • THESIS_ROTATOR:THESIS_CUSTOM . ‘/rotator': e.g., http://domain.com/wp-content/themes/thesis_18/rotator
  • THESIS_ROTATOR_FOLDER: THESIS_CUSTOM_FOLDER . ‘/rotator': e.g., http://domain.com/wp-content/themes/thesis_18/rotator

Are there any CONSTANTS that are used quite often that I missed?

post

Posting on Two Different Pages When Using a Static Front Page

On one of my sites using Thesis, I wanted to create the WordPress blog so that I can “blog” on two different pages (in my case I wanted a blog blog and a podcast blog) based on categories with a static home page. So I first go to /wp-admin/options-reading.php and select static page and select my front page (Create New Page called Home) and my posts page (Create New Page called Blog). If you want two different blogs then your post page could be something like Blog1.

Since WordPress defaults to one certain page (the posts page) to be able to have it default to two different pages, we will be using Categories to control which posts go where. For example, blog posts (with multiple categories) to one page and my podcast posts (via podpress, with only 2 categories) to another page (called Podcasts).

I use categories for my blog and have two categories (podcast and something else) that I exclude from my blog (or posts page) and create a custom category page (Thesis Tutorial – Creating Custom Categories – Sugarrae) for podcasts (or you can use custom_functions.php to create a custom page with its own CSS, etc). You can use the Front Page Excluded Categories or Simply Exclude or Front Page Category (inclusion method) plugin if your blog is your front page (which here we are using a static page) or you can refer to the WordPress Functions Reference (Function Reference/query posts WordPress Codex) which tell you how to Exclude Posts Belonging to Only One Category (Show all posts except those from a category by prefixing its ID with a ‘-‘ (minus) sign) by using the php code query_posts('cat=-3'); manually.

To remove the Podcasts & Podcasts ShowNotes (categories) posts, I added this code to my custom_functions.php

[php]//exclude category from the posts page
function exclude_category($query) {
if ( $query->is_posts_page) {
$query->set(‘cat’, ‘-324, -20′);
}
return $query;
}

add_filter(‘pre_get_posts’, ‘exclude_category’); [/php]

is_posts_page (Function Reference/WP Query WordPress Codex says it is available for wp-query) works! The category IDs (-324, -20) can be found when you go to /wp-admin/categories.php and hover over the category, you will see /wp-admin/categories.php?action=edit&cat_ID=XXX at the bottom (in Firefox), or if you click on the category, you will see this in the URL. You want the cat_ID number. The (-) tells the query to exclude the category. So you would replace my numbers 324 and 20 with your category number(s). If you have only one category, it will look like this: $query->set('cat', '-XXX'); but if you have two it will look like this:$query->set('cat', '-XXX, -XXX'); and if you have three it will look like this: $query->set('cat', '-XXX, -XXX, -XXX');.

This creates the Blog posts correctly. Now to create the second one, there are two methods: (1) Custom Category Page (see Sugarrae’s Creating Custom Categories) or (2) Custom Page (see DIY’s Custom Page tutorial). The easier option is to use the custom categories (usually renders a url of domain.com/category/podcasts/), but the sweeter way is the Custom Page.

I hope this helps!