Remove Header from Custom Template - php

I am using a custom template named "full_width" which I downloaded from this tutorial/blog post: https://www.wpbasics.org/advanced-custom-fields-custom-front-page/
In this link you will find both, the php and css code.
Everything works fine but the fact that I cannot remove the main header (what I called Header "1" in the picture below).
here you can see what I refer to when I write Header "1"
I want to remove the Header 1 because I already have a second header (header 2 of the picture), which was already built in my website from my developer.
I thought was enough to replace the get_header() line at the end of the php code with the one which recalls my header "2". However it does not work.
At the moment, I changed the last part of the template code, by simply adding a new line (the second one) as follow:
get_header();
get_template_part('parts/header'); the_post();
do_action('full_width_content');
get_footer();
Obviously it will show the both headers. In fact, this is how the page currently looks like.
If I delete the "get_header()" line, the layout of the page will turn like this (a mess)
Can someone guide me to a solution. Let me clarify that I know nothing about coding, nor PHP, neither CSS. I am not a developer. Therefore I would need a ready to go solution which I simply need to copy and paste into my website.

could it be as easy a
get_template_part('parts/header'); the_post();
do_action('full_width_content');
get_footer();

Related

Change header on specific page wordpress?

I want to change my header (all header : logo + menu) on specific pages of my wordpress.
EDIT : I didn't precise something important, in my mind, I woudl like to change the header on specific page AND tagged post.
Example : header test on page id 4, and post 3,4 & 5 wich are tag "test".
How can I manage that easily ?
I tried some plugins without success :
WP Display Header
Page Specific Menu Items
Menu Swapper
I have the idea to change it with an if statement, but I'm worried about maintaining this code in time (I'm thinking about WordPress or Theme updates).
Have you already do that ?
Thanks a lot,
<?php if(is_page(<page id>)) { ?>
--------- Header 1 -----
<?php } else { ?>
--------- Header 2 --------
<?php } ?>
Add this code according to your header sections in header.php of your theme.
When you use get_header() an optional parameter is the name of the header, you can see this in:
https://developer.wordpress.org/reference/functions/get_header/
You need to create, for instance, header-another.php and put the code in it, after this only need calls get_header('another').
Probabilly you need to create a custom template for the page that has a different header and call get_header('another') instead get_header() in it.
There are some bullet points you have to know about using different on different page.
first if you want to use different headers on different pages for example you want header(one) on productOne-page.php and header(two) on productTwo.php file.
For this First you have to create two header files namely header-one.php and header-two.php.
now when you call header(one) in your productOne-page.php file you call it like:- get_header('one');
and when you call header(two) in your productTwo-page.php file you call it like:- get_header('two');
and at last if you need to call default header in any file you can call just get_header();
summery: just call different header with their name after hyphen(-) in file name i.e. get_header('Custom Header Name');
I hope it will help you.:)
I'm using the plugin Page Menu (by Rohit Kumar) to change the menu and the Haninder Singh solution to change the header and it work perfect.

How can I include / exclude a part of an included PHP file based on the file I am including it in?

The title is a bit convoluted. Let me explain better.
I'm making a blog where registered users can delete and edit their posts. The posts are displayed on 2 sites - the main page, and an admin control panel page. The code for generating the posts is in a separate file.
On the title page, everyone should only be able to see the posts. On the admin page, registered users can edit / delete their posts using the same included php file. There is one function smack in the middle of the code that determines if the editing buttons are visible. I want that function to be present when the file is included on the admin page, and not be present when it is included on the main page.
Let's say that the file which is included, blogposts.php looks something like this:
<?php
code
function();
rest of code
?>
What can i do to exclude that function in the instance where I don't need it?
I've also tried deleting the function and writing:
<?php
require "blogposts.php";
function();
?>
That executes it only on the last post, but should execute it on all of them since it is part of a while loop in the original code.
So, other than writing the code twice, once with and once without the function, if you guys have any ideas I'd appreciate it,
You could place the function inside an if statement, and check the current page against $_SERVER['REQUEST_URI'].
Something like:
if($_SERVER['REQUEST_URI'] == '/current_page_uri.php')
{
function();
}
And then replace the '/current_page_uri.php' with the URI for your admin page.

Drupal variables in region templates

I'm doing my first totally custom Drupal 7 theme. I have the page.tpl.php file working fine and have header and footer regions working, until I move this:
<?php print render($page['main_menu']); ?>
into region--header.tpl.php - the menu is no longer generated - the html around the PHP is generated - nav etc. so I know drupal's reading the template file OK.
The same code works fine if it is in page.tpl.php
Any help greatly appreciated.
Main menu available as block. So you can just put him to this region. It's good practice.
Also don't forget to clear drupal/browser cache.
If you define custom variable in preprocess_page() or any other preprocess functions you shouldn't use render function, just use print $main_menu for example.
Also try check this

How to make a template overwrite for mod_menu with alternative layouts for link outputs?

I understand and love template overwrites. I need to do some heavier changes to the menu output (basically making the output work better with Bootstrap) - but only for certain menus.
Currently in Joomla 3 there are the following in the mod_menu/tmpl folder:
default.php
default_component.php
default_heading.php
default_separator.php
default_url.php
If I want to change the classes I'd copy the default.php into my mytemplate/html/mod_menu and change it. Great, no problem.
If I want to change the link outputs to go along with that I can copy the default_component.php to mytemplate/html/mod_menu and change it. Great, no problem.
If I want to have the choice of having a different "Alternative Layout" I'd rename the mytemplate/html/mod_menu/default.php to newlayout.php, then select it in the admin module manager for that menu. Great, no problem.
Here's the problem: If I want to have the link output changed for certain menus but not all of them I figure I'd change default_component.php to newlayout_component.php like I did above which would correspond to the newlayout.php...but that doesn't work.
Questions:
1) How to have alternative layouts for each of the default_component.php, default_heading.php, default_separator.php, default_url.php template files (not just an overwrite)?
2) I would think default_url.php is the one that would affect the link outputs but it seems it's default_component.php that does. So what does each one of those do? I couldn't find any information on joomla.org about that.
Thanks!
The alternative layout feature only works for the main file (default.php), not for the sublayouts (default_component.php, ...). So you have to create your own newlayout.php which then can load newlayout_component.php, or use the default_component.php. In fact, the default_component.php will be used as fallback if no newlayout_component.php is found.
The code switches over the $item->type of the link. 'separator', 'url', 'component' and 'heading' are handled by the 'default_'.$item->type, everything else will use default_url. So a plain URL should indeed be generated by default_url.php, not default_component.php. If it behaves differently, it's likely a bug.

Wordpress calling an HTML file from PHP

I am trying to modify a theme on wordpress. The theme shows a slider on the front page, which reads from the featured.php file.
I have gone into the featured.php and removed all the PHP code. I can inject my custom HTML into the featured.php and the pages display properly, however I want the page to display from a wordpress page.
So i tried to:
<?php
$html = file_get_contents('http://www.mydomain.com/homepage-featured');
?>
The above link corresponds to a page i created in wordpress. So i want to be able to inject my HTML into that page and then when you load my homepage, the PHP tells the browser to display the contents of this URL.
The above code doesn't work.
Thanks for the help.
file_get_contents() - as its name suggests - reads a file in but does not print it. You need to echo your $html variable. A better way is to use require() or include() but if I were you I would put my custom file on the same server so that way you don't have to use the file from a remote location thus sparing network traffic.
I think you have better to use the include function.
The file_get_contents you are using would generate an HTTP request, so it would make your script slower. I think it would be a good idea to put the HTML file on the same server if possible.
Have you tried
<?php
require('http://www.mydomain.com/homepage-featured');
?>
If my understanding is correct, you are trying to use a template (featured.php) for a different page other than the front page.
To do so, just change the Page Template of the page(the separate page which is # www.url.com/myhomepage). You can change this # Dashboard > Pages (Click Edit link in the required page) > Edit Page > Page Attributes meta box (available in the rightside below Publish) > Template. Change the template of this page to "Featured".
(I assume that your code in file feature.php has Template Name: Featured at the top)

Categories