I'm currently developing a website where I need a widget to display the upcoming match. The site is for a football team. I've therefore created a plugin which creates a custom post type and a widget. Everything is working really well, but as I don't like to clutter my PHP code with HTML I figured I'd include the widget settings in from another file in the plugin directory. Although the include returns bool(true) nothing is showing in the widget form.
Here is the code I'm using to include the file:
public function form($instance){
require_once($this->plugin_directory.'/views/widget-form.php');
}
The variable $this->plugin directory is defined in the constructor and points to the correct path.
Here is the html code inside the included file, it's brief but just to test. No matter what I type in there it keeps returning blank.
<input type="text" name="title" value="Hello World!" />
Any ideas why this keeps happening, or doesn't WordPress support loading extra files in places like this? I could just have my html in the plugin-file, but I prefer to keep PHP clean, and not cluttered with HTML and/or CSS, JS etc.
If anyone could help me figure this out I would greatly appreciate it! :)
Thanks in advance,
Jonathan
I know you've mentioned that your $this->plugin_directory is set in the constructor as the correct path, have you tested the output of this and/or is it set as the absolute path or relative?
I've had issues in the past where plugin files couldn't read the relative path correctly and so therefore I had to switch to an absolute path instead or vice-versa.
Related
I've inherited a very large Drupal site and need to edit the content in $linked_site_logo as below, but I have no idea where to find this file.
<div id="logo"><?php print $linked_site_logo; ?></div>
What is typically the file structure for a large-scale Drupal site and where should I begin looking to edit this? I haven't been able to locate the file.
There seems to be an answer on a drupal community which might help you. https://www.drupal.org/project/corolla/issues/1472416 - which suggests the code maybe in the page.tpl.php file
However, your best bet might be to use your terminal or code editor to do a search across the code base for the line of code, as there could be multiple references to the logo being included.
It's probably in your theme template files page.tpl.php or in include header file. Use theme debug mode, put this in your settings.php at the end of the file:
$conf['theme_debug'] = TRUE;
Than inspect element using your browser and see where elements come from.
I have a header.php file containing my DOCTYPE and all my links/scripts.
I use
<?php
// HTML DOCTYPE insert
include 'header.php';
?>
at top of all my pages to have only one header for everyone, and it works fine.
Now, I have another page that get from a database a summary of my products information. When someone click on the "read more" link:
<p>
read more...
</p>
another page opens with the full information displayed...
Actually that works...
BUT on my new page (display_product.php/id=[anynumber]) my included file doesn't work. So I have no nav bar, no scripts, no stylesheet. Only the text from my database.
AND the weird thing is that when I copy/paste the HTML of my generated display_product page and launch it on my browser, it works... O-o
So the generated code is good.
AND the second weird thing is that when I get rid of the /?id... my layout works fine (but I have no text anymore, of course)
Does one of you have an idea why this crazy things happens?
"Hi guys, Thanks very much Fred -ii this was it. it works perfectly. Thanks sergiodebcn for your concerne."
Since other answers were given and did not solve the actual problem, am posting my comment to an answer, in order to close the question.
Remove the slash from /?id
The slash is trying to instruct the server to probably find a folder after a filename, which technically looks like is what's happening here.
The ultimate solution for include and require functions with path issues, is to use the absolute filesystem path to the file that you want to include or require.
i.e you may say:
include("C:\\www\\app\\incs\\header.php");
Hint
To learn how to set the absolute path for include dynamically for your project, check the source code of two files of cakephp framework:
index.php
webroot/index.php
I created a template on WordPress and I made an html form. It works well in HTML but doesn't work when used on WordPress. It seems that it doesn't find my contact-send.php page and it displays a 404 Error page.
My permalinks were on default and it didn't work.
Does anyone know how to fix this?
If any of my code is needed, I'll post it. I just didn't because I think it's not a code error once it doesn't find contact-send.php.
Use an absolute URL for the target of your form instead of just action="contact-send.php".
But unless you have particularly unusual requirements for your contact form, you will likely have better results using one of the many popular contact form plugins like Contact Form 7.
Using a well-maintained plugin ensures stability, and more importantly, security. Don't reinvent the wheel if you don't have to.
Your problem can be caused due to 3 reasons.
Giving wrong path in action tag. Using <?php echo get_template_directory_uri(); ?>/contact-send.php will solve this problem.
Missing contact-send.php page in the themes folder. This problem can be solve by adding the page to the themes folder.
Improper .htaccess file. This can be solved by recreating the code for your .htaccess file from Dashboard > Permalinks and paste it in the .htaccess file in the WordPress root directory.
I am giving the explanation in the assumption that your template file is directly in the themes folder.
Add <?php echo get_template_directory_uri(); ?>/contact-send.php. When you write contact-send.php only then it don't find your file which is in your theme. So use this <?php echo get_template_directory_uri(); ?>/contact-send.php in form action. This change may be helpful.
I'am templating the website under the Joomla 3.2.0 for HikaShop ecommerce component, and would like to find out which file is loaded with following code, so I could correctly override the styles for specific file.
The filename I'a working with is root\templates\MY_TEMPLATE\html\com_hikashop\user\registration.php. Inside that file there is a small part of code which underloads custom fields I would like to override with custom styles:
<div class="address-fields">
<?php
$this->type = 'address';
echo $this->loadTemplate();
?>
</div>
Anyone knows which filepath is exactly loaded with the following $this->loadTemplate(); ?
Not sure if you are using it the same way as it is used here, but they explain it as if the parameters you pass in the function loadTemplate(), actually as loadTemplate(address) would be files in your case found in registration_address.php
hey, It's worth a shot checking it out
SEE HERE
Can anyone tell me what is the difference between including the js script file in the following two ways,
I made this inside system plugin in joomla and included the js file inside "onAfterInitialise" function.
1)
<script type="text/javascript" src="<?php echo JURI::base(); ?>/plugins/system/test/script/script.js"></script>
This works fine and including the js file correctly, But when I logged-in from the backend the font size from userlisting and listing from other extensions gets enlarged.This is not the issue in my js script.
2)
$document->addScript(JURI::root(). "plugins/system/test/script/script.js");
This works fine without any issues.
Can anyone explain what goes behind this.
Using the second method is simply using Joomla coding standards and adds your script in between the <head> tags.
There isn't much difference except for where the script gets imported on the page.
JURI::base() and JURI::root() are both the same. They both define the root folder for your Joomla site. If you are unsure which one to use, I would recommend using method 2, as it's always good to get used to Joomla coding standards.
You can see the source of addScript() :) Basicly, if you use first method, your srcipt will be added in the same place you wrote the code. Second method will add link to a inner table in $document and will be 'rendered' at the
<head></head>
section at the end of page processing.