I found this solution to getting the featured image to default below the post title.
wordpress add featured image below post title
Where do I place this php?
Will it work for all posts?
Please have a look at the wordpress template hierarchy in themes:
https://developer.wordpress.org/themes/basics/template-hierarchy/
You can edit the look of single post views inside the single.php, if using a custom post type single-{post-type}.php. If you are using a theme that is not made by yourself and might get updated, make sure to use a child theme, so your changes will not be overwritten when the parent theme is getting updated.
This is a nice tutorial for creating child themes in wordpress:
https://www.smashingmagazine.com/2016/01/create-customize-wordpress-child-theme/
In the template file you get the featured image with get_the_post_thumbnail() function and the post title with get_the_title() function.
Search for the lines in the code, where you can find the functions and change the location to your desired place. Or if there is no featured image, you can add the code you already found.
Where do I place this in php?
Inside of the single page template of your theme.
Will it work for all posts?
If you use the single.php file, yes. All posts use this template. But you can only apply the changes to specific post types as described above - if you like to. You can also make it work for some specific category terms with category-{term}.php or maybe you want to change the post listing in your archive.php. Please check the link above, Wordpress Template Hierarchy will make this clear, very easy to understand.
Hope this helps!
Related
I have custom posts that I want to be shown in a different template.
Right now I have custom posts on:
www.mywebsite.com/travel/post-name
All other (default) posts are on:
www.mywebsite.com/post-name
Basically, I'm trying to find a function.php code, that identifies URL and applies another template.
So, if path www.mywebsite.com/travel/post, then load post in traveltemplate.php
else, single.php
Any help would be appreciated.
P.S. this is not categories, so in_category category ID and category won't work.
I'm looking for a rough url identifier.
WordPress has a pretty sophisticated system to pick the “correct” template for specific pieces of content already, based on certain file naming patterns.
Check https://developer.wordpress.org/themes/template-files-section/custom-post-type-template-files/, it explains how that looks for custom post types.
single posts of a custom post type will use single-{post_type}.php
and their archives will use archive-{post_type}.php
I'm using different page-templates this for pages.
Now I need the same for posts.
Since 4.7 this should be a core functionality.
So I pretty much followed this quick tutorial and added a custom single-duplicate.php in my theme folder and added this code at the top:
<?php
/*
Template Name: Full-width layout
Template Post Type: post, page, product
*/
However upon creating a new post I dont see the "Post Attributes" Box with the Template-dropdown. What do I do now? Is it possible that my theme somehow prevents that?
Here's my themes functions.php as a gist, if that helps.
I think you are a bit confused as to what Page Attributes will give you access to. To the best of my knowledge, you do not get a drop down to choose a template (as you do on Pages) as an automatic function on posts/custom post types.
you need to create a single-{POSTTYPE}.php in your theme directory and need to add/follow the HTML structure of your page template.
For more information,
Custom Post Type page template doesn't show up
Post Template Files
Hope this will helps you.
I need to add my own custom PHP script to all Wordpress pages of my blog.
I am not referring to adding PHP onto a single page (which can be done with a plugin).
Essentially, this is what I need to do:
Add a snippet of code directly to Wordpress script that handles
display of posts.
The snippet needs to be able to grab a ID of the post.
Can someone show me the best way to do this?
This is what I need to figure out:
Which of the Wordpress php files handles the display of the Wordpress
posts (is it post-template.php by any chance?)
How to grab the Post ID using PHP? I found the page which says this could be the possible way, is that correct way of getting the Post ID?
$id = get_the_ID();
for single post, it single.php and to get post ID
$post = get_post();
$id = $post->ID;
It depends on the theme. Very simple themes might use index.php for all pages, others use single.php for the display of single posts, and there are a lot more possibiites, also secondary templates (template parts) which are included in the primary templates and contain part of the post. Have a look in the theme folder.
Inside all of these, the posts are always inside "the loop". This page has the explanation and some useful examples: https://codex.wordpress.org/the_loop
HTH
I have created a custom theme and I want to customize my posts to a grid format but I cannot find the files that control the posts. Also I have searched for all things related to posts in my style sheet and deleted them to see if this would affect my posts but it did not. Which files do I edit to change the style of my posts?
The list of post get by default in page.php or you can create custom template for get list of post.
The detailed view of post will get by default in single.php.
REF : https://codex.wordpress.org/Template_Tags/get_posts
https://premium.wpmudev.org/blog/creating-a-customizable-post-list-template-with-advanced-custom-fields/?imob=b&utm_expid=3606929-106.UePdqd0XSL687behGg-9FA.1&utm_referrer=https%3A%2F%2Fwww.google.co.in%2F
I am having issue with a custom category template. I want to create a new template for my specific category "VIDEOS" so that all posts under this category show in new style. Basically, i want to show posts with videos in a new way as 3 posts in one row with featured images and a featured slider on top of that page showing 4 new posts of that category ?
But i am confused... Can i do this in wordpress ? Because my home page also has a featured slider. Can i create a new slider for that page template but one thing is sure. I need to work with only one category for that custom template i.e. videos.........
Just create category-[id].php & you will be ready to use that. Wordpress will automatically load that file for that ID of category.
You can also do same task via slug like category-files.php etc as well
Yes, certainly possible with WordPress.
Find the slug or the category id. Your slug for the category may be videos. So create a custom template named category-videos.php. This template will be used for the category archive VIDEOS.
If you know the category id, you can create template named category-<category_id>.php.
For other people landing on this page and wondering what to do when they go to their theme's folder and don't find a file called "category.php", what you need is to find the next file in the hierarchy, copy it, and rename it category-[slug or id].php (this should be archive.php, followed by index.php).
For a listing of the category hierarchy, see the official documentation: http://codex.wordpress.org/Category_Templates