WordPress--post only latest 1 or 2 or 3 posts on homepage - wordpress

How do I just display the latest post on home (not the whole archive as wp does by default)?
And how can I influence that it has/not date, category, read more, etc?
WP manual does not explain this clearly. Or does it? If yes, please tell me where?
Thank you guys! And girls!

The new Wordpress Themes have child themes, it is a new way to organize and simplify upgrading themes, but it can be a pain because they are not as easy to modify as older themes. Anyway, there is the old way:
You can use the settings in the Administration Page to set your homepage to display only one post (Settings / Reading / Blog pages show at most -> 1 post). But if you want just your home to display one post, and decide you want your archives to display the basic 10 posts, you can edit your theme template to use this function:
<?php query_posts('posts_per_page=1'); ?>
Function Reference/query posts
http://codex.wordpress.org/Function_Reference/query_posts
To be sure no date or category is displayed, you also have to edit the template and remove the corresponding php code (in the loop, you should look for these functions:
<?php the_category(); ?>
<?php the_date(); ?>
Function Reference/the category
http://codex.wordpress.org/Function_Reference/the_category
Function Reference/the date
http://codex.wordpress.org/Function_Reference/the_date
To use the new way, you have to create a child theme to your theme, and override the loop by creating your own loop.
Chld Themes
http://codex.wordpress.org/Child_Themes

Related

Add Shortcode to All Post Types

I want to display shortcodes (I'm using fruitful Shortcode) above the post title tag (H1). And I want to display it to all my post (also as a template).
i want to be like this
Thanks.
If you want to adjust the way your single posts are displayed for all the posts, you have to edit the single.php file in your theme folder. You can do this in the backend under "Design" -> "Theme Editor" or you can access the folder and files via FTP.
For your default posts in wordpress you just need to open the single.php file and look for the h1 with your title. It can look something like:
<h1><?php the_title(); ?></h1>
Above that (if you want to display it above), you can put your shortcode with the do_shortcode() function:
<?php echo do_shortcode('[name_of_shortcode]'); ?>
If you are not using normal posts of wordpress but custom post types or something else, please have a look at the wordpress template hierarchy to find out, which file to edit or how to name the new files for creating template files: https://developer.wordpress.org/themes/basics/template-hierarchy/
If you are using a theme that is not made by you, you should make sure you keep your theme updateable. So if you overwrite the single.php, with the next update of your theme, the file will not have your edits. You need a child theme, if you want to keep your parent theme up to date but also customize it in the page templates. Here is a nice tutorial for child themes: https://www.smashingmagazine.com/2016/01/create-customize-wordpress-child-theme/

woocommerce theme development without shortcodes

I was wondering if someone could help me out. I am developing a theme that uses woocommerce as the ecommerce solution. I know that there are predefined shortcodes that you can use but i was wondering if there was a way to actually implement woocommerce items in my php code as opposed to using shortcodes.
Thanks,
Try this:
https://wordpress.stackexchange.com/a/125286/60175
<?php echo do_shortcode('[product_page id="31"]'); ?>
And at the Shortcodes doc, I see
To find the Product ID, go to the Product > Edit screen and look in the URL for the postid= as shown below.
http://docs.woothemes.com/document/woocommerce-shortcodes/
Of course this still uses shortcodes (pretty slick), but in your PHP. The Wordpress framework must be available in your PHP page, which I think you do by including wp-load.php at the beginning.

Using Jetpack Portfolio Project in WordPress child theme does not call archive custom template

I have a child theme that uses the new Jetpack Portfolio Project custom post type and wish to modify archive.php to display custom results.
I'm using: WordPress v3.9.2; Theme: Child of Point, Jetpack is installed with Custom Content Types enabled, and Portfolio Projects selected in the Settings. (No other plugins that implement portfolio functionality are installed.)
According to the Codex:
Template Files
In the same way single posts and their archives can be displayed using
the single.php and archive.php template files, respectively,
single posts of a custom post type will use single-{post_type}.php
and their archives will use archive-{post_type}.php
and if you don't have this post type archive page you can pass BLOG_URL?post_type={post_type}
where {post_type} is the $post_type argument of the
register_post_type() function.
My understanding is that if you create files called single-jetpack-portfolio.php and archive-jetpack-portfolio.php within the child theme, WordPress will automatically use those files in place of single.php and archive.php respectively.
However, my child theme successfully calls single-jetpack-portfolio.php, but completely ignores archive-jetpack-portfolio.php, instead calling archive.php in the child.
I am stuck for a solution.
From the codex above, adding to the URL "?post_type=jetpack-portfolio" does cause the child theme to correctly use archive-jetpack-portfolio.php, but should I need to be manually modifying every single URL to explicitly specify this? Should WordPress not automatically be detecting this, as it does for the single-jetpack-portfolio.php file? How can I solve this?
I have tried:
Resetting the permalinks in case it was related to that (changing the option in Settings and saving and back again)
Adding an archive.php file to the child in addition to archive-jetpack-portfolio.php (I initially didn't have an archive.php in the child, so it used the parent's archive.php)
Publishing a new Jetpack portfolio project and updating an existing page (I read somewhere that publishing something might trigger Wordpress to see the changes)
Thanks in advance for any help.
I had the same problem described by the OP. When I visited mydomain.com/portfolio it would use the custom archive template. When I tried to view a project type it defaulted to the regular archive.php. I'm wondering if OP was viewing a project type page without realizing it.
My solution was to create a taxonomy template file. After playing around with it I figured out that
taxonomy.php
taxonomy-jetpack-portfolio-type.php
taxonomy-jetpack-portfolio-type-{name-of-project-type}.php
all worked correctly, depending on how specific you wanted to get.
There's more info at the wordpress codex: http://codex.wordpress.org/Template_Hierarchy#Custom_Taxonomies_display
Hope this helps someone.
I will be working on this the next days.
You should try this in the child archive.php first lines:
<?php
if( is_post_type_archive('jetpack-portfolio') )
get_template_part('content', 'jetpack-portfolio');
elseif( is_tax('jetpack-portfolio-type') || is_tax('jetpack-portfolio-tag') )
get_template_part('archive', 'jetpack-portfolio');
else continue;
?>

How do I use different category template in wordpress?

I am using Twenty twelve theme in wordpress to make a project. To display various styles of pages I can choose custom page template page, but I have to use category instead of pages.
But how I make different category template and use them ? Thanks.
You can do it in almost exactly the same way as you would do with pages.
Just follow the Wordpress Template Hierarchy:
"category-slug.php"
"category-ID.php"
etc
http://codex.wordpress.org/Category_Templates
So, if you have a category with the name "cars", the name of template for that category should be "category-cars.php" :)
Edit: a few minutes too late :(
You can check category by id and use native function where it needed.
get_template_part( 'custom_category', 'category' );
Also You can try something from here Wordpress Codex

Wordpress - how to show just posts on main index

I have a Wordpress theme that I've been making 'my own' visually and can't seem to get the main content section to display regular posts only - instead of the boxes.
Does anyone know how I can change this without messing it up completely? I've tried stripping everything away and replacing with the 'display all posts loop' thing, but no go. I've tried adding a new page and setting that to show posts and such, but that didn't work either ... all it did was show the latest post.
Any ideas?
Thanks, Jennifer
It depends on what theme you are editing to make your own. If you were editing the default theme one way to do it would be to open index.php, define the template name with something like:
<?php
/*
Template Name: home
*/
?>
and then save it as home.php. In your admin Reading settings set that as your home page.
I am not sure what you mean by "boxes" but I assume you are not interested in the sidebar?
In this file there is one main loop running and it is set to retrieve only the latest post and a sidebar. It pulls in the title of that post : the_title(); the content : the_content(); and the sidebar get_sidebar();. What do you mean by "regular posts"? If you wanted the home page to pull a selection of latest posts you would create your own loop using WP_Query.. something like :
<?php $the_query = new WP_Query('cat=3&showposts=5');
while ($the_query->have_posts()) : $the_query->the_post();?>
Where you are interested in defining the category id (3) and the number of posts to show (5). You can read more on creating these kind of loops here
http://codex.wordpress.org/Template_Tags/query_posts
Good luck :)

Resources