How can i have a pagination on my wordpress website - php

I'm trying to have a pagination on my custom Products page that is not the default one in Woocommerce.
I used Elementor to customize this page and after some research I saw that I could call a function that is already integrated in WordPress using the < paginate_links > function.
The only problem is that I have no idea where to call this function in order to have a pagination on my product page.
To be more precise, i would like to know where exactly i have to change or add my php functions, and what code should i use to get my pagination.

Normally it is in the archive.php or a version of that file name specific to your post-type. But before you go and change it, create a child theme in case you haven't done that already. In the child theme folder, you then duplicate the archive.php or similar to make it overwrite the one from the parent theme. This way you keep your version of the theme clean and updatable without losing any changes.
(For creating a child-theme you will need to create at least a style.css [with a WordPress-specific comment, you can google] and a functions.php-file that needs a bit of php-code to enqueue the child-themes scripts and styles. The code for the functions.php can also be found by a quick google search. You then just place the style.css and the functions.php into a new folder you name in the pattern [foldername of your themes name]-child. You then place this folder next to the parent-themes folder in the "/wp-content/themes/"-directory.)
And here you go for the pagination: https://codex.wordpress.org/Pagination

Related

WordPress: Child theme + Custom Post Template

I'm building a WordPress site using Elementor theme. I'm quite new to WordPress development.
I'm using a custom post type for a group of entities. I need to create a custom post template for these. I'm using the default Hello Elementor theme. I've created a child theme, so that I'm not making code changes to the base theme, in order to avoid issues when updating.
In the child theme, I've created a template for the custom post type, using the structure described in the documentation here, by creating a file called single-{entity name}.php. This works, as I can modify this file, and it'll affect the results rendered when I try and access one of these pages.
My problem is that the header and footer disappears and it seems to disregard everything from the parent theme. If I copy this single-{entity name}.php file into the parent file, it works just as expected with the header and footer showing.
I'm guessing there's some logic that intercepts the render in the parent theme and adds the header and footer, but I don't know how it actually works.
I'm not sure whether I should keep it in the parent theme to get this to work of if I should move it back to the child theme and then add some configuration in order to get the header/footer to show? If the last option is the recommended way, guideline on how to achieve this.
Goal is to be able to have a file that governs the template for all entities of this type, keep the header/footer and not be at risk of breaking when updating the theme and/or WordPress.
Have you tried to copy an existing file (exact copy of single_post.php for example) just to see if it works ?
If the page have header and footer, then the error is on this php file, otherwise it's somewhere else.
You can have an idea like that

Add a custom-made slideshow to Wordpress Theme

So i made a slideshow using HTML, CSS and JS.
It's for a personal blog i'm creating, so i would like to add the slideshow into a Wordpress theme that i purchased.
I created a child theme and tried to edit the function.php file and the style.css, and although i know some PHP it's really hard to understand how the code works and where to add mine.
Basically i want to display my slideshow initially, and then the rest of the Wordpress theme with all the posts and such.
Is it possible or should i only work with the customization options of the theme, although they're limited?
Since you've gone with a child theme, may I suggest copying a page template from the parent into your child theme?
Then you can copy your code for the slideshow via the editor into your child theme's copy of page template and use said template throughout your website for whatever page you'd like without colliding with parent theme updates.
Here's a relatively simple tutorial for creating a page template:
https://www.cssigniter.com/add-custom-page-template-using-child-theme/

Is it possible to hook a text box into a WordPress theme, via the functions.php file?

I am currently using a WordPress theme to create an ecommerce website. I am looking to create a horizontal text box, with 3 columns, to appear directly beneath the Main Menu navigation. Rather than edit the header.php file, and risk breaking the theme, is it possible to achieve this by hooking into the theme, via a functions.php file in the child theme or would thus be bad practice?
So adding "right after the main menu" is not something WordPress will be able to give you directly, no. Because, by definition, the structure of a page is a theme's responsibility.
That would be a perfect case for a child theme, and it would be my first choice. There you can safely override the index file (or header file, depending on how the theme is built) and add your html to it.
Another option a child theme might give you, is adding html through the theme's own filters and actions - but that will totally depend on your theme giving you such hooks.
Finally, if truly you want to add right after the main navigation, you might look at the wp_nav_menu filter: using that, it should be possible to first detect if you are looking at the main navigation or not, and if you are, append your own html. But frankly, I think the risk of breaking your layout is greater with that method.
Hope this helps!

How can I avoid Wordpress theme upgrades changing my parent themes functions.php?

I have currently manually implemented a tracking code in wp-content/themes/genesis/header.php
The code looks like this (shortened):
<script>
CODE HERE
<?php if (is_single()){CODE HERE}?>
CODE HERE
</script>
</head>
Whenever I upgrade genesis (the Wordpress theme) this code is lost and I have to manually add it again.
How can I add this code via the functions.php to the head section in wp-content/themes/genesis/header.php so that it survives a Wordpress theme upgrade - how would the code look?
You need to use wp_head hook to add content to the <head></head> dynamically.
Your code would look like this:
add_action('wp_head', 'change_this_name');
function change_this_name(){
?>
<script>
CODE HERE
<?php if (is_single()){CODE HERE}?>
CODE HERE
</script>
<?php
};
Generally, the solution for modifying your theme without having your modifications overwritten is using a child theme. But you could also create a small plugin that would do the same thing you want to do here.
Which option you take is generally much of a muchness for now, but if you are planning more changes in the future, you should keep in mind that:
plugins are for adding functionality
themes are for controlling how things look and feel
This might help you decide which option is best to take now (although you can easily do both, or change later if you wish :)).
Option 1: Creating a child theme
Create a new folder in the wp-content/themes folder (name it whatever you'd like to call your new theme), and then create a style.css in that folder.
At the top of style.css you'll need to include defining information for your theme. You can copy the format for this from the Genesis theme, just change the name and other details so it's clear when you go to activate it that this is your theme.
The key here is then to add a new line to this theme info reading:
Template: genesis
That line tells Wordpress that your theme will be a child theme of Genesis, and anything your theme doesn't provide, Wordpress will grab from Genesis.
The key here is then to override only what you want to and let the rest fallback to Genesis.
So, you could copy the header.php and add your code in, but then you'll still need to update the rest of the file if it changes. A better solution would be to create your own functions.php in your new child theme and use the following:
add_action('wp_head', function(){
?>
Enter tracking code here...
<?php
});
This will then hook into Wordpress' head action and print out the tracking code right where you want it, without you having to muck around with the rest of the header.
Of course, once you're ready, go to Appearance -> Themes in Wordpress and you'll see your new theme there. Activate it and check your site!
For more background and tips on child themes you can see this page on the Wordpress Codex.
Option 2: Creating a plugin
If it's just functionality you want to add to your site, you may find a plugin more helpful - particularly because you can change themes later and easily keep your plugin, and you can activate it and deactivate it at will.
You can create as many plugins as you like if there is more functionality you want to add later.
The process is fairly similar to creating a theme above. Instead of creating the new folder in the wp-content/themes folder, stick it in wp-content/plugins instead. Then, create a .php file in that folder (eg. myplugin.php, but you can call it whatever you like), and add the following to the top of the file:
<?php
/*
Plugin Name: My Toolset
*/
(You can add additional information if you wish, more information is available on this page of the Wordpress Plugin Handbook)
Under this, simply place the exact same add_action() code mentioned in the theme option above.
Save your file, go to Plugins in your Wordpress admin, find your new plugin in the list, click Activate, and check your site!
For more background and tips on plugins you can see this page on the Wordpress Codex.

where to find the origing category.php file in wordpress?

Hi I'm new to wordpress I have been working on a theme I would like to have the original category.php file that needs to get added on the theme? I have tried to copy a category.php file from a theme that was created on the core of wordpress but the body is missing, where can I find the original category.php file template that will be used by wordpress when it is not being defined on my theme?
version: wordpress 3.5.1
As templates are going to have theme specific markup, you'll need to make revisions to any file that you plan on copying over if you want the page to work with your theme.
A simpler solution is to copy your page.php file and replace your post loop with that of the categories loop. This will allow you to easily maintain your site's design without having to rework any markup and can be accomplished pretty quickly by copy/pasting a category loop snippet.
A great starting place to see how these loops are structured is the WP twentytwelve theme found here: http://wordpress.org/extend/themes/twentytwelve
Much greater documentation can also be found in the codex here: http://codex.wordpress.org/Category_Templates
Template files are stored in:
/wp-content/themes/<theme_name>/
You can copy the category template from a theme, but then it wouldn't look like it's a part of your theme though and might be badly styled because of missing CSS rules.

Categories