Post navigation – background images
-
Hi,
I am having a little issue with the background images of the post navigation links.
I use a Gazette child theme. In my child theme, I modified the file
single.phpin order to restrict the previous/next post links to posts within the same category only. To do that, I added'in_same_term' => true,inthe_post_navigation( array( ) );.It does work … but only for the links themselves. With
'in_same_term' => true, the navigation “banners” do show the links (and its respective titles) to the previous/next posts of the same category, but with wrong background images. The background images shown are not from the actual linked posts, but from the previous/next posts of the whole blog (irrespective of its category).Apparently the background image is set by the function
gazette_post_nav_backgroundin the file\inc\template-tags.php, but I have no idea what I have to do to make it work likethe_post_navigationwith'in_same_term' => true,.Two questions, then:
1. What modifications do I have to do to get the right background images (when using
'in_same_term' => true,)?2. In case I need to edit the file
\inc\template-tags.php, would it be possible to do so in a child theme? Or will I have to edit the file in the parent theme and be careful with theme updates? (If it is impossible to edit such file in a child theme, simply adding something to the filefunctions.phpwould certainly be preferable?)Thanks in advance!
-
I’ve successfully edited the file
\inc\template-tags.phpto show the right background images in the post navigation — just had to change the first parameter ofget_adjacent_postfromfalsetotrue.Now I just need to know how I can use this in a child theme, since the file is in a subfolder. I have tried to simply copy the original directory hierarchy, but the file was not loaded. I suppose only the files in the root folder of the theme are automatically overrode by its respective child versions, then.
I see
\inc\template-tags.phpis loaded in the parentfunctions.phpwithrequire get_template_directory() . '/inc/template-tags.php';, but I have no idea how to override thisrequirein a child theme.Any help will be appreciated. Thanks again!
gazette_post_nav_background()is not a “pluggable” function (it’s not wrapped in a conditional) so it’s not possible to override it simply in a child theme.The technique you’d use is to unhook the function from the parent and then add your new function in a child theme, so there are no conflicts.
If you’re not familiar with this, here’s a tutorial that may help:
http://code.tutsplus.com/tutorials/a-guide-to-overriding-parent-theme-functions-in-your-child-theme–cms-22623 – see the section “Removing Functions From Hooks.”
Great, I did what you suggested, and it worked!
I was first looking for a way to override the
requirestatement in the parentfunctions.php, but I couldn’t find a way to do it. That’s exactly what this guy wanted: http://stackoverflow.com/questions/32554393/how-to-override-a-parent-file-in-a-child-wordpress-theme-when-parent-file-is-bei.But simply unhooking the original function and including the new version with a different name worked. Thanks again!
Glad that did the trick!
The topic ‘Post navigation – background images’ is closed to new replies.
