I commonly run into a scenario where “the powers that be” want an exact copy of a page in multiple places on a website. Rather than actually duplicate the content, all I do is override the section in the nav that is highlighted, and then include the page. The final page looks something like this:
<?php
$top_nav_item_id = 'teen';
include('../interests/teacher-resources.php');
?>
This typically works. I am trying to duplicate this for a blog category, done in wordpress. All I seem to get is a blank page, no matter what I do. I’ve tried all of the following lines:
<?php
include('../blog/index.php');
include('../blog/type/teen/index.php');
include('../blog/type/teen/');
include('../blog/');
?>
Does anyone have any ideas? Is this a URL rewriting thing? Do I have to include the template file for that particular category?
Any help is appreciated.
PHP
include
expects files, not URLs, so it doesn’t have access to the URL namespace exposed by WordPress. Those files don’t exist on-disk; mod_rewrite first turns the pretty URLs into an internal request toindex.php
, WordPress figures out what you really wanted based on the original URL, fetches a bunch of stuff from the database, then produces the page.This is a pretty complicated topic, and one that isn’t very apparent from the start. This page should help you get started. The key is to include the WordPress blog header – explained on the linked page. You’ll probably also want to check out the WordPress Codex for resources on using the WordPress engine’s API.
No idea what’s going wrong, but it does. Maybe WordPress can’t find it’s environment, maybe some variables are being overrided… Actually it’s a bad idea to include solutions like wordpress, because you never know, what global variables, functions, classes will intersect.
PS: And, by the way, include uses file system paths but not URLs.
For similar issues I use iframes to include the copy of the content. You can write the original page to look for an “?embed=1” flag in the url, and only include the embeddable content in the main page when the embed flag is present (so you can leave out toolbars and frames that would be redundant.) So the iframe src url would use the ?embed=1 tag to embed the content.
This solution is a bit of a hack, but then, the problem is a bit of a hack to begin with.
I received a good explanation of why I couldn’t include the blog page, but not any alternatives that would work for me.
My final solution was to modify the category template for that page directly. As stated originally, I use $top_nav_item_id to control which menu item is highlighted in the nav, to give the appearance of the page belonging to that section. Rather than override this, I simply made it conditional on a query string. As long as the user is following legit links on my site, they will get the correct query string and have no problems.
$_POST is disabled in WordPress. $query_string (built into WP) uses some sort of caching, and would always display as it was first loaded.
Final solution:
Thanks to all who tried to help.