I have a created a view (lets call it my_view).
In the theme: information section if the view I have noted one of the suggested template names (views-view--my-view--default.tpl.php (or close to that)), and created my own template file with that name.
This all works fine and when I visit the theme registry, I can see there is a hook there with the name of the template (views-view--my-view--default). However this hook has a type field of 'engine' rather than 'module'. I assume this is to do view the way views works out its own theming?
I want to implement hook_registry_alter to modify this theme hook (and others created in the same way), but I cant work out how to retrieve a list of these hooks.
I tried using array_keys(views_theme()) to get all the views hooks back but this list doesn't contain hooks created by over-riding template files. It only contains the default hooks like views_views_field etc
Is there a way to bring back a list of views theme hooks over-ridden in this way?
I answer here as your last comment seems to indicate you are not interested anymore in pursuing your initial approach, and 600 chars would not be enough, anyhow.
An alternative approach to achieve what you want could be to use the "inheritance" of sub-themes from their parent theme. You could in other words define your user theme as a sub-theme of the admin theme.
In this way the theming engine would search for templates - in the case of a user viewing the site through the user theme - first in the user theme folder, then in the admin theme folder, and then in the module directory.
This is for example the same mechanism used by zen for letting you create your themes with the starter kit.
Hope this helps!
Related
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
I am developing a custom theme from scratch in WordPress, So i have few questions about it.
1) Is custom theme create using default theme.
For example ( Suppose i have copied twentyseventeen and paste it and rename it my_custom_theme then after changes as per HTML in particular files (header,footer etc)
2) Should i create necessary files for theme like (header, footer, index, style, page, function etc)
So i want to clarify which way should i go for create a custom theme 1st or 2nd.
Someone please help me for this
I would recommend using underscores
It is a starter theme foundation setup built for that purpose, it has all the needed files templates and uses the best practices and organised code.
You will take it and build your theme from it.
There is also understrap which is underscores with bootstrap styling
this will save you alot of setup and preparation time, you can delete and remove any code or any template you not using.
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!
It has been a few years since I properly worked with WordPress. Now I have a proposal to build a WordPress site where every page has a custom design and only some areas of each page is editable.
The reason for this is to build a bespoke layout on each page which cannot be messed up by someone non-technical editing it in the CMS, except for small areas which they can customise.
e.g. A page contains one div which has some text in it, which can be edited in the WP admin backend, but the rest of the page cannot be edited.
Can this be done? How?
Edit: There needs to be multiple editable areas not just one. I know how to make custom pages/templates.
One method may be to create new page templates. Just create a new file in your main theme folder (or the templates folder if there is one). As long at the top of that file contains the line:
/*
Template Name: <your template name>
*/
You can design the page however you want. The data pulled from the admin section will go wherever you invoke
the_content();
The rest of the page can be hardcoded.
Then on the post edit page, on the right side (usually), you can choose the template with your template name for that page. It may be a good idea to copy the current post.php or single.php into your custom file and work from there.
For restricting access you can look at setting up user levels and keep your content contributors as "Authors" instead of "admins" so they can't change themes or edit settings.
(See https://codex.wordpress.org/User_Levels)
For creating specific unique pages with an area that gets changed you should look into custom Page Templates. You can create a page template by dropping a php file with the right naming structure into your theme hierarchy and it will get picked up by the back-end as template option when you create a page.
(See https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/)
I solved this problem using a plugin called Advanced Custom Fields which does exactly what I required.
is there any way to include a custom template from a folder inside my plugin page into the Wordpress system so that when I, for example create a new page/post, it can show as one of the template choices other than default of course.
I have seen this link here WP - Use file in plugin directory as custom Page Template? but does not seem to talk about the stage were Wordpress checks for custom templates in the themes directory and how to make it look else where.
It's not in the documentation because WordPress doesn't look elsewhere. Your best bet would be to create a template page in your theme folder, call it what you want, and then use include() to pull the contents of your template file in the plugins directory into the file in your theme directory, which would allow WordPress to see it.
I think the only other way to accomplish this would be to mess with Core, which is very bad practice.