Wordpress PHP Include - wordpress

EDIT SOLVED The code <?php ob_start(); ?> put before any other output seemed to solve the problem.
I have a problem with errors appearing on a page on my site.
I am including 3 php files before any HTML output which is.
<?php
include_once("rpw_includes/dtd_site_root.php");
include_once("rpw_includes/dtd_remote_module_classes.php");
include_once("rpw_includes/rpw_remote_module_classes.php");
?>
<!DOCTYPE html>
<head>
That code is in my header.php file and all works fine on my index file but when i go onto another page which also calls the same header file i get these errors.
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\barnet\wp-content\themes\barnet\search-results.php:7) in C:\xampp\htdocs\barnet\wp-content\themes\barnet\rpw_includes\dtd_remote_module_classes.php on line 15
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\barnet\wp-content\themes\barnet\search-results.php:7) in C:\xampp\htdocs\barnet\wp-content\themes\barnet\rpw_includes\dtd_remote_module_classes.php on line 16
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\barnet\wp-content\themes\barnet\search-results.php:7) in C:\xampp\htdocs\barnet\wp-content\themes\barnet\rpw_includes\dtd_remote_module_classes.php on line 17
Any ideas?
EDIT*
search-results.php
<?php
/*
Template Name: Search Results
*/
?>
<?php ob_start(); ?>
<?php get_header(); ?>
<div id="page-search-hold">
<Div id="page-search"></div>
</div>
<?php
$module_obj= new RPW_results_obj();
$module_obj->write_html();
?>
<?php get_footer(); ?>
With the ob_start(); added the errors dissapear but i get about a 20px margin before my body starts like there should be erros but they are just not showing?

Make sure that the other page that includes header.php has the include as the very first line.

Related

What is the url for page-test.php?

I create a file page-test.php in my template directory.
page-test.php
<?php echo "Hello"; ?>
What is the url for this page?
But it's not working...
i want to find the url for display the php file "page-test.php"
You can put this line to create the page template in WordPress
<?php /* Template Name: Example Template */ ?>
and then write your code in this PHP file
<?php echo "Hello"; ?>
After that, assign this page template to the admin area,
Reference: https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-custom-page-templates-for-global-use
I hope it might be helpful to you!

template management with wordpress (underscore boilerplate)

I am using underscore to develop a wordpress theme.
I have a custom post type name project, thus I have, for instance, this url: http://a.site.local/projects/a-beauty/.
I have in my template-parts/ directory the file content-projects.
$ cat template-parts/content-projects.php
<h1>Project</h1>
When I browse http://a.site.local/projects/a-beauty/, I have my title but also the sidebar and the footer (even if they do not appear in my content-project.php nor in index.php).
Where are those widgets coming from / loaded ?
Add conditions to the header, footer and sidebar.
For whole custom post archive:
<?php if( !is_post_type_archive( 'project' ) ) : ?>
// wrap the code you don't want to show on that archive
<?php endif; ?>
For custom post only:
<?php if( !is_singular( 'project' ) ) : ?>
// wrap the code you don't want to show on the post
<?php endif; ?>
If you want to put the code you WANT to show, remove the '!' before condition.
P.S.
You can put the whole content in a condition, but keep the
</div><!-- #page -->
<?php wp_footer(); ?>
</body>
</html>
otherwise the page will break :)
Please share some more code from your project so we can easy to understand the real problem.

Different header template for cms pages

I would like to use two different header templates for a website. One for the home page and in other cms pages the layout will be different. Can anyone please help me out with it?
There are two ways:
1-
<?php if (is_front_page()): ?>
home header codes
<?php endif; ?>
other pages header codes
2- You should have two header files like: header.php & header-home.php :
<?php
if (is_front_page()){
get_header('home');
}
else {
get_header();
}
?>

Call to undefined function gcb() In wordpress

Fatal error: Call to undefined function gcb() in D:\wamp\www\isee\wp-content\themes\isee\home.php on line 10
and this is my Code
*/
get_header();
echo homeslider_function(); ?>
<article id="first-article"><?php echo gcb(1);?></article>
<article id="second-article"><?php echo gcb(2);?></article>
Line No 10 is gcb(1)
It looks like you need to install the Global Code Blocks plugin.
From the FAQ page:
Can I use content blocks outside of posts and pages?
Yes, just wrap it in the PHP function <?php echo gcb(x);?> where x is the content block ID. You can also use the longer form <?php do_shortcode("[contentblock id=x]");?>

Adding a static text on top of view when it is not filtered

I want to add a static text (some sort of explanation/welcome text) on the very top of a view (over the filter) in Drupal 6.x with Views "2". I want this text appear only when the view is not filtered (i.e. on initial load of the page).
My problem is that the only place I figure out to make it work partially is in the views-exposed-form--MYVIEW.tpl.php. The problem is that when I place the code in this template, I don't know if the view is filtered or not, so the text appear on every single page! I don't have access to this info in that template so the only place this is available ($rows or $empty variables for example) is in views-view--MYVIEW.tpl.php.
But there I got an another problem. The order in witch it seams the variables are output are not the same as the order in witch they appeared in the file. For example, the $exposed variable content is render always on top, then $admin_links, $header and so forth.
<?php if ($header): ?>
<div class="view-header">
<?php print $header; ?>
</div>
<?php endif; ?>
<?php if (!$rows): ?>
<h3>This static text appear AFTER $exposed !!!</h3>
<?php endif; ?>
<?php if ($exposed): ?>
<div class="view-filters">
<?php print $exposed; ?>
</div>
<?php endif; ?>
<?php if ($attachment_before): ?>
<div class="attachment attachment-before">
<?php print $attachment_before; ?>
</div>
<?php endif; ?>
So even if I place my static content before this code, the filter form always appear on top!
I found the reason why is doing this: the exposed filter form is rendered as a part of the content-top <div></div>, but not the result (and $header, $footer, etc).
So is this by design? Do I miss something? How can I get my static text on the very top of the content-top!?
Well, after some tweaking and lecture on preprocess function in the theming system, I found a solution to my problem. I share it with you and if you find a more elegante approach; let me know!
What I did is this...
1) In the template.php file of the theme, I add two fonctions:
function YOURTHEME_preprocess_views_view__MYVIEW(&$variables) {
if ($variables['rows'] || $variables['empty']) {
$GLOBALS['dont_show_static_text'] = TRUE;
}
}
function YOURTHEME_preprocess_views_exposed_form__MYVIEW(&$variables) {
if ($GLOBALS['dont_show_static_text']) {
$variables['custom_flag1'] = TRUE;
}
}
So, if my views is showing some results ($row) or a blank result ($empty), then I set a flag to be use in the template file....
2) In my views-exposed-form--MYVIEW.tpl.php
...
<?php if (!$custom_flag1): ?>
<h2>Some static text here</h2>
<?php endif; ?>
...
And voilĂ ! My static text is showing up only on the initial load of the view and it shows on TOP of the filter (not under!).
Hope this help someone else!

Resources