I have been asked to build a custom landing page / section of an existing Drupal 7 site via a custom module but the section needs to have a design that is completely different than that of the parent site. It's just a full size background image, no navigation, no footer, no header, and a new form.
Can you remove all the base site theme from a 'page' via custom module so you can create a custom design?
Short answer: Yes you can! It would require a lot of work, but you can.
Long answer: If the requirement about the solution coming from a custom module is strict, then skip to the last part of this answer. Otherwise you're welcome to fully read it.
What I would do
If the requirement about custom module is not strict, you can just create a page and add a custom template for it. Take a look at Template (theme hook) suggestions
i.e. Create a page called My custom page and let's say the Node id is 23, so you can create a file called page--node--23.tpl.php inside the current theme.
In that page you can modify all the html you need (even the header, footer, etc.)
Custom module
If the solution above does not work for you, you'll have to:
Create a custom module
Create a custom theme
In the custom module you can add a new path like this:
<?php
function mymodule_menu() {
$items['my-page-path'] = array(
'page callback' => 'mymodule_render_page',
);
return $items;
}
function mymodule_render_page() {
// Render your content
}
Later use the hook_custom_theme, in the module, to load your custom theme when certain criteria is met.
Something like:
<?php
function mymodule_custom_theme() {
if ($criteria_is_true) {
// Use the machine name of your custom theme
return 'my_custom_theme';
}
}
Related
I've created a custom module based on Divi's Blog module. Ever since the 4.10 the module's grid layout does not work anymore because of the Dynamic CSS feature. When this is enabled Divi basically only loads the required assets when a specific module is used. So if the Divi Blog Module is not in the page the required CSS is not included and my custom module displays bad.
I saw a filter that should force the assets of a default module and used it inside my custom module:
//force the blog assets to be included inside this custom module
function include_module_assets($assets_list) {
return ['et_pb_blog'];
}
add_filter( 'et_required_module_assets', 'include_module_assets' );
Now this adds some column styles, but the column widths are not being set. So there are still some styles that are not being loaded.
Anybody experienced this yet with their Divi extensions?
Thanks
As there doesn't seem to be a filter for $grid_items_deps found in ET_Dynamic_Assets::get_global_assets_list you can use the et_global_assets_list filter.
You'll probably find you need to add_filter earlier than when your module class is initialized, perhaps one level back in the constructor of your extension class.
function init() {
parent::init();
/** Removed other code the sake of simplicity **/
add_filter( 'et_required_module_assets', array($this, 'include_module_assets') );
}
// Make sure we include gutters3_grid_items
public function include_early_global_assets($global_asset_list, $assets_args, $dynamic_assets_class){
$assets_prefix = et_get_dynamic_assets_path();
$gutters_3_grid_path = $assets_prefix . '/css/gutters3_grid_items.css';
$global_asset_list['some_custom_blog'] = array(
'css' => $gutters_3_grid_path
);
return $global_asset_list;
}
Hopefully ET adds a filter in the future for $grid_items_deps in the near future. They do seem to be getting a little better with providing filters, still many more could be added.
If anyone knows of a better solution I'd be keen know, as there is an issue with the below that we include gutters3_grid_items.css even when not using a grid layout.
Cheers
I am adding a page with a node-id and earlier I was using "page--node--node-id.tpl.php" template to customize the node/page. However, I accidentally deleted that node, and now I am unable to create that node with particular nid node. I want to know how to customize the specific page as each page his unique title.
Use page--node.tpl.php for all the nodes instead of each template otherwise use
node--[node-type].tpl.php for specifc node content type template
There is another smart step to create content type template with your own specific name by following below code
function themeName_preprocess_page(&$vars, $hook) {
if (isset($vars['node'])) {
$vars['theme_hook_suggestions'][] = 'page__'. str_replace('_', '--', $vars['node']->type);
}
}
In above case If node content type is "article" then the template suggestion will be "page--article.tpl.php".
Create template file page--nodetype.tpl.php in your theme directory.
I'm currently working on a custom post type and want to be able to edit the archive page from Wordpress with a page template. So I created the CPT called 'cars' and created a page template with template name: 'Cars overview'. Next i create a page inside WordPress and choose the template page 'Cars overview' and gave it the URL: mywebsite.com/cars/
Now the problem is that the slug 'mywebsite.com/cars/' is already in use by the custom post type itself causing the page to load the custom post type loop instead of the page template loop. So I can't edit the title, content etc inside WordPress. I could change the url of the page, but i want to be able to control the overview page in WordPress.
Long story short: How can I create a page template that is using the same URL as the custom post type archive page?
Thanks in advance!
One simple solution, simply disable the archive where you create your custom post type:
register_post_type("cars", array("has_archive" => false));
Another approach rather then disabling the archiving and adding another page to show the cars. Changing the archive template used by your theme might be a better option.
First step is to find the template currently in use by your theme, copy it to your plugin file and you can change the template file to whatever you like. You can find more information about it here.
The only thing you need to do is point WordPress to the right direction:
add_filter("archive_template", "archive_template");
function archive_template($archive_template) {
global $post;
if ($post->post_type == "cars")
{
$archive_template = "path/to/your/template.php";
}
return $archive_template;
}
Disabling the archive and creating one manually seems a bit strange to me. And I always replace the archive page and sometimes single page from our theme (usually the7).
In my plugin i have created a custom template that prints a requested sidebar. and for running the code of this template i assigned a custom page to it (by calling update_metadata) .
Is it a good idea for getting content of a specific sidebar into Ajax call ?
Now my problem is that WORDPRESS shows it in the dashboard and front page , and after searching i have not found any easy to understand solution for Hiding a page completely so only can be accessed by its id .
Can any one tell me how to do that ?
you are going about this the wrong way. You can create a function that can create anything that can be created on a wordpress page.
But if you really must you can create a page outside of the database, etc:
add_action('init', 'add_rewrite_rule');
function add_rewrite_rule(){
// add_rewrite_rule(REGEX url, location, priority (i.e. top is before other rewrite rules)
// I created a custom post type for this plugin called market -- replace post_type with whatever you want
//basically tell wordress to add a query var if sidebar is added to url.
add_rewrite_rule('^sidebar?','index.php?is_sidebar_page=1&post_type=market','top');
}
// register a query var
add_action('query_vars','market_set_query_var');
function market_set_query_var($vars) {
array_push($vars, 'is_sidebar_page');
return $vars;
}
// associate a template with your quer_var
add_filter('template_include', 'market_include_template', 1000, 1);
function market_include_template($template){
if(get_query_var('is_sidebar_page')){
$new_template = (theme or plugin path).'/pages/yourpage.php'; // change this path to your file
if(file_exists($new_template))
$template = $new_template;
}
return $template;
}
This will not be a page that will be in the admin section or in any query that relates to pages but someone could of course navigate to this page. But as i said above you would be better to create a function to create your sidebar. If you want a seperate file to handle the "view" you use require_once 'filename'; a file and keep your functions area free of html.
If you are creating functions in a wordpress plugin dont forget many functions may not be available until later in the load process. Use add_action() if you run into any undefined functions
edit:
you are loading wordpress before you get to the template so you have all the functions. (google wp load for more info) + get_header() / get_footer() will also load a few things like css, etc. I had a small typo in the code above, fixed that but basically what you are doing is telling wordpress if someone lands on www.example.com/sidebar to apply a query_var (rewrite rule). Wordpress will look up its saved vars (final function) and return the template assoc. The 2nd function just registers the var.
You also have wp_functions in any file you create and include in a plugin, etc hence why you can create a file that does exactly the same as this page.
I am looking to add a custom template for a single post inside of a Custom Post Type. The Custom Post Type is working as it should and all of the posts are correctly using single-{$posttype}.php. However, for the page with the slug "our-wedding", I am trying to override single-{$posttype}.php and have it use single-our-wedding.php. However, the page is still using single-{$posttype}.php.
Any ideas?
You can either use a solution that will let you assign custom templates to one particular post of that post type (there are plugins).
Or you can edit the single-{$posttype}.php to include a
if( is_single('our-wedding') ){
get_template_part( 'my-template');
} else {
// The usual code for this single-posttype
}
And then create a file called "my-template.php" inside your theme folder.
(Edited based on user feedback.)