so i need to create a custom single post page in wordpress according to a client's specification on a mock up of the page. It's gotten quite difficult trying to customize the single post page of the theme i'm currently using. What can i do to make the single post page look exactly like the one in the mock up because both look way different from each other. This is the mock up of the proposed page
You have to options either you can goto child theme and customize your post template single.php or like example (themes\twentyseventeen\single.php)(themes\twentyseventeen\template-parts\post\content.php) and apply your design there or you can create new template for single post.
New template
<?php
/*
* Template Name: New Template
* Template Post Type: post
*/
get_header(); ?>
// your html design and content of post
// along with the post loop
<?php get_footer(); ?>
Related
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.
I need to apply the same content on over 4000 Wordpress pages. Now to make it as easy as possible. I create a single page and designed it with the content. So what I want to do now is create a template out of this page. Is there any possibility to export the page as php code to put it in the theme as a template?
(It hast to be the exact content as the template file)
I am also open-minded for other Ideas to solve this problem. Thanks a lot!
Yes, you can create a template and apply your template to your pages.
With the content that you wish to apply to your pages, create a .php file. At the top of this.php (called say page-mycontent.php) file add this header:
<?php
/* Template Name: My Template */
?>
Now the template will appear in the admin panel for Page - Edit on the right hand side.
Code Changes in header.php and page.php
Your changes are in both the header and the loop. So I suggest creating two templates, one for the header and one for the body.
In your header.php, if you name your header code as header-myheader.php then pull your new header template into header.php like so:
<?php get_header('myheader'); ?>
And similarly add your body code (called mytemplate.php say) into page.php like so:
<?php get_template_part('mytemplate'); ?>
I have a custom post type, "Store Pages" for instance, which is an almost identical duplicate of the default Wordpress "Page" post type.
Like the "page" post type, I would like to create page templates (not post-type templates) and be able to select them from the "Template" drop-down within the "Page attributes" box in the page editor.
I have created several templates, but the drop-down menu does not appear; I am assuming this is because a custom post types does not allow support for this.
Is there a way I can create page templates for a custom post type without using "single-{post-type-name}.php" and having a dozen queries to load up different template files?
I have double checked the comments for the templates are correct as they appear when I create a new page (post type, "Page").
Help would be greatly appreciated.
starting 4.7 you can use the new feature described here https://make.wordpress.org/core/2016/11/03/post-type-templates-in-4-7/
<?php
/*
Template Name: Full-width layout
Template Post Type: post, page, product
*/
// … your code here
If I understood correctly you want a Select template dropdown for your custom post type.
You can do this easily through Advanced Custom Fields, here's a quick guide how to get through.
After installing the plugin you can access the Custom Field section, if you open it and click Add new it bring you to the field editor. Name it whatever you want, it's just for administrative display.
On Field type choose "Select", this will allow you to construct a select box on your backend, keep in mind the value of "Field name" you will need this later on the code.
Scrolling down you can add the values of the select box in the following format: "key value : Textual label" just assume for now you want 2 templates, one for audio posts and one for video posts.
If you keep scrolling down you can see the display rule for this field group, now you will have "post" and "page" by default, when you add different content types you will have the additional content types here to select, just go ahead and pick yours.
And, ta-da. If you go on the custom content type edit window you will find your new fresh select box here waiting for you.
The code integration now is very simple, just go onto your single-{post-type-name}.php template and pull the custom field data into your loop. Then you can use this to use get_template_part() to pull your custom templates.
<?php $template_type = get_field('template'); // This must match with the field name value ?>
<?php if (isset($template_type) && !empty($template_type)): ?>
<?php get_template_part( 'store', $template_type ); ?>
<?php else: ?>
// You should have a fallback for the all the existing posts without template set or if you create a new post without a template.
<?php endif; ?>
In this specific example the pulled template files will be in the format of store-{key-value-of-the-selectbox}.php, of course you can readapt that for you best convenience.
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.
I have generated pages using a custom template by creating a php file in
/wp-content/themes
something like :
<?php
*
* Template Name: Contact Page
*/
?>
<html ..... </html>
and then adding a new page on the dashboard selecting this new template
The problem is i cannot associate tags and categories to each pages.
i would need apparently instead to create posts.
How could i then create posts from a custom html file ?
Use custom post types and create a single-{posttype}.php
I think this will solve your problem.
Custom post types are exactly what you need. Essentially, they're custom content containers and an extensible version of default posts. They can be associated with tags and categories just like normal posts can.
You can find implementation instructions here. :)