I am building a plugin for the first time and I have setup my rewrite rules to call a PHP file I have located in my plugin folder and this is working but all I have it output just now is "test"
I wanted to ask, is there is a way of pulling in the existing theme and using this as the basis for the page, then I can have my plugin just output the page content area so to speak.
My plugin is quite big in terms of the amount of data it handles so I would like to be able to use a menu link to the aforementioned file and this file can then output all the sub pages of content but still using the default theme (theme I have made) and fill the content area only is this possible and if so is there anything to explain this already available because I couldn't see it.
Any help with this would be much appreciated.
Edit: I have tried including a file from my current theme but this will give me a 500 error so I assume its not as simple as this.
Have you thought about using custom post types for your plugin content rather than relying on custom tables and separate code?
Other than that, you could use a shortcode (just one) and have users insert that into a regular WP page, the shortcode then displays all of your various plugin stuff.
It's hard to be more specific without understanding why you've done it this way.
Related
I need to add few additional pages to my wordpress site.
These pages should not be "part of the site", ie they should not be linked somewhere from the posts and so on.
However, they should have the same header/footer as the rest of the site ( I am using custom theme ). And they should be accessible via url.
The final requirement is, I should be able to code in php.
At the moment, I tried to create a new "Page" in my admin console. And then write some php-code inside. However, all my php code gets commented and since not executed.
I don't think that installing plugins such as Exec-PHP is a good idea, so I am trying to find other solutions.
Any comments/advice/suggestions how to make it?
I would be grateful if you give me some how-to link.
Thank you in advance.
You can use a custom page template in your theme for this and just keep the site empty in the admin panel:
http://codex.wordpress.org/Theme_Development#Custom_Page_Templates
By using Template tag's you can create custom page.
write this code on the top of your php file....
/*
Template Name: Your Template Name
*/
I'm using Artisteer to create WordPress themes.
Artisteer is not able to include php code into pages, then I have to do some modification via WordPress page editor.
I'm using "PHP Insert" plugin to include php code into WordPress page editor and to make WordPress able to use my php code into my pages.
In my site I have a form for B.M.I. calculation and I need to use php code in the page.
The problem is that if I change the theme in Artisteer and if I upload it into WordPress, I loose php changes.
It's very boring to apply modification every time (and also dangerous...lost code, wrong code position,...).
I'm thinking to use a child theme, but I don't know how to apply it to php code added into pages.
Suggestions?
Thanks in advance
The Wordpress team has made it a rule of thumb to never execute PHP in posts and pages either because it can be hectic to change things in the future and may expose security vulnerabilities that could not be fixed by Wordpress itself.
A better practice is editing your WordPress theme by creating a custom post/page template - that basically can include everything. However for some situations, it may be necessary to execute PHP on more than one WordPress posts/pages.
In this case, my recommendation would be to create a simple page template containing your PHP, or, if your code is used multiple times, create a shortcode (in the functions.php of your template).
Simplest example of adding a shortcode tag (with parameters) to your themes functions.php:
function footag_func( $atts ) {
return "foo = {$atts['foo']}";
}
add_shortcode('footag', 'footag_func');
The output code can be used everywhere with the tag [footag foo="bar"]. When extending this, alway remember to return the results of your function. Using echo or print would just echo the results (on the top of your content, skipping the content itself).
You're not supposed to use PHP in the content editor, you've got a few decent options:
Creating a custom template for that specific page:
http://codex.wordpress.org/Page_Templates
Creating a shortcode for that specific piece of PHP code:
http://codex.wordpress.org/Shortcode_API
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.
#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
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:
inside the php file everything you do is classic wordpress.
all this is giving you is a custom page tamplate.
Put it in your root folder. When you go to look at it, you'd look at www.mywebsite.com/test.php
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.
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.
I am working on moving a normal HTML website to Wordpress for a client. It's a simple website with a lots of images and HTML text. The idea is that client should be able to modify contents of website through the simple CMS without actually looking into code.
While doing analysis I came across some roadblocks like
Problem: If I want to modify text/ image for Header or footer in wordpress, I will need to do it in PHP code.
Solution: Create a customized header/ footer update tab. Modify database to store these contents and modify PHP code to directly read the data from database.
Problem: Wordpress provides a set of widgets (blogrolls catergories etc.), I need more like Latest News.
Solution: Modify PHP code and datbase, basically create your own widget.
Problem: There are a lot of static HTML pages which are linked from one page to another.
Solution: I don't see any way in wordpress to create static HTML pages which among which we can create links from one to another.
Solution: Create a new interface where user can create HTML pages/ plain text content. This will return a link which can be used to provide hyperlinks in another page.
My query is: Are the solutions mentioned above correct? The problems mentioned look very common, so is there a tried and tested way to solve?
Edit: User (Client) want to use wordpress. Just wanted to make sure here that Solutions I am thinking about are correct. So would like to have suggestion from someone who has already worked on Wordpress and solved the problems like I have mentioned. Do not want to reinvent the wheel.
I've worked a lot on a Wordpress-base white-label CMS, so I think I can help you in some ways.
First of all : always remember the real power of Wordpress is its community and its plugins base (that you can access directly from wordpress admin)
Problem: If I want to modify text/ image for Header or footer in
wordpress, I will need to do it in PHP code. Solution: Create a
customized header/ footer update tab. Modify database to store these
contents and modify PHP code to directly read the data from database.
If you want to have a fully customisable appearance, I suggest you to start from a theme like Consctructor. This is a theme with a whole admin panel for simple appearance editing. The code is far from perfect but this is a good start.
If you just want to manage the content of header / footer, you can do it via Menus / Widgets / Links, but only if your theme is designed for that. For example, a lot of good theme allow you to add widgets in footer, then you can construct your footer with only a few drag-n-drop in the Appearance/Widget menu. For header image, the default theme (Twenty-Twelve) provide an header panel where you can upload a new image.
Problem: Wordpress provides a set of widgets (blogrolls catergories
etc.), I need more like Latest News. Solution: Modify PHP code and
datbase, basically create your own widget.
Yes you can create your own widgets for specific needs, but I suggest you always start from an existing one. There is a lot of plugins providing you dozens of widgets. Explore that before reinventing the wheel.
For your specific case, a 1s google-search returns me this plugin.
Problem: There are a lot of static HTML pages which are linked from
one page to another. Solution: I don't see any way in wordpress to
create static HTML pages which among which we can create links from
one to another. Solution: Create a new interface where user can create
HTML pages/ plain text content. This will return a link which can be
used to provide hyperlinks in another page.
No, use the pages. Wordpress Pages are static content and this is editable, and for each page ou have a permalink. If Pages aren't good for your job, you can consider creating a custom type (or install a plugin that create a custom type).
Wordpress themes can be made to accept images and stuff like that.
The are ample wordpress widgets to do just that. Just be sure to find the right one.
I don't understand this one. You can create any amount of wordpress pages, and to link between them is easy. If you want your files to end in .html, simply enable permalinks and specify that option. It's very easy.
Reinventing the wheel sometimes is good, possibly even good for you (Given patience and time). Nothing is prepackaged to do everything for you, hence these are times when you need a custom build.
Anyways, CMSes don't come as a multipurpose, all-in-one package that solves your programming woes and turns everything into a point-and-click solution. Every CMS is unique, designed to serve a specific purpose. Others general purpose, others for blogs, others for very simple sites.
If you don't find anything native that fits your needs, find the right plugin for the job. If you cannot find anything at all, then might as well build a custom solution, or build on top of an existing resource. Innovate
im looking easy steps for convert any html/php template into a very simple wordpress theme for personal use. I have a site, in there i want news at the begining using the wordpress interface, i worked a lot with wordpress and i made some themes, but modifing already made ones, so i didnt care a lot about the code.
So, lookin in internet i dint found a good step by step tutorial in order to create a simple theme in wordpress from 0. Remember that i dont need sidebars, widgets and soo, i only need "the loop", or, the last 3 post made.
It's as simple as installing wordpress correctly and then including the wp-blog-header file into your pages. Doing so will give you access to all of WP's functions.
require('/path/to/wp-blog-header.php');
$posts = get_posts('arguments');