I'm trying to add :
require get_template_directory() . '/mytheme/folder/file.php';
To specific category in WooCommerce, I tried already:
function get_file() {
if( has_term( 'categoryName', 'product_cat' ) ) {
require get_template_directory() . '/mytheme/folder/file.php';
}
}
add_action( 'woocommerce_before_main_content', 'get_file');
But it doesen't work ;/
How can i add this file only for 1 category?
Or for multi cat. by using else if
Regards, Gabrielle
I'm surprised you aren't getting a PHP error for the file not existing. But check out the get_template_directory() function. It gives you the path to the current theme folder. Therefore I think your path is probably wrong since your theme folder is being repeated... something akin to SOME_PATH_STUFF/wp-content/themes/mytheme/mytheme/folder/file.php
Try the following instead:
function get_file() {
if( has_term( 'categoryName', 'product_cat' ) ) {
require get_template_directory() . '/folder/file.php';
}
}
add_action( 'woocommerce_before_main_content', 'get_file');
Related
I am trying to check if a folder is writable so I can prompt an error dialog.
I am trying this:
QFileDevice::Permissions permissions_list = QFile( folderName ).permissions();
if ( permissions_list && QFileDevice::WriteUser )
{
}
but it does not work. It's the same for both writable folders and restricted ones.
use QFileInfo:
QFileInfo my_dir(folderName);
if(my_dir.isDir() && my_dir.isWritable()){
// Do something
}
but pay attention to this problem if you're on Windows
I have two set commands in my CMake.txt file. I have something like:
set(GUI_SOURCE_FILES
src/UINode/main.cpp
src/UINode/b.cpp
src/UINode/c.cpp
src/UINode/d.cpp
)
set(GUI_HEADER_FILES
src/UINode/b.h
src/UINode/c.h
src/UINode/d.h
)
This works fine and the executable is good. Now I want to have another group of set commands that need to included the above and add new .h and .cpp files. I am not sure if this is possible but I know that I cannot do something like:
set(GUIA_SOURCE_FILES
src/UINode/different_main.cpp
src/UINode/b.cpp
src/UINode/c.cpp
src/UINode/d.cpp
src/anotherpath/e.cpp
)
set(GUIA_HEADER_FILES
src/UINode/b.h
src/UINode/c.h
src/UINode/d.h
src/anotherpath/e.h
)
EDIT 1: Thanks for the reply user2799037! I now have something like:
set(COMMON_SOURCE_FILES
src/UINode/a.cpp
src/UINode/b.cpp
src/UINode/c.cpp
)
set(COMMON_HEADER_FILES
src/UINode/a.h
src/UINode/b.h
src/UINode/c.h
)
I then use them by:
set(GUI_SOURCE_FILES
src/UINode/main_GUI.cpp
${COMMON_SOURCE_FILES}
)
set(GUI_HEADER_FILES
${COMMON_HEADER_FILES}
)
and do
QT4_WRAP_CPP(GUI_HEADER_FILES_HPP ${GUI_HEADER_FILES})
followed by the
rosbuild_add_executable.
For the next part I do:
set(GUIA_SOURCE_FILES
src/commands/main_GUI1.cpp
${COMMON_SOURCE_FILES}
)
set(GUIA_HEADER_FILES
${COMMON_HEADER_FILES}
src/pathplanning/anotherheader.h
)
but I get an error when i do:
QT4_WRAP_CPP(GUIA_HEADER_FILES_HPP ${GUIA_HEADER_FILES})
'CMake Error: Attempt to add a custom rule to output'
I think you want to do something like that
set(COMMON_SOURCE_FILES
src/UINode/b.cpp
src/UINode/c.cpp
src/UINode/d.cpp
)
set(COMMON_HEADER_FILES
src/UINode/b.h
src/UINode/c.h
src/UINode/d.h
)
and use these for you more specific variables:
set(GUI_SOURCE_FILES
${COMMON_SOURCE_FILES }
src/anotherpath/main.cpp
)
set(GUIA_SOURCE_FILES
${COMMON_SOURCE_FILES }
src/anotherpath/different_main.cpp
)
Analog for the headers. With this approach you avoid having two list which can get out of sync.
I've written a rudimentary requirejs compiler for Django-Pipeline and I'm trying to polish it up but I'm stuck with a certain problem. I've noticed the same "problem" with the SASS compiler so I wonder if this is a setting I'm missing or something.
PIPELINE_CSS = {
'main': {
'source_filenames': (
'sass/main.scss',
),
'output_filename': 'css/crushcode.css',
'extra_context': {
'media': 'screen,projection',
}
}
}
PIPELINE_JS = {
'requirejs': {
'source_filenames': (
'js/lib/requirejs-2.0.4.js',
),
'output_filename': 'js/require.js',
'extra_context': {
'data': '/static/js/bootstrap'
}
}
}
Both of these create an output file in the source directory of the same name as the input file, with the extension changed to output_extension of the respective compiler class. For SASS, this is ok as the extension is .css so you end up with main.css next to your main.scss, but with my requirejs plugin the first time I ran it, because the extensions are the same, I actually overwrote my original file (Nothing lost of course, thankyou version control).
I noticed that infile and outfile were both pointing to:
APP_ROOT/static/js/lib/require-2.0.4.js
when I would have thought outfile should point to output_filename in the settings.
The easy fix was to change the output_extension of my custom compiler class to be 'optimized.js', but at this point I'm adding a .gitignore for every compiled file, and not to mention collectstatic then brings everything across, and also creates the desired output_filename file in the target directory.
What I was hoping for was that collectstatic would simply create the js/require.js file in my STATIC_ROOT directory.
It feels like I'm doing something wrong here, any tips? Is this expected behaviour? If so, what's the best should I go about changing it?
Is it possible to show modules in Joomla only in a specific article (not per menu item), but in standard module position?
For example somehow get the current article id in a template and insert the modules with according id suffix in the name?
I would advise you not to hardcode things like this in the template. My question is, why don't you want to use a menu item? You can create a hidden menu item for that article and use it, then assign the module to that menu item.
If you still want to do it without using a menu item, a possible workaround would be to use something like "mod_php" (some module that allows you to use php code) and do something more or less like this:
Create the module and assign it to a position that is not used anywhere (you can type whatever you want in the module position)
In your php module, put this code:
$option = JRequest::getVar( 'option', '' );
$view = JRequest::getVar( 'view', '' );
$id = JRequest::getInt( 'id', 0 );
if ( $option == "com_content" && $view == "article" && $id == YOUR_ARTICLE_ID ) {
$module = JModuleHelper::getModule('your_module_type', 'module_title');
if ( ! empty( $module ) ) {
$attribs = array( 'style' => 'xhtml' );
echo JModuleHelper::renderModule( $module, $attribs );
}
}
I'm sorry if the code snippet is not showing properly, but I hope you can read it ok. Just one thing, when you fill in the part saying 'your_module_type', don't include the "mod_" part of the name. For example, if you want to output a module of type "mod_article_list", you should write "article_list" in "your_module_type".
I hope it helps!
From another forum I found the following example:
"I was looking for a way to pull node data via ajax and came up with the following solution for Drupal 6. After implementing the changes below, if you add ajax=1 in the URL (e.g. mysite.com/node/1?ajax=1), you'll get just the content and no page layout.
in the template.php file for your theme:
function phptemplate_preprocess_page(&$vars) {
if ( isset($_GET['ajax']) && $_GET['ajax'] == 1 ) {
$vars['template_file'] = 'page-ajax';
}
}
then create page-ajax.tpl.php in your theme directory with this content:
<?php print $content; ?>
"
This seems like the logical way to do it and I did this, but the phptemplate_preprocess_page function is never called ... any suggestions?
I figured it out for myself from a Drupal Support Theme Development page:
"Maybe this helps
leahcim.2707 - May 29, 2008 - 05:40
I was trying to get the same thing done and for me this works, but I'm not sure if it is the correct way as I'm still new to Drupal:
in "template.php" I added the following function:
function phptemplate_preprocess_page(&$vars)
{
$css = $vars['css'];
unset($css['all']['module']['modules/system/system.css']);
unset($css['all']['module']['modules/system/defaults.css']);
$vars['styles'] = drupal_get_css($css);
}
I think after adding the function you need to go to /admin/build/themes so that Drupal recognises the function."
The part in bold is what did the trick ... you have to re-save the configuration so it recognizes that you've added a new function to the template.