Drupal Content Image URI - php

I'm trying to theme a view in Drupal 7. I have the view theme set-up and it is working fine. The issue that I have is that I can't see a way to override the $content variable passed into the render() function.
Is there a pre/process hook that I should be using or should it be done in a .tpl file using the $node variable?
Currently I'm looking at the $node variable but the image attached to the content has a url of public://field/image/imagefield_JmDqqm.jpg and I've not been able to find a function (so far) that will parse that url into the correct url to view the image on the page.
Thanks for any and all help.

The file_create_url function is what you're after

Related

Passing a variable to template file in wordpress plugin

In my wordpress plugin I have a function which has a page id:
public function create_view_for_pdf() {
$page_id = $_POST['page_id'];
$this->template_shortcode('template.php');
}
here, "template_shortcode" function includes a template located in a folder in the plugin directory.
private function KendoPdf_template_shortcode($template_name) {
return include '/template/dir' . $template_name;
}
In the template file, I want to pass the page id so that I can print content there. How can I do that?
Note: Since I am just including the template file, I thought I will get the $page_id variable there normally. But it did not work. I needed the page id in template file because the content will be different than the actual page. That page also has ACF fields. I am basically creating a new template for pdf export. That's why I cannot use all the content of that page.
Please correct me if I am wrong but why would you pass the the page_id to the template file if it is within $_POST? Just access the variable using $_POST['page_id']; within your template file.
Instead of including your template file you could also read it into a string with file_get_contents(); and do your desired replacements before you return it.
Another possibility would be a global variable which is already set: global $post;
And last but not least you could use output buffering with ob_start(); (and consecutive functions).
You see: A lot of ways to solve this.

Read POST data in Wordpress page

I am trying to write a plugin for wordpress. I have a problem i can't solve.
Inside plugin i habe added a shortcode that show a form.
function showForm() {
echo '<form method="post" action="www.example.com/myDestinationPage">';
[...]
}
add_shortcode( 'ShowFormSC' , 'showForm' );
After that, in a page, i added the shortcode and it works perfectly. ;-)
Now the problem: how can i read POST data in myDestinationPage (another wordpress page)?
In Php would be very simple ... but in wordpress I do not know how to do.
Second problem: myDestinationPage must be a real wordpress page with another shortcode inside, or can be defined as a "virtual" page inside my plugin?
Thank you for your help!
Best Regards,
Simone
www.example.com/myDestinationPage needs to be edited to recieve the post data, just as in any other php script, wordpress or not. If 'myDestinationPage' resolves to dynamic wordpress content, then you are in muddy waters.
Let's say, myDestinationPage is a wordpress Post. That "page" doesn't exist as a file, it comes directly from the database.
You could write a shortcode which handles this though:
add_shortcode('post_parser', 'postParser');
. . .
function postParser() {
filter_input(INPUT_POST, 'my_post_value');
//do something
}
Then, you just add the '[post_parser]' shortcode to the myDestinatioPage Post. (You mentioned it's a wordpress page, but page & post are both WP_Post objects.)
Another option is to put your post processing code in the post.php (or whichever template myDestinationPage is).
1st answer: you can directly use $_POST in wordpress like in php.
2nd answer: Yes you can. If you want to use pages in your plugin, use plugins_url() to generate the path for form action.
https://codex.wordpress.org/Function_Reference/plugins_url

Why can I see the variable in the URL but the variable contains NULL when using GET

I am using a WordPress child theme and a custom page template. A separate folder in the child theme directory connects to an external database outside of this WordPress install. All database connections are good!
I am having a problem reading a 'test' variable passed from a link to another PHP page. Both pages exist in WordPress but each page are using a different page template - passing a variable between page templates!!
The HTML and PHP code from the first template (Wordpress Page) sends on link click to the other
View Photos
The destination URL reads: websiteurl.co.uk/?page_id=93?test=162
To see if the variable is being passed correctly before continuing I dumped the variable, however the variable contents displayed NULL
<?php var_dump(count($_GET['test'])); var_dump($_GET['test']); ?>
I have also tried
<?php var_dump(count($_POST['test'])); var_dump($_POST['test']); ?>
But the output is
int(0) NULL
Why can I see the variable in the URL but the variable contains NULL when using GET? All research seems to suggest this should be fine, or is it the way WordPress handles the URL?
Hope someone can point me in the right direction!
Thanks in advance
Your URL needs to be as
websiteurl.co.uk/?page_id=93&test=162

Wordpress Get URL Footer File

I need to access the footer inside a wordpress theme via a url. Ideally it would just render the footer data and nothing else, alternative suggestions welcomed though.
To add some context, the data will be fetched through the url and a script will read the markup. This data will then be cached and available through Magento where it is needed to be displayed..
Is there a url path that will display it or should I make a new page that can be called via the base-url+the-page-name???
There's nothing built in to do that. You could use the AJAX API in your theme or a plugin and accomplish it.
You hook into an action that gets sent as a URL or POST data parameter and then make a request to yoursite.com/path/to/wordpress/wp-admin/admin-ajax.php.
<?php
add_action('wp_ajax_so20495429_display_footer', 'so20495429_display_footer');
add_action('wp_ajax_nopriv_so20495429_display_footer', 'so20495429_display_footer');
function so20495429_display_footer()
{
get_footer('ajax');
}
This will work for all users, logged in or not, despite the wp-admin URL. Here is code above wrapped up in a plugin.
what you can do is make a wordpress custom page template.
If you dont know how heres a little tutorial : http://www.expand2web.com/blog/custom-page-template-wordpress/
Now you want the custom page template to only load the footer (add the html, head and body opening tags yourself)
if you create a new page with your page template seletced it will only output the footer.
Hope you can get it to work
Greetings
merijn
What about $footer_url=get_template_directory_uri().'/footer.php'; ?

Acces the raw wiki page contents in a Dokuwiki Render Plugin

I created a plugin and its basic functionalities are working well. It returns always testing as you can see in the method document_end().
But how can I access the plain, raw wiki page content?
This is my rawcontent.php file in the corresponding plugin folder.
I got it. After a deep serach in the code of Dokuwiki I discovered rawWiki().
It returns the raw content of a page, the current page name/id is a "global" "constant" named $ID.
Solution:
global $ID;
return rawWiki($ID);

Categories