I have an installed addon for magento called Fishpig. It essentially runs wordpress through magento allowing both to be used on the main website. The WP install is being used for a blog, and i've the whole initial theme set up for it by altering the magento files as required. What i'm looking for though is a way to change the theme if i look under a certain category related to the representative for the site.
Is there a way to set a different template if i were to choose the category? Will i need to add if statements to the category WP layout file?
If you want to change the whole theme based on the current WordPress category (or any conditions), you would need to listen to for an event and then change the theme programmtically. The most general event that would work would be 'controller_action_predispatch' however if you wanted to only change the theme for WordPress category pages, you would be better suited to use 'controller_action_predispatch_wordpress_post_category_view'.
Attach an event observer method to the event of your choosing and then use the following code:
$_category = Mage::registry('wordpress_category');
if (!$_category) {
return $this;
}
$_categoryId = (int)$_category->getId();
if ($_categoryId === 1) {
Mage::getDesign()
->setPackageName('default')
->setTheme('default');
}
else if ($_categoryId === 2) {
Mage::getDesign()
->setPackageName('default')
->setTheme('default');
}
return $this;
You would need to modify to code to set the correct package/theme (the code below enables the default package and default theme) to match the package/theme you want to set.
Related
I'm using Genesis framework and I have this page (http://staging.seedcreativeacademy.co.uk/short-courses/) showing the categories of my custom post type short_courses. I have changed the category name to course_type, by creating a new custom taxonomy.
This is how I want it to work so far (styling needs sorting out admittedly!) Im also using CPT UI plugin.
Now, when I click through to a category, is displays each 'Course in a nice masonry block as you will see here: http://staging.seedcreativeacademy.co.uk/course_type/digital-marketing/
However, I dont want this pages to look like this and I've tried adding custom template for the following:
Archive-short_courses.php & taxonomy-short_courses.php
Archive-course_type.php & taxonomy-course_type.php
But it doesnt seem to alter the layout at all...
Once I pass this hurdle I will want to alter the single.php page for these short courses, but I thought I would start with this first.
Im not sure if genesis blocks this and sets a site wide default? I know if sets a site wide default for the archive settings but I cant find anything about a template, plus i dont know if I shoujld be searching for tutorials on archive.php pages, category.php pager or taxonomy.php pages...
Can someone help me clarify things please?
course_type is a term name, not taxonomy name.
So, these are correct for your case:
category-course_type.php (category-{slug}.php is correct format. So check if course_type is correct slug of that category)
single-short_courses.php
Just in case, try reload permalinks via Settings->permalinks->save after making these changes.
Looks like your theme or some plugin is adding masnory class to body tag, which then is styled by your child theme. You need to filter that class out of your body tag and then might styling goes to non-masonary styling.
Add following code to your taxonomy-course_type.php file, and also make sure you have genesis(); call as the last thing in the template.
add_filter('body_class', 'remove_body_class', 20, 2);
function remove_body_class($wp_classes)
{
foreach($wp_classes as $key => $value)
{
if ($value == 'masonry') unset($wp_classes[$key]);
}
return $wp_classes;
}
Above could should be in custom taxonomy template, which also have genesis(); as last line.
If I create custom field in Joomla, it's will show in homepage (featured article) and blog category menu.
I want custom fields to only show in a single article. It should be hidden in the homepage (featured articles) and blog category menu.
Where can I setting it or modify in PHP code?
The files you need to override are at \components\com_content\views\featured\tmpl\default_item.php and \components\com_content\views\category\tmpl\blog_item.php
Important : core files should be overridden in your template, and the core code left unchanged.
The fields themselves are generated by the lines
<?php // Content is generated by content plugin event "onContentBeforeDisplay" ?>
<?php echo $this->item->event->beforeDisplayContent; ?>
Note that removing these lines will also stop any other plugin which uses this area from working. As far as I can tell, the only other thing to use it is the voting system. If you need that, then you may need to write a bespoke plugin or just hide the area with CSS.
You can create the override of Layout com_fileds - field.
(copy the file render.php from components/com_fields/layouts/field/ to templatename/html/layouts/com_fields/field/)
Add two new variables and one more condition on the if condiction
defined('_JEXEC') or die;
$app = JFactory::getApplication();
$view = $app->input->getCmd('view', '');
if (!key_exists('field', $displayData) || $view != 'article')
{
return;
}
I got situation like I am using multiple themes in my php website and also integrate a wordpress blog.
For example this is my site URL: http://example.com
There I want to switch Themes by passing a query parameter like:
http://example.com?mytheme=red_theme
http://example.com?mytheme=blue_theme
etc.
Currently my activated theme in WordPress is like blue_theme and my WordPress blog URL is like:
http://example.com/blog?mytheme=red_theme
e.g.: red_theme should be display just like preview.
Otherwise if I go through this URL:
http://example.com/blog
Then the default theme (blue_theme) should be display.
I can adjust it in core PHP but i don't know how to do it with WordPress.
In WORDPRESS, you can set Theme Programmatically, Based on Device, like different theme on mobile and different theme on Desktop. Write below code in functions.php of your Default theme
function use_mobile_theme() {
// Chech device is mobile or not
if(wp_is_mobile()){
return 'theme19388'; // set theme name here, which you want to open on mobile
}
else {
return 'milano'; // set theme name here, which you want to open on other devices, like desktop
}
}
add_filter( 'stylesheet', 'use_mobile_theme' );
add_filter( 'template', 'use_mobile_theme' );
Is there a way we can change to a specific theme for a specific page only in Wordpress?
I tried easy theme switcher but the problem with that is that it changes theme permanently.
I don't want that...
I am not 100% sure of exactly what you want to achieve - but if it is only to have a different display for a single page (rather then really change ALL the theme to include all the functions etc..) , then -
You should can create a page-template and then choose it in the drop-down menu for your page .
(in the sidebar - Page-attributes ->Template)
In that case , you could also use specific functions by adding them to the page itself (before the output.)
For example :
<?php
/*
Template Name: my-page-name
*/
function my_specific_page_function() {
//..do_whatever
}
?>
There is this plugin but it hasn't been updated in over a year
http://wordpress.org/plugins/page-theme/
You can use the free plugin Freesoul Switch Theme, both for debugging and in a permanent way
I'm trying to make a custom Taxonomy Term page in Drupal 7. I've created a page--taxonomy.tpl.php file in my templates folder. The file only prints out a message. I now try to force the template file by adding
function template_preprocess_page($variables) {
if (arg(0) == 'taxonomy') {
$variables['template_file'] = 'page--taxonomy-tpl';
}
}
in my template.php, but it won't work. Can you help me? And if I get the custom page working, how do I fetch the nodes with this term (in page--taxonomy.tpl.php)? Thanks in advance.
Try using this in your template.php:
function template_preprocess_page(&$variables) {
if (arg(0) == 'taxonomy') {
$variables['theme_hook_suggestions'][] = 'page__taxonomy';
}
}
You need to pass $variables by reference, so add a & before it
template_file has changed to theme_hook_suggestions in Drupal 7
You don't need the -tpl in the template suggestion unless you want it to be a part of the filename like "page--taxonomy-tpl.tpl.php" which I don't think is what you want.
For more information, check out template_preprocess_page(), theme_get_suggestions() and Working with template suggestions
Not sure if this would meet your requirements, but one of default D7 views - Taxonomy term - emulates Drupal core's handling of taxonomy/term pages. You could just enable it (it would automatically replace Drupal's core taxonomy URLs), and then do whatever you want with it, keeping original page structure, all blocks etc, using Views' page templates (see "Theming information" in "Advanced") and all other bells and whistles...
Since you are using Drupal 7, you could also create a file name "taxnomy-term.tpl.php" and edit according to your needs.
See taxonomy-term.tpl.php
Full control over the taxonomy term page can be obtained using hook_menu_alter() . See https://drupal.stackexchange.com/questions/48420/theming-and-overriding-taxonomy-term-vocabulary-page/111194#111194