How to change the custom header for posts page (Wordpress Childtheme) - wordpress

I have created a custom page template for my wordpress theme that uses a custom header-file:
get_header('custom');
Everything works as expected, but when I set a page to be the Posts-Page somehow the standard header-file gets loaded instead (my custom page template is activated).
I have also tried to override the blog.php from the parent and added the explicit call to my custom header-file, but it didn't have any effect.
What am I doing wrong? How does this work?

You should override home.php
A bit more information home.php is the template used for the blog homepage (the page with all blogposts). You can learn more about which templates are being used where in the template hierarchy documentation: http://codex.wordpress.org/Template_Hierarchy

The solution was to override home.php.

Related

Custom post type: creating a page template with the same slug

I'm currently working on a custom post type and want to be able to edit the archive page from Wordpress with a page template. So I created the CPT called 'cars' and created a page template with template name: 'Cars overview'. Next i create a page inside WordPress and choose the template page 'Cars overview' and gave it the URL: mywebsite.com/cars/
Now the problem is that the slug 'mywebsite.com/cars/' is already in use by the custom post type itself causing the page to load the custom post type loop instead of the page template loop. So I can't edit the title, content etc inside WordPress. I could change the url of the page, but i want to be able to control the overview page in WordPress.
Long story short: How can I create a page template that is using the same URL as the custom post type archive page?
Thanks in advance!
One simple solution, simply disable the archive where you create your custom post type:
register_post_type("cars", array("has_archive" => false));
Another approach rather then disabling the archiving and adding another page to show the cars. Changing the archive template used by your theme might be a better option.
First step is to find the template currently in use by your theme, copy it to your plugin file and you can change the template file to whatever you like. You can find more information about it here.
The only thing you need to do is point WordPress to the right direction:
add_filter("archive_template", "archive_template");
function archive_template($archive_template) {
global $post;
if ($post->post_type == "cars")
{
$archive_template = "path/to/your/template.php";
}
return $archive_template;
}
Disabling the archive and creating one manually seems a bit strange to me. And I always replace the archive page and sometimes single page from our theme (usually the7).

Can't seem to import bootstrap into wordpress

I am trying to import a page I made in bootstrap into Wordpress and I can't seem to figure it out.
I would like someone to give me some hands-on support if they have the time. I get different results with different attempts.
I changed my index.html to home.php and suddenly the entire site goes down. Restored it again and did something else and then the site showed up without its CSS. i understood i had to create a functions.php file where i call the stylesheets but im not getting any further.
What do i need to do to succesfully import a bootstrap page as theme in wordpress?
You need to create a WP theme, or just a WP page template (in case of just one page.)
https://developer.wordpress.org/themes/template-files-section/page-template-files/
In your current theme, if you have page.php , duplicate it by saying e.g. page-custom.php
In the template header section name the template:
<?php /* Template Name: Example Template */ ?>
Below it add your bootstrap page's code, you may need to fix paths to css/js files but I am sure you will figure that out by googling.
Once you have that page as WP template. Now create a page in WordPress to which you want to apply that bootstrap template.. and in the page edit sidebar, there is section you can select that custom template you created.
see this photo:
https://developer.wordpress.org/files/2014/10/basics-page-templates-03.png
Now if you will visit the page on the front-end , that page will have bootstrap design applied from your custom template.

creating wordpress custom php page

I'm trying my make my first theme for wordpress.
Is there any possibility to create custom php page to display custom content?
Pretty much adding to WordPress another copy of the likes of single.php, post.php or 404.php.
All I want just a page to display the custom content on it.
Every tutorial I found so far uses just creating new page within WordPress.
I want to avoid it and for custom page to be enabled straight after theme activation.
The Idea is to have something like my_custom_page.php and to be able link to it after.
Is there any way of doing it?
Thanks
here is the solution to what I was looking for
http://kovshenin.com/2014/static-templates/
To achieve custom page functionality you can use page template concept of wordpress. Creating a page template is extremely easy. Create any new file in your theme and start the file with a comment block like so:
<?php
/*
Template Name: My Awesome Custom Page
*/
<h1>Hello There</h1>
You need paste php code inside this template file. When you submit for then redirection action will be page with custom template page.
Referance :
https://premium.wpmudev.org/blog/creating-custom-page-templates-in-wordpress/
Video :
https://youtu.be/1ZdHI8HuboA

How do I create and link Pages in Wordpress? (not the Pages that can be created inside the Wordpress Admin)

I would like to create a fully functional page within my WordPress application (which will have jQuery and other stuff). The problem is that when I create a file within my theme/starkers (I'm using the Starkers Theme) directory let say about.php the following links (in my index.php) don't work:
<li>About</li> <-- Fatal error: Call to undefined function get_header()
<li>About</li> <-- site not found
What's the best way of doing this becasue I think I can't add PHP and jQuery and other complex stuff inside the Pages that can be created in Wordpress Admin.
Any suggestions?
What's the best way of doing this becasue I think I can't add PHP and jQuery and other complex stuff inside the Pages that can be created in Wordpress Admin.
Why not? Just make a custom page template inside your theme, create a new page on your wp-admin, and assign that custom page template for your page. You should be able to customize that as much as you want.
Try a scan here : Wordpress Template Hierarchy : Pages
Try loading
require( '/path/to/your/wordpress/wp-load.php' );

Wordpress themeing

I am relatively new to wordpress, I am creating a custom theme, and so far it is going ok.
I currently have index.php, header.php, footer.php and sidebar.php.
I have now hit a bit that has been puzzling me for a couple of days.
My home page has a slightly different layout to other pages, how do I theme for that change?
My website is essentially made up, of 'static' pages and 2 posts pages, what can I do so that the homepage looks different to the other pages?
Create a page template called home.php. WordPress will use it automatically for the start page.
Example:
<?php
/**
* Template Name: Home
*/
get_header();
// Do your regular page.php stuff
get_footer();
See also the codex page an Conditional Tags.
Go into your dashboard, settings>reading, check what the setting is for your home page display. You may need to change it from the default "list of latest posts" to a static page of your choosing.
You need a front-page.php
Please see the template hierarchy
You need to use the built-in functions from wordpress such as is_home() and is_front_page().
Conditional Tags
If you have a front-page.php that will take precedence over home.php or page.php. Whether or not home.php or page.php are defaulted to (assuming you have both) can be controlled in Settings → Reading. If you do not have a front-page.php, home.php, or page.php, then index.php would be defaulted to.
One difference between home.php and front-page.php is that home.php defaults to being a blog index page. Though both home and front-page may be used to display static or blog index pages.
More info may be found Wordpress' Template Heirarchy page.

Resources