I'm putting together a web site that needed to include some signup and blogging capability. Wordpress seems to be a perfect fit for that portion of the app, so I've started experimenting with it. I see plenty of tutorials on creating custom themes so I don't expect that to be a problem.
What I'm not able to figure out is what to do with the rest of my site. I will have other non-blogging related php pages that will access a database, etc. I see that wordpress has a capability for generic pages of static content, but these would need to be coded PHP pages. I just can't find a way of having the wordpress theme apply to other php pages outside of wordpress. I was hoping of just doing something like
wp_header();
blah blah
wp_sidebar();
blah blah
wp_footer();
but I'm not really seeing any examples or documentation on how this might be done. Am I missing a key piece of documentation?
EDIT: The answer is to essentially copy and paste a file from the theme, with one crucial addition:
require( dirname(__FILE__) . 'path_to_wp_root/wp-load.php');
That sets up the wordpress environment and allows me to call get_header(), get_sidebar(), get_footer(), etc.
Generally, "yes".
A well-designed WordPress theme uses mostly CSS/Stylesheets for display, and you are correct in your assumptions: Look through the "Codex" about Theme Design / Template Design (http://codex.wordpress.org/Stepping_Into_Templates).
Essentially you could base your design on some of the current theme files, but leave out "the loop".
I think what you really want to do is include wp-load.php at the top of your php file. This will give you access to all the wordpress functions (wp-header(), wp-footer(), etc).
wordpress has pages in it. each page can have its own content and its own template and still be part of the whole wordpress site. i mean it will share the header and the footer if you want and will share the css and javascript that you include in both.
for more information on pages and pages templates
What you should do is develop your other non-blogging related php pages as a wordpress plugin. There are plenty of references online on how to do this, for example:
http://www.tutorialized.com/view/tutorial/Creating-a-Custom-Wordpress-Plugin-from-Scratch/41834
Another option is to use Wordpress as the CMS for all content on your site. This is increasingly becoming popular, as Wordpress is quite good at non-blog-things these days.
define('STYLESHEETPATH', '');
define('TEMPLATEPATH', '');
$base = substr(__DIR__, 0,strrpos(__DIR__, '/[name of the dir where u store the php files]'));
require_once($base."/wp-load.php");
require_once($base."/wp-includes/pluggable.php");
easy to use wordpress function outside
Related
Here's my issue. My company needs a vendor database added to our wordpress website. None of the existing plugins will even come close to what we need, and we already have a mysql database with all of our information, so we need to create a plugin or something to do what we need.
These urls need to be direct-accessible and have SEF urls. So, for example:
mysite.com/vendors/
mysite.com/vendors/pipe-manufacturers/
mysite.com/vendor/bobs-pipes/
And, the custom content needs to appear inside the wordpress template.
There are really 2 options:
1) Find a way to write our application outside of wordpress, but find a way to bootstrap wordpress to show the header, footer, and sidebar.
2) Run the app from inside wordpress.
So I went for option #2. I created a new template file named "vendor.php", and began working. I added this code to my functions.php of my theme:
add_filter( 'template_include', 'xyz_template_check' );
function xyz_template_check() {
global $template;
$rqst = $_SERVER['REQUEST_URI'];
$ra = split("/", $rqst);
if ($ra[1] == "vendors") {
$template_file = get_stylesheet_directory() . '/vendors.php';
return $template_file;
}
return $template;
}
So what the above code does, if it sees the word "vendors" as the first part of the url after the site name, it sends you to vendor.php. This works PERFECTLY....
except...
Wordpress believes that the page is not found. It returns a 404 header, and NOT FOUND into the page title and breadcrumb.
Adding a PAGE called "Vendor Database" with the permalink "/vendors/" fixes the main page. But there will be literally hundreds of vendors and different categories. I cant be creating a custom page for each one. This needs to be dynamic.
So, how do I make wordpress give a 200, and supply an acceptable page title, breadcrumb, etc.
Don't even get me started on the danged wp_title filter. This did NOT work as documented. Although, it just occurred to me that this might be an issue with Wordpress SEO (the wp_title filter issue).
Anyone got an idea on this?
Ok got this. The solution was to use the rewrite api, as mentioned above, to look for the pattern /vendors/, letting it know that it was a valid URL. Coupled with my existing template override, this is what I needed.
Lets say, I want an affiliate plugin that I bought for WP to work on Modx. What are the procedures to follow? Yes, you can assume that all the plugins I bought use php, javascript, and jquery.
You need to refactoring your plugin to modx snippets and chunks - http://www.cmslesstraveled.com/index/tutorials/refactoring-a-simple-php-application-for-modx.html
You can use internal Wordpress functions by including this file
include_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php' );
You can try including the file in one of your modx templates and then
see if it gives you access to your affiliate plugin functions.
Vice-Versa you could include modx into your wordpress theme files by
adding this code.
define('MODX_CORE_PATH', 'full/path/to/your/modx/core/');
define('MODX_CONFIG_KEY', 'config'); require_once MODX_CORE_PATH .
'model/modx/modx.class.php'; $modx= new modX();
$modx->initialize('mgr');
This will give you access to the $modx object and all it's wonders.
Source: http://www.quora.com/MODX-CMS/How-would-WordPress-plugins-need-to-be-recoded-in-order-to-work-in-MODX
I am working in worpress front page.
I want to add a plugin to the page at a specific location manually but adding the code to the page myself.
I basically want to include a plugin in a certain page on a certain location. So I'm create a div...
<div id="plugin-holder">
**Plugin-will-appear-here-with-this-code**
</div>
Don't anyone know how this is done please?
Thanks
If you're wanting a plugin to appear somewhere, you'll be looking for "shortcode" functionality.
This is actually surprisingly easy to code, check out the examples in the Codex under Shortcode API - ie:
function bartag_func( $atts ) {
// ... do more things here ...
return "text to replace shortcode";
}
add_shortcode( 'bartag', 'bartag_func' );
Once you've called these functions you can use [bartag] in code and it will run your function and replace the shortcode with the generated text your function returns.
If you're adding shortcode functionality to your site, it generally makes most sense to code a really simple plugin and put it in that. The reason why this works best is that, over time, it's really easy to forget and upgrade a theme by mistake (or even change to a new theme) and thus break your site by losing your custom code in your former functions.php. Surprisingly, this is pretty easy to achieve and only requires some specially formatted comments at the top of your plugin file and a little common sense in coding - there are many tutorials and "how to"s around!
Here's a useful shortcode tutorial: http://www.reallyeffective.co.uk/archives/2009/06/22/how-to-code-your-own-wordpress-shortcode-plugin-tutorial-part-1/
You should add the relevant plugin code to functions.php.
I suspect you'll want to use some conditional tags, like is_home() to pinpoint your location. But maybe not, depending on what you are trying to do,
Also, if you're trying to to insert from a pre-existing plug-in, make sure you remove the register_activation_hook or activate_pluginname action.
If your plugin supports a sidebar widget you can simply "widgitize" the div tag that you wish to insert the plugin into.. Google the term and you are gonna find many resources.
Some background if you want to see why I'm doing what I'm doing:
I have a client who wanted a new blog done with Wordpress on a separate subdomain. Their existing website is on Drupal, which I have had 0 experience with prior to this. They have a pretty extensive navigation on that site (multiple levels), so rather than create duplicates of nav menus that would need updated on both wordpress and drupal, I am using YQL to pull in the whole navigation onto the Wordpress website. I know this isn't great for SEO, but at this point I'm not worried about that.
The issue I have is that all of the links on the Drupal website do not include the http://domain.com so that none of the links work on the blog site, because they're going to relative pages on that subdomain that don't exist.
So in summary, what I'm trying to accomplish:
I need each href that Drupal is generating to begin with 'http://domain.com'. Currently they just start with '/pagename'. I have no clue what Drupal version the site is on nor on how to find it, sorry. The site is using Drupal's Nice Menu plugin as well. I've been digging through the files for a couple of hours now, and can't figure out where I need to make the change. Please help! Thanks
Edit: dobeerman mentioned using custom_url_rewrite_outbound to settings.php. This seems to accomplish close to what I want. I tried adding this to the end of settings.php:
function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
global $user;
$path = 'http://www.reillypainting.com/'.$path;
}
However, the end result of an href in the menu becomes this example:
href="/http%3A/%252Fwww.reillypainting.com/services/sell/rent-your-house"
So the other code generating Drupal's menu is trying to escape the :// and it's also still adding a / to the beginning of the href. Anyone know how to avoid this?
Drupal has function custom_url_rewrite_outbound you can add to settings.php
Use this code:
function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
$options['absolute'] = 1;
}
i created a Worpress 3 Multisite with 5 Sub-Blogs.
Is it possible to share the same Media-Library in this Blogs?
i changed upload_path in wp_1_options and wp_2_options for example and also in my backend in "Super Admins" Menu but it has no effect.
The files are uploaded to wp_contents/blogs.dir/1-2-3/files and the options have no effect.
any ideas? thanks!
One way around is to hook onto the load events of all media admin files, and switch to the main blog using switch_to_blog(1).
This would mean in any blog admin, the media library will always run as if it were on the main blog.
Note that a couple caveats include;
The media library for all blogs is stored in the main blog database table.
You may run into problems with inserting media into posts outside the main blog admin
You will run into problems with inserting galleries into posts outside the main blog admin
User permissions may be false positives or negatives
My best advice would be to use the code example below, and have a good play around with blog admins, logged in as different users, with different roles, and see what happens.
function use_main_blog_library()
{
switch_to_blog(1);
}
add_action('load-media-new.php', 'use_main_blog_library');
add_action('load-media-upload.php', 'use_main_blog_library');
add_action('load-media.php', 'use_main_blog_library');
add_action('load-upload.php', 'use_main_blog_library');
In my searching on this topic, several posts lead back to this one, so I figured I'd share an idea that might help someone wanting to develop a suitable plugin to solve this...
Use get_site_option() and update_site_option() to store global plugin options.
Add an option via hooks to choose if a media upload should be shared network-wide and let the plugin track which media files and where they're located at.
Again, using hooks, have the shared items show up in each blog's media library and perhaps add an indicator showing the file is a network share.
I have spent several hours playing with the administrator hooks and filters and this could be accomplished through them, although I'm not savvy enough to know how to fully integrate it with all of the media library features.
The Shiba Media Library Plugin could serve as a valuable reference since they have utilized several custom features for the Media Library via hooks and filters.
I really wish I had the spare time to work on this right now because I would take my best shot at it. I hope this helps someone else.
I have found a possible solution, which works for me in WP3.7.1 (I haven't tested it in earlier versions)
Create a filter, which overrides the default upload directories:
add_filter('upload_dir', 'ms_global_upload_dir');
function ms_global_upload_dir($uploads)
{
$ms_dir = '/sites/' . get_current_blog_id();
$uploads['path'] = str_replace($ms_dir, "", $uploads['path']);
$uploads['url'] = str_replace($ms_dir, "", $uploads['url']);
$uploads['basedir'] = str_replace($ms_dir, "", $uploads['basedir']);
$uploads['baseurl'] = str_replace($ms_dir, "", $uploads['baseurl']);
return $uploads;
}
Important: the 'Upload Url Path' settings should be empty in Site Settings or if you need to customize it, check the results by dumping the $uploads array to view possible conflicts.
To check if your version of WP supports this method, locate function wp_upload_dir() in file wp-includes/functions.php and find function call: $uploads = apply_filters( 'upload_dir' ...
If it presents, the solution above should work.
Hope, this helps ...
Additionally, I have spent almost two days to make a solution to replicate/delete the uploaded media in each of the blogs with action hooks 'add_attachment' and 'delete_attachment' by generating the necessary post and postmeta entries in the corresponding database tables. With this, you can add/delete media in any of the blogs, that will be visible in/removed from all blogs media library. If you are interested, I can share it...
Cheers