In WordPress how to add post to custom pages: - wordpress

I am new to WordPress.
suppose i have made pages as follows
home, news, about us
now if i want to create post for news page only
news1,
news2
then posting new post how could i set this settings?

You can create page templates.
Create one for all your pages.
Then, change the template of the page of news to the news template.
In that PHP file now you can do whatever.
For example, for news.php
<?php
/*
Template Name: My Custom Page
*/
//Here comes your PHP code, where create a $WP_Query(); and loop troough on that.

Related

Use custom templates in posts (not pages)

Is there a way to allow the user to select a template for a post in the same way you can select one for a page?
I could create a new post type and create a single.php file for that type, but there are several templates to add I it would mean when I am pulling in posts, I would have to add those post types to the feed throughout the site, so I would like to avoid it if possible.
Sure, you can use the same process as for page templates by creating your single file with this header at the top of the file:
<?php
/*
* Template Name: Featured Article
* Template Post Type: post, page, product
*/
get_header(); ?>
Then on the dashboard, you will be able to select the template for your post.

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).

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

Different templates for Posts in WordPress

I have a created a custom WordPress Theme.
All the Posts have a different layout and Pages have a different layout.
By default for Posts wordpress uses index.php and content.php
By default for Pages wordpress uses page.php and content-page.php
I have created two different posts.
What I want to know is how to display one post in the page template layout and the other post in post template layout?
Is this possible?
Please help.
Yest this is possible by using a Plugin named - Custom post template.
Here is the link to the plugin: http://wordpress.org/plugins/custom-post-template/
No,It is not possible to do.Different Posts is a normal post type called posts.And pages are called Page.
So you can not mess up with pages and posts.Please see wordpress codex templates
http://codex.wordpress.org/Templates
In your template you create a template called template-post.php and template-page.php
At the beginning of the file you need to use
<?php
/**
* Template Name: Page Builder
* Template Post Type: post, page
* #package WordPress
*/
Please note the Template Post Type: post, page.
Now the templates are available for both posts and pages.

How to create multiple custom pages in wordpress?

I am designing a website in wordpress. I have 1 custom home page & another are single themed pages. Now I want to add some more landing pages with different design. How can I get this?
create new php file in your theme directory, add this on the top of your php file:
<?php
/*
Template Name: your template name
*/
?>
use the template by choosing page templates on post option.

Resources