I have a custom template named "eshop". In there, it calls a separate API out from WordPress and clicking on a link returns something like : eshop/ABC-123/
Is there a way I can make all the URLs that contain the word "eshop" to use the custom template I have created?
Thanks!
Step one: Pull the URI into a variable (http://webcheatsheet.com/php/get_current_page_url.php)
Step two: Search the variable string for the string you're looking for (How do I check if a string contains a specific word in PHP?)
Step three: use an if statement (If variable includes string "eshop", include the template) with a PHP include statement.
Related
I am trying to make a plugin that will display custom page when a parameter is present in the URL. For example, let's say that the URL of a post is localhost/wp/2018/03/22/postname/, it displays post normally as expected. What I want to achieve, is when I specify URL as localhost/wp/2018/03/22/postname/?param=1, I want to display page that I will generate with the plugin. I made a function that works when the parameter is present and it echoes some example content, however, it merges with what WordPress normally displays. So when I put the parameter into URL I get a regular page with post and my content somewhere in the middle. I want to display only the page that i generate from scratch, from <html> to </html> with my plugin. How can I do that?
There is a filter in WordPress called template_include this filter is executed before any output is displayed on the WordPress generated page.
You can override the current template via this filter as soon as you find the parameter and value in the URL. E.g. below is a filter I was using in a project to override archive & single template for a certain CPT:
function em_templates($template) {
if(get_query_var('post_type') == 'xyz' ) {
return FMM__DIR__ . '/templates/archive-xyz.php';
}
return $template;
}
add_filter('template_include', 'em_templates', 1, 1);
You can adopt this logic for parameter and use this WordPress filter to take over the template process and display yours own.
I have created page template in wordpress. right now its url is static like http://localhost/wordpress/test-test1 but i want to make it dynamic like http://localhost/wordpress/test1-test-test2 . Is it possible to create a single page template having dynamic url??
I want both url's to comes on single page. If page templating approach is not good then what could be other approaches. Here the test urls:
http://localhost/wordpress/test-test1
http://localhost/wordpress/test1-test-test2
http://localhost/wordpress/test13-test2-test1
I found similar links but none of the link helped me.
Here it depends on how would you change to pass argument, Suppose the last stage and it should be same always, and let page name 'anything'
<?php
add_action('init', 'add_my_rule');
function add_my_rule()
{
global $wp;
$wp->add_query_var('args');
add_rewrite_rule('test\/laststage\/(.*)','index.php?pagename=Pagename&args=$matches[1]','top');
Apply your custom template to this page, & on that template use this:
//if you visit http://.../test/laststage/name/AnyName, thus this $params will be name/AnyName.Now need to explode this and get the value.
$params = get_query_var('args');
Here's info: http://www.workingwith.me.uk/articles/scripting/mod_rewrite
I've created a custom configuration text field in Magento admin called Link.
Whatever is entered becomes pulled in frontend as URL.
User can add absolute paths and also Magento variable {{store url='awesome.html'}}.
The question is how to pull the {{store url='awesome.html'}} in the frontend to become http://www.domain.com/awesome.html?
I used this in the block
echo str_replace( '{{store url=""}}', Mage::getBaseUrl(), $top_menu_category->getContent() ); ?>
And it works for me in blocks, you need to use that function, because as I see, in template that variables aren't parsed
Here's a fun one. I'm using advanced custom fields inside of a template to pull a field called Applications with the following code.
the_field('applications');
The problem is that this won't pull the actual content without the page ID along with it, for example:
the_field('applications','42');
where the page ID is 42.
What I would like to do is use another template tag to pull the existing page ID with something like this in place of the 42, so that it will content specific to that page:
the_ID();
Which, in a perfect world would look like so:
the_field('applications','the_ID();');
This is obviously ridiculous and doesn't work, but I don't know what I need to do to get this to actually work.
Thanks!
the_ID() will automatically echo whatever is returned, whereas get_the_ID() will return that value so that it can be stored in a variable, or passed as an argument (which is the deal in this case).
<?php the_field('applications',get_the_ID()); ?>
http://codex.wordpress.org/Function_Reference/get_the_ID
I have a drupal view, which displays a content type filtered by a url argmuent (e.g. category). Now i'd like to add a link in top of my view, which allows my users to add a new node. In the add form the argument field should be prepopulated with the value from the filter.
I think to archive this, i have to install the prepopulate module and add some php-code to the header section of my view, which generates the link.
Any suggestions how to manage this?
If you are wanting to add php code to get the arguments passed to views in the views header section, do the following:
Make sure that the PHP filter is turned on; this is a module that can be enabled
In the header section use the following code:
$view = views_get_current_view();
// [0] is first arg, [1] is second etc.
$argumentOutput = $view-> args[0];
Remember to have the input format set to PHP code. This will get you the argument passed to views.
It would be a lot easier to override the template for the view and insert the code/markup there. Check out the Theming infomation inside the view to find out what to call your template.