Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Wednesday, March 9, 2016

Why Can't I Include A Blog?

Why Can't I Include A Blog?


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:

  

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:

  

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.

Answer by Hooray Im Helping for Why Can't I Include A Blog?


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.

Answer by Steve Madsen for Why Can't I Include A Blog?


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 to index.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.

Answer by Jet for Why Can't I Include A Blog?


ini_set('display_errors', true);  error_reporting(E_ALL);  

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.

Answer by MikeN for Why Can't I Include A Blog?


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.

Answer by Cory Dee for Why Can't I Include A Blog?


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:

if(strtolower($_SERVER['QUERY_STRING'])=='display=teen') {  	$top_nav_item_id = 'teen';  } else {  	$top_nav_item_id = 'programs';  }  

Thanks to all who tried to help.


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.