technillogue
technillogue

Reputation: 1571

Make special pages from WordPress theme?

I'm trying to figure out how a certain WordPress sets things up. I'd like to have a special page where I could make WP calls and interact with the theme, without affecting anything else.

I just making test.php and putting it into my theme's folder, but that doesn't work.

Upvotes: 0

Views: 505

Answers (5)

Skrivener
Skrivener

Reputation: 1023

@Eliran provides one possible option, but you could also add a page in the back-end of WP, just make sure it has the slug 'test', and change your 'test.php' filename to 'page-test.php'. If you're worried about the public seeing this, set the page visibility in the admin to 'private'.

Edit:

to move your understanding along a little further also, you should review the way that WordPress determines what file to grab to render a particular URL. This can be pretty confusing to start with, so be patient if you're not familiar with it, but it's at the heart of designing WP themes. I'll link to the examples, and if you scroll down a little there's a diagram that, along with the text, will help you see how WP is 'thinking'. http://codex.wordpress.org/Template_Hierarchy#Examples

Upvotes: 2

The Alpha
The Alpha

Reputation: 146191

What Pages are Not:

  • Pages are not Posts, nor are they excerpted from larger works of fiction. They do not cycle through your blog's main page. WordPress Plugins are available to change the defaults if necessary.
  • Pages cannot be associated with Categories and cannot be assigned Tags. The organizational structure for Pages comes only from their hierarchical interrelationships, and not from Tags or Categories.
  • Pages are not files. They are stored in your database just like Posts are.
  • Although you can put Template Tags and PHP code into a Page Template file, you cannot put these into the Page or Post content without a WordPress Plugin like Exec-PHP which Read overwrites the code filtering process.
  • Pages are not included in your site's feed.
  • Pages and Posts may attract attention in different ways from humans or search engines.
  • Pages (or a specific post) can be set as a static front page if desired with a separate Page set for the latest blog posts, typically named "blog."

More About Pages.

In WordPress to add a new page you have to log in to the admin/backend and from the pages menu you can add a new page. In this case, you can select templaes for your page and also you can create a custom page template for that page.

You may read Createing a new page in WordPress. and custom Page template in WordPress.

Upvotes: 0

davidmh
davidmh

Reputation: 1378

It may be other ways to do this, but I rather use the rewrite API and custom query vars, to create custom routes.

A previous answer on the subject can be found here

The basic idea is to add a new url rule, catch the query var with the parse_request filter and maybe do a die or redirect to prevent the default wordpress template from loading.

I prefer this over theme templates, because with templates you need to create a page for each new url, and if that page gets acidentally deleted, that functionality would stop working.

Upvotes: 0

Eliran Efron
Eliran Efron

Reputation: 621

You can see here: Page Templates

all you need to do is create a page named page-{custom-name}.php and add it to the theme folder.

and inside this php file add:

/*
Template Name: My Custom Page
*/

and than to use this page you need to go to the wp-admin, add/edit a page and chose it:

enter image description here

inside the php file everything you do is classic wordpress. all this is giving you is a custom page tamplate.

Upvotes: 1

DragonVet
DragonVet

Reputation: 409

Put it in your root folder. When you go to look at it, you'd look at www.mywebsite.com/test.php

Upvotes: 0

Related Questions