php-coder
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: How can I check if jquery is included?I have created another new page. There I can see jquery.js. Could not understand what was the problem with previous page.
Forum: Everything else WordPress
In reply to: Is jquery disabled for new pages?@sterndata , I think, no code is adding jquery for home page.
Forum: Everything else WordPress
In reply to: Is jquery disabled for new pages?Theme codes:
//header.php <!DOCTYPE html> <html <?php language_attributes(); ?>> <head> <?php wp_head(); ?> </head> <body> //index.php <?php get_header(); while ( have_posts() ) : the_post(); the_title(); the_content(); endwhile; wp_reset_query(); get_footer(); ?> //footer.php <?php wp_footer(); ?> </body> </html> //style.css /* Theme Name: Custom Test Description: To test Version: 1.0 */
Plugin codes:
<?php /* Plugin Name: Form Ajax Plugin URI: https:// Description: Form ajax request Version: 1.0 Author: User1 License: GPLv2 or later Text Domain: form-ajax */ if (!defined('ABSPATH')) { exit; } function form_ajax_add_theme_codes() { // Enqueue javascript on the frontend. wp_enqueue_script( 'example-ajax-script', plugins_url( 'js/simple-ajax-example.js', __FILE__ ), array('jquery'), null, true ); /* if( ! wp_script_is( 'jquery', 'enqueued' ) ) { echo 'no jquery'; exit(); } */ // The wp_localize_script allows us to output the ajax_url path for our script to use. wp_localize_script( 'example-ajax-script', 'example_ajax_obj', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce('ajax-nonce') ) ); } add_action('wp_enqueue_scripts', 'form_ajax_add_theme_codes'); function example_ajax_request() { $nonce = $_POST['nonce']; //print_r($nonce); //print_r($_POST); //print_r($_REQUEST); //exit; if ( ! wp_verify_nonce( $nonce, 'ajax-nonce' ) ) { die( 'Nonce value cannot be verified.' ); } // The $_REQUEST contains all the data sent via ajax if ( isset($_REQUEST) ) { $fruit = $_REQUEST['fruit']; // Let's take the data that was sent and do something with it if ( $fruit == 'Banana' ) { $fruit = 'Apple'; } // Now we'll return it to the javascript function // Anything outputted will be returned in the response echo $fruit; // If you're debugging, it might be useful to see what was sent in the $_REQUEST // print_r($_REQUEST); } // Always die in functions echoing ajax content die(); } add_action( 'wp_ajax_example_ajax_request', 'example_ajax_request' ); add_action( 'wp_ajax_nopriv_example_ajax_request', 'example_ajax_request' ); function form_ajax_form() { ?> <form method="POST" action="" > <div><input type="text" name="username" placeholder="Username" /><div> <div><input type="button" value="Submit" /></div> </form> <div id="id_div_fruit"></div> <?php } function form_ajax_show_form() { add_shortcode( 'form_ajax_form', 'form_ajax_form' ); } add_action('init', 'form_ajax_show_form');
Javascript codes:
//simple-ajax-example.js jQuery(document).ready(function($) { // We'll pass this variable to the PHP function example_ajax_request var fruit = 'Banana'; // This does the ajax request //console.log($); $.ajax({ type: 'POST', url: example_ajax_obj.ajaxurl, data: { 'action': 'example_ajax_request', 'fruit' : fruit, 'nonce' : example_ajax_obj.nonce }, success:function(data) { // This outputs the result of the ajax request console.log(data); $("#id_div_fruit").append(data); }, error: function(errorThrown){ console.log(errorThrown); } }); });
Forum: Everything else WordPress
In reply to: Is jquery disabled for new pages?When I browse https://localhost/wordpress > “View Page Source” I see jquery there. Why is this?
Forum: Everything else WordPress
In reply to: Is jquery disabled for new pages?I am expecting like this:
<script type='text/javascript' src='https://localhost/wordpress/wp-includes/js/jquery/jquery.min.js?ver=3.5.1' id='jquery-core-js'></script>
- This reply was modified 3 years, 8 months ago by Steven Stern (sterndata).
Forum: Developing with WordPress
In reply to: How can I check if jquery is included?From “View Page Source” of a page I do not see jquery there. Why?
Forum: Fixing WordPress
In reply to: How can I remove horizontal scrollbar in wordpress with css?[Four columns with four posts is being shown in home page with admin logged in. But they are not shown without admin logged in. Why is this?] This is solved.
- This reply was modified 4 years, 3 months ago by php-coder.
Forum: Fixing WordPress
In reply to: How can I remove horizontal scrollbar in wordpress with css?Please look at the previous link. I have added some posts.
Forum: Fixing WordPress
In reply to: How can I remove horizontal scrollbar in wordpress with css?Without “row” class, how will I put four columns in one row?
Forum: Fixing WordPress
In reply to: How can I remove horizontal scrollbar in wordpress with css?Will you check the link: https://dev-food00.pantheonsite.io/ ?
Forum: Fixing WordPress
In reply to: How can I remove horizontal scrollbar in wordpress with css?Why do margin:0; padding:0; not work? Is there any other way without html {overflow-x: hidden;}?
Forum: Themes and Templates
In reply to: How to add pagination for listing posts?<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div> <div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
these two lines doesn’t displya Older posts, and Newer posts link even though there are 6 posts in databases.
Forum: Themes and Templates
In reply to: How to add pagination for listing posts?It is index.php page.
Forum: Themes and Templates
In reply to: How to add pagination for listing posts?I am trying to write customized theme. There are two posts. How can i add Older and Newer posts there?
Can you please explain/elaborate the code?