I am using ajaxloadmore plugin. it works perfect from the code below inside template.
but when I call above code from the ajax call it returns empty divs with no records.
can someone let me know why it dosen't work from ajax call.
Ajax load more plugin uses ajax to load posts. Why are you not using its inbuilt functionality? You cannot use ajax inside PHP code for another ajax.
If you use this shortcode in ajax action, I don't think it will load it's JS files. If you could share some more details about what you are trying to achieve here, I might be able to help.
Also, if it does work somehow, you also need to manage the offset parameters or you will end up loading the same post again and again.
Edit 1-
You can reload the page when the user selects a category and by default, you can use all categories.
Try below code:-
if ( isset( $_GET[ 'category' ] ) && $_GET[ 'category' ] !== '' ) {
$cat = esc_html( $_GET[ 'category' ] );
} else {
$cat = "in-the-news,leadership,tips-tricks,trends";
}
echo do_shortcode( '[ajax_load_more post_type="post" posts_per_page="6" category="' . $cat . '" ]' );
Related
I am generating my own Wordpress template and would like to give users a front-end form (so they don't have to log in to the wordpress dashboard) to submit some post content. I've got everything working, thanks to this tutorial - but I'd like to make one enhancement. Currently when the user presses submit the data is stored in wordpress and they are then redirected to a fixed URL of my choosing. Rather than this I would like to simply clear the form data and display a confirmation message - I guess via AJAX? I know there are built in AJAX capabilities in wordpress, but I've never really used it. Can anyone help me out?
The part of the code that submits the data to Wordpress and provides the URL to be redirected is copied below. I assume I wil need to make a change here?
$post_id = wp_insert_post($post_information);
if($post_id)
{
wp_redirect( '/thanks' );
exit;
}
You could simply redirect to the current page with get_permalink():
if ( $post_id )
{
wp_safe_redirect( add_query_arg( array( 'thanks' => '1' ), get_permalink() ) );
exit;
}
To display a message in the template, check the query arg:
if( isset( $_GET['thanks'] ) && '1' == $_GET['thanks'] )
echo '<p class="success">Thanks!</p>';
if you need more featuredone means, try this,
http://kvcodes.com/2014/02/front-end-post-submission-wordpress/
In my CakePHP 1.3 version, I have two submit type image tags as mentioned below:
echo $form->submit('save-print.jpg' , array('name'=>'savenprint','value'=>"savenprint",'id'=>"savenprint"));
echo $form->submit('save.jpg');
Now, What I want is to identify in my Controller, that which button is submitted, whether "Save" or "Print & Save"
So I have applied name and value to each of them and in Chrome browser, i am getting name and value pair, while in Mozilla Firefox, I do not get the same.
Any idea, how that can be achieved? or what is wrong or missing in my code.
Earliest response will be appreciated.
Thanks !
Your Form should looks like:
echo $form->submit('save-print.jpg' , array('name'=>'savenprint','value'=>"save",'id'=>"savenprint"));
echo $form->submit('save.jpg', array('name'=>'savenprint','value'=>"savenprint",'id'=>"savenprint"));
In your Controller use:
if($this->data['ModelName']['sbmtfrm_x'] == 'save')
{
//Your save code here
}
else if($this->data['ModelName']['sbmtfrm_x'] == 'savenprint')
{
//Your savenprint code here
}
One another solution is to make a hidden field and set the value of it onclick of submit button in your jquery code like in the following way:
Your form:
echo $form->submit('save-print.jpg' , array('name'=>'savenprint','value'=>"save",'id'=>"savenprint", 'class' => 'submitBtn'));
echo $form->submit('save.jpg', array('name'=>'savenprint','value'=>"savenprint",'id'=>"savenprint", 'class' => 'submitBtn'));
echo $form->hidden('sbmtValue', array('id' => 'sbmtValue', 'value' => ''));
And your jquery code should looks like:
$(document).ready(function(){
$('.submitBtn').click(function(){
$('#sbmtValue').val($(this).val());
});
});
And in your controller's action use:
if($this->data['ModelName']['sbmtValue'] == 'save')
{
//Your save code here
}
else if($this->data['ModelName']['sbmtValue'] == 'savenprint')
{
//Your savenprint code here
}
Hope it will work for you.
Ive been working with CI and I saw on the website of CI you can load a view as a variable part of the data you send to the "main" view, so, according the site (that says a lot of things, and many are not like they say ...ej pagination and others) i did something like this
$data['menu'] = $this->load->view('menu');
$this->load->view ('home',data);
the result of this is that I get an echo of the menu in the top of the site (before starts my body and all) and where should be its nothing, like if were printed before everything... I have no idea honestly of this problem, did anybody had the same problem before?
Two ways of doing this:
Load it in advance (like you're doing) and pass to the other view
<?php
// the "TRUE" argument tells it to return the content, rather than display it immediately
$data['menu'] = $this->load->view('menu', NULL, TRUE);
$this->load->view ('home', $data);
Load a view "from within" a view:
<?php
// put this in the controller
$this->load->view('home');
// put this in /application/views/home.php
$this->view('menu');
echo 'Other home content';
Create a helper function
function loadView($view,$data = null){
$CI = get_instance();
return $CI->load->view($view,$data);
}
Load the helper in the controller, then use the function in your view to load another one.
<?php
...
echo loadView('secondView',$data); // $data array
...
?>
please help, I've a problem with Joomla's function renderModule.. I am trying to render module with this function, but it unfortunately strips javascript from the the rendered module.
I use the function in my own module which includes other modules according to current article..
The code is as following:
<?php
$moduleType = "j15html";
$moduleName = "test";
$option = JRequest::getVar( 'option', '' );
$view = JRequest::getVar( 'view', '' );
$id = JRequest::getInt( 'id', 0 );
$moduleName .= $id;
//echo $view;
if ( $option == "com_content" && $view == "article" ) {
//echo $moduleName;
$module = JModuleHelper::getModule($moduleType, $moduleName);
//print_r($module);
if ( ! empty( $module ) ) {
$attribs = array();
echo JModuleHelper::renderModule( $module, $attribs );
}
}
When I set the position of the included module to any position used in my template and set it to displat in particular menu section, it renders properly even with javascript and so on..
Any advices how to make this thing working?
You didn't mention which version of Joomla you're using - but you may want to check out SOURCERER it keeps coding how you put it and does not strip out extra coding.
Make sure you read the how-to so you know how to use it because it can seem a little confusing at first, but it has a button to 'change the tags' from < to << or [ which do not get stripped out by the WYSIWYG editor in Joomla!.
Of course, that could be your issue also, if your WYSIWYG editor is on (by default it is) and you're inputting code - it strips it. An easy way is to just turn it off under global options, then when you save the code doesn't get stripped. Just turning off the WYSIWYG editor is the quick/easy/simple solution - but if you turn it back on and open that module again, the code will be gone. So it can be a tricky solution if others may like using the editor or if you're using lots of custom code around your side. In that case the plugin I mentioned above is a great solution.
I have an index view which has some elements on it .
index controller code;
$userID = $this->Authsome->get('id');
$qnotes = $this->Qnote->getnotes($userID);
$this->set('qnotes', $qnotes)
$this->render();
elements have been added to the page using
index view code
<?php echo $this->element('lsidebar'); ?>
now the Issue is I also Have an add controller.
add controller code
function add() {
if(!empty($this->data)) {
unset($this->Qnote->Step->validate['qnote_id']);
$this->Qnote->saveAll($this->data);
$this->Session->setFlash('New Note Template has been added.','flash_normal');
}
}
now what I am trying to achieve is once I add a Qnote i want the element('lsidebar') updated
for the new Qnote.
I am Using the Ajax helper. found at http://www.cakephp.bee.pl/
also Here the add qnote View Code :
<?php echo $ajax->submit(
'Submit', array(
'url' => array(
'controller'=>'qnotes',
'action'=>'add')
));
I know its sound like a noob question . can Somebody point me in the right direction atleast.
I have tried everything i could think off. I bet the solution something easy which i didnt think off
help :)
If you want to dynamically update a sidebar with information that is submitted via ajax, there should be a "success" option in your ajax post that would allow you to fire a specific javascript action when the post is finished (or succeeds). You should write a small javascript ajax function to reload the contents of your sidebar when the post succeeds.
See this other stackoverflow answer: CakePHP ajax form submit before and complete will not work for displaying animated gif