>> Iβve copied the content of the wp-content/themes/twentyseventeen folder into the wp-content/themes/twentyseventeen-child <<
That’s not what you should do. Only copy over files you need to modify. DO NOT COPY OVER style.css or functions.php.
If you want an example of a 2017 child, see https://github.com/sterndata/sds_2017
Adding to what Steven said, if there are theme functions that you wish to alter, first see if there is a filter or action hook you can use to alter behavior. If you do need to copy over a function’s declaration in order to change it, unless the function declaration is wrapped in if ( ! function_exists( 'function_name' )): logic (making it “pluggable”), you must give the function a new name and alter whatever code calls that function. You can only use the same name with pluggable functions, in which case your declaration should also use the if ( ! function_exists( 'function_name' )): logic or you’ll have trouble activating your child theme. Once activated, your version will take precedence.
Thread Starter
Ilse
(@directionsud)
Thank you the both of you. I’ve never done anything with PHP (or coding in general) so I’ll try to keep that Pandora’s box lid as closed as possible π but open to learning!
Basically, I’m just looking for a way to create a child theme to be able to show only the excerpt of my blog posts on my blog page instead of showing all my blog posts in full length. The excerpt field in the blog itself doesn’t seem to do the trick (I understood not showing excerpts is a default 2017 setting).
Full text vs. excerpt behavior is one of the more confusing aspects of WP. There are a few options for you to choose from, but behavior is also influenced by your theme. If your theme forces full text and you don’t want to manually insert <!–more–> tags, adding a child theme with an edited index.php is a viable solution.
Thread Starter
Ilse
(@directionsud)
I’ve managed to set up a working 2017 child theme. Then replaced:
get_template_part( 'template-parts/post/content', get_post_format() );
with:
get_template_part( 'template-parts/post/content', 'excerpt' );
in index.php Line 45 and archive.php Line 40 – as I found elsewhere on this forum.
You should have heard the loud YES!!! that almost woke up the entire household at 2AM when those excerpts showed up nice and shiny after refreshing π
Next challenge: show a thumbnail next (or above/below/..) to the blog archives page (preferably the blog panel on the homepage as well). I noticed a lot has been written about it already but I have a more specific question: I would like to have a thumbnail image (or a cropped version of the feature image of the specific blog post) but not show the feature image on the top of my blog page.
I’ve tried to add to the template-parts > post > content.php:
<div class=”entry-content”>
<?php
get_the_post_thumbnail();
the_content(
sprintf(
/* translators: %s: Post title. */
__( ‘Continue reading<span class=”screen-reader-text”> “%s”</span>’, ‘twentyseventeen’ ),
get_the_title()
But it doesn’t do the trick, even though a feature image for certain posts has been defined. Is there any (simple) way to show a thumbnail, and not show the feature image on the blog post? (assuming the thumbnail is based on the feature image).
Thanks for the help (and yes, I realise I’ve drifted away from my initial problem.. but hope someone can help pointing me in the correct direction). Merci π
-
This reply was modified 5 years, 1 month ago by
Ilse.
-
This reply was modified 5 years, 1 month ago by
Ilse.
-
This reply was modified 5 years, 1 month ago by
Ilse.
-
This reply was modified 5 years, 1 month ago by
Ilse.
Such a simple thing, having one’s code actually work. Yet so rewarding when it does so after a struggle. Be careful, it can be addictive π
Removal is a matter of editing the right template to remove the responsible code. Some CSS adjustment might be required if removal leaves a hole. But if you’ve correctly removed the image output code along with the related container HTML, the space ought to close up automatically.
It’s still a featured image even if it’s less featured and more thumbnail. Output the img tag anywhere you like with the_post_thumbnail('thumbnail'); (specify whatever size you like. I’d more likely use ‘medium’ over ‘thumbnail’) The call still needs to be within the loop context because the current post dictates what image is used. Outside of loop context, use get_the_post_thumbnail() which accepts a post argument. In this case you need to explicitly echo out the return, whereas the_post_thumbnail() echoes for you.
Thread Starter
Ilse
(@directionsud)
Sorry, had to read your reply 5 times and still haven’t got a clue were to start. Where should I place the_post_thumbnail('thumbnail'); or the_post_thumbnail('medium'); ? In the content.php?
Output the img tag? .. The call still needs to be within the loop context?
..accepts a post argument? Echo out the return… well you got the idea..
This is a ‘bit’ too technical for me π
-
This reply was modified 5 years, 1 month ago by
Ilse.
Sorry for the confusion. You place the call on the template where you want it to appear. Different themes can use different templates for the same purpose. content.php would be a likely candidate. If you have trouble identifying the right template, try the template debugger plugin.
“Loop context” is going to take some explaining. The templates involved for any given request will somewhere include code for “The Loop”, code which includes
while ( have_posts()) : the_post();
//code to output a post
endwhile;
Calling the_post() establishes the current post in several global values, all within the scope of this loop. Outside of this loop, determining the current post from these global values is unreliable. the_post_thumbnail() gets the image related to the current post established by these global values, so you cannot reliably use it outside of the loop.
get_the_post_thumbnail() will also use the current post, but you can instead optionally specify a specific post. So if you’re outside the loop and can get the right post ID through your own means, this function can still be used.
So which function you use depends on whether it is used within or outside of the loop. Outside of the loop you need to tell it which post you want the image for. There is one exception. On singular pages where only one post had been queried for, the global values established in the loop will retain the current post values after the loop has completed. So for singular templates only, you can still use the_post_thumbnail() after the loop has completed.
I hope that makes more sense, though I fear I may have added more confusion instead of clarifying.