I need to use CHtml::link() inside " ".
Here is my existing code:
$html .="<li>\n <a href='books".$menu['items'][$itemId]['link']."'>
".$menu['items'][$itemId]['label']."
</a> \n";
$html .= buildMenutree($itemId, $menu);
$html .= "</li> \n";
I hope I can find a nice solution.
You can use the CHtml function in your string just as any other PHP function:
$html .="<li>\n " . CHtml::link($menu['items'][$itemId]['label'], $menu['items'][$itemId]['link']);
See normalizeUrl for the url's you can use.
Related
I have this shortcode (I wrote it in functions.php) that shows the read previous and read next links in a single post:
<?php
function prev_next_buttons_post() {
$html = '';
$html .= '<div class="container-single-post-buttons">';
$html .= '<div class="prev-next-buttons">' . previous_post_link('%link', '< read previous') . '</div>';
$html .= 'back to blog';
$html .= '<div class="prev-next-buttons">' . next_post_link('%link', 'read next >') . '</div>';
$html .= '</div>';
return $html;
}
add_shortcode('prev_next_buttons', 'prev_next_buttons_post');
The problem I have is that when I add the shortcode:
<section>
<div class="container btd-container-sm">
<?php echo do_shortcode('[prev_next_buttons]') ?>
</div>
</section>
when inspecting it shows the different structure and the links are outside their containers losing their styles:
I need them to be in the same structure as defined in my shortcode.
How could I solve this? Please help.
This is because previous_post_link and next_post_link do not return a value, but write to the output buffer directly.
You need to use their counterparts that return the value, so that you can then concatenate those into your string - get_previous_post_link and get_next_post_link.
(If you check the source code for the former two functions, you’ll see that they are just wrapper functions that call the latter two, and echo their return values - https://developer.wordpress.org/reference/functions/previous_post_link/#source)
Hi I have a Api list that is been generated using php here is the code that is been used to generate the list
<html>
<title> API LIST</title>
<body>
<?php
$jsondata = file_get_contents("api_link");
$json = json_decode($jsondata, true);
$output = "<ul>";
foreach($output['A'] as $schools){
$output .= "<li>".$schools['name']."</li>";
}
$output .="</ul>";
echo $output;
?>
the list is populated successfully but how can i add a link to the list so that when a user click on one of the items it opens a particular linked page here are the ways i have tried
$output .= "<li ".$schools['name']."</li>";
$output .= "<li>".$schools['name']. "</li>";
$output .= "<li>".$schools['name']."</li>";
I don't know where or how to add the a href code
Use
$output .= '<li>'.$schools['name'].'</li>';
You just need some changes in your code.You can try for
$output .= '<a href=https://www.google.com'.$schools['name'].'><li>'.$schools['name'].'</li></a>';
As per the comments you can use . to concatenate(join) the string and variable in php.
I have a challenge that is bugging me.
The thing is - I'm creating a plugin that is doing an AJAX call to another file in this plugin. It seems Joomla is preventing me from accessing that file.
I need to POST to a file that returns data from a SOAP call.
I'm calling the file from this line:
$html .= '$.post("search.php", { address: $(\'#address\').val(), zipcode: $(\'#zipcode\').val() },';
I've tried both a relative, absolute and server path as well - Joomla doesn't like it. But I can't remember or find the correct way to do it.
The file is in the same folder as the plugin that outputs above code.
Here's the complete javascript function my plugin outputs:
$html .= '<script type="text/javascript">';
$html .= 'function searchParcels()';
$html .= '{';
$html .= '$.post("search.php", { address: $(\'#address\').val(), zipcode: $(\'#zipcode\').val() },';
$html .= 'function(data) {';
$html .= 'var shops = $.parseJSON(data);';
$html .= '$(\'#shops_output\').html(\'\');';
$html .= 'for(i in shops)';
$html .= '{';
$html .= 'var html = \'<p>\'';
$html .= '+ shops[i][\'CompanyName\'] + \'<br>\'';
$html .= '+ shops[i][\'Streetname\'] + \'<br>\'';
$html .= '+ shops[i][\'ZipCode\'] + \' \' + shops[i][\'CityName\'] + \'<br>\'';
$html .= '+ shops[i][\'Telephone\'] + \'<br>\'';
$html .= '+ \'</p>\';';
$html .= '$(\'#shops_output\').append(html);';
$html .= '}';
$html .= '});';
$html .= '}';
$html .= '</script>';
Any help is greatly appreciated :-)
Thanks.
Please check this post on how to use Joomla's ajax interface (it seems you are not using it). This is much easier and much cleaner (and much more standard) than the method you described. All you need to do is to create the module/plugin (make sure that you have a function name ending with "Ajax") and then issue the right call from anywhere on your Joomla website (make sure you use the URL pattern described on the website).
My Wordpress plugin creates a few shortcodes that return blocks of HTML.
When I register the shortcodes, I do so like this:
add_shortcode('bb-loans-form', function() {
return Shortcodes::loanApplicationForm();
});
And here is the static method from the Shortcodes class:
public static function loadApplicationForm()
{
$form = new \AdamWathan\Form\FormBuilder;
$html = $form->open()->action('/apply')->class('bb-loan-form');
$html .= '<div class="bb-form-field">';
$html .= '<h2>Loan Application Number</h2>';
$html .= $form->text('loan_app_number')->id('loan-app-number');
$html .= $form->submit('Continue Loan');
$html .= '</div>';
$html .= $form->close();
return $html;
}
This is very cumbersome, and messy. I don't like outputting the HTML like this. I've also used Heredoc, but I had to use string substitution to include important values when the form is rendered.
Is there a better way to store my HTML files? I don't want these files publicly accessible. They would have to live in my plugin directory.
It's not a huge plugin, so I'm not overly concerned, but I'd like to know for future reference if there's a cleaner way to include the needed HTML.
You could just use a single string with concatenations...
$form = new \AdamWathan\Form\FormBuilder;
$html = $form->open()->action('/apply')->class('bb-loan-form') .
'<div class="bb-form-field">
<h2>Loan Application Number</h2>' .
$form->text('loan_app_number')->id('loan-app-number') .
$form->submit('Continue Loan') .
'</div>' .
$form->close();
return $html;
It at least keeps the HTML aligned.
I also don't really see an issue with Heredoc, as long as you assign variables and substitute them in:
$form = new \AdamWathan\Form\FormBuilder;
$form_start = $form->open()->action('/apply')->class('bb-loan-form');
$loan_app = $form->text('loan_app_number')->id('loan-app-number');
$submit = $form->submit('Continue Loan');
$form_end = $form->close();
$html = <<<HTML
{$form_start}
<div class="bb-form-field">
<h2>Loan Application Number</h2>
{$loan_app}
{$submit}
</div>
{$form_end}
HTML;
return $html;
I am trying to edit this code to make it a link which opens ins a new tab, but wherever I insert the "target='blank'" part in the code I get a parse error, can anyone one help me out please. Thanks.
$websiteurl = "" . $_POST['websiteurl'] . "";
need to add:
target='blank'
$websiteurl = '<a target="_blank" href="' .
$_POST['websiteurl'] . '">' . $_POST['websiteurl'] . '</a>';
You missed _.
put target="_blank"
Mine is like this:
$output .= "<p class='fb-page-name'><a href='". $app['link'] ."' title='". $app['name'] ."'>". $app['name'] ."</a></p>\n";
I had to use target='_blank' instead of target="_blank".
I'm just saying because maybe someone is struggling with it as I was.
$websiteurl = '' . $_POST['websiteurl'] . '';