Rajarshi Bose
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Unable to get JQuery to work in the backendI had tried with the admin_enqueue_scripts hook initially but even that doesnt work .
function enqueue_min_max () { //wp_enqueue_script( 'min_max', plugins_url( '../../js/minmax.js', __FILE__ ) , array() , false, true ); } add_action( 'admin_enqueue_scripts', 'enqueue_min_max', 999 );
What is odd is any vanilla JS seems to be working but JQuery is not . I am absolutely stuck with this for two days .
- This reply was modified 3 years, 9 months ago by Rajarshi Bose.
Forum: Developing with WordPress
In reply to: static HTML to WP questionsSeparate the content from the elements that are common to all(or groups of) pages. The common stuff goes in the theme, as does the treatment of the featured image or the header image. The content goes in the database.
After several days of playing around with WP and the course project I think this makes great sense now . I think finally I am able to understand how WP works now .
Forum: Developing with WordPress
In reply to: static HTML to WP questionsThanks a lot for the reply guys . It its reassuring to know what I feel should be the right way is indeed the right way . I have set about entering the HTML using the editor . I am however facing a problem which bcworkz foresaw. All the php in the template is getting commented when using the editor (the static HTML doesnt have any inline JS yet) So,things like :
<a class="event-summary__date event-summary__date--beige t-center" href="<?php the_permalink(); ?>"> <div class="page-banner__bg-image" style="background-image: url(<?php echo get_theme_file_uri('/images/library-hero.jpg') ?>);"></div> <div class="full-width-split__inner"> <h2 class="headline headline--small-plus t-center">From Our Blogs</h2> <?php $homepagePosts = new WP_Query(array( 'posts_per_page' => 2 )); while ($homepagePosts->have_posts()) { $homepagePosts->the_post(); ?> <div class="event-summary"> <a class="event-summary__date event-summary__date--beige t-center" href="<?php the_permalink(); ?>"> <span class="event-summary__month"><?php the_time('M'); ?></span> <span class="event-summary__day"><?php the_time('d'); ?></span> </a> <div class="event-summary__content"> <h5 class="event-summary__title headline headline--tiny"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5> <p><?php echo wp_trim_words(get_the_content(), 18); ?> <a href="<?php the_permalink(); ?>" class="nu gray">Read more</a></p> </div> </div> <?php } wp_reset_postdata(); ?>
are getting commented out in the HTML and the whole page is getting messed up . I understand that PHP is not allowed while using the editor and as suggested above I tried doing the PHP using shortcode :
So for :
<div class="page-banner__bg-image" style="background-image: url(<?php echo get_theme_file_uri('/images/library-hero.jpg') ?>);"></div>
I tried creating a shortcode :
function uni_image_shortcode($att) { $image_url = get_theme_file_uri($att['src']); return $image_url ; } add_shortcode('image', 'uni_image_shortocde');
And in the editor I’d used :
<div class="page-banner__bg-image" style="background-image: url([image src = '/assets/images/library-hero.jpg'])"></div>
This seems to be working all right . I just wanted to reconfirm if I am going in the right direction and that each of the different PHP ( and JS ) needs to be converted this way or is there possibly a quicker way to get this done ?
Thanks again for all the help and have wish you guys a Happy New Year .
Forum: Developing with WordPress
In reply to: Implementing Search and Filter in WordPressThanks , this is of great help . The results are indeed not unique . I have started coding this .
Forum: Developing with WordPress
In reply to: Implementing Search and Filter in WordPressHi thanks for the reply The JSON data has about 500-600 rows with 62 columns . I did not think about storing the data in the database and using SQL queries for the search and filter. I was thinking of doing the search and filter in my code itself . Unfortunately , the data from the API needs to be fetched each time a user visits the page ( properties can be sold /added at any instant ) . If this is the case would it be better :
1. To store the data in the database and use SQL queries or create custom posts and parse the data and store it in custom posts or would it be better to implement the search and filter functionality in my code itself ?
2. Either way do I need to keep a track of which users data is stored in which row in the database / custom post by using may be a cookie value in the database/custom post ?
3. Do I need a cron job later to delete all the rows / custom posts for a particular user ?
Forum: Developing with WordPress
In reply to: Question about using ob_start()Thank you , Joy .
Forum: Developing with WordPress
In reply to: Checking for is_admin() while creating custom postThank you .
Forum: Developing with WordPress
In reply to: Checking for is_admin() while creating custom postHi , the code is registering a custom post type and adding a metabox in the backend .I have put the code below . This is a tutorial that I am doing to understand how plugins are developed so there is no plugin support page . I guess the question I want to ask is if I am registering a custom post type using register_post_type(‘todo’, $args); on init hook do I need to check if its the backend using is_admin() before including the file which has the callback for register_post_type() ?
includes/my-todo-list-cpt.php
<?php // Create Custom Post Type function mtl_register_todo(){ $singular_name = apply_filters('mtl_label_single', 'Todo'); $plural_name = apply_filters('mtl_label_plural', 'Todos'); $labels = array( 'name' => $plural_name, 'singular_name' => $singular_name, 'add_new' => 'Add New', 'add_new_item' => 'Add New '. $singular_name, 'edit' => 'Edit', 'edit_item' => 'Edit '. $singular_name, 'new_item' => 'New ' .$singular_name, 'view' => 'View', 'view_item' => 'View '. $singular_name, 'search_items' => 'Search '. $plural_name, 'not_found' => 'No '.$plural_name. ' Found', 'not_found_in_trash'=> 'No '.$plural_name. ' Found', 'menu_name' => $plural_name ); $args = apply_filters('mtl_todo_args', array( 'labels' => $labels, 'description' => 'Todos by category', 'taxonomies' => array('category'), 'public' => true, 'show_in_menu' => true, 'menu_position' => 5, 'menu_icon' => 'dashicons-edit', 'show_in_nav_menus' => true, 'query_var' => true, 'can_export' => true, 'rewrite' => array('slug' => 'todo'), 'capability_type' => 'post', 'supports' => array( 'title' ) )); // Register Post Type register_post_type('todo', $args); } add_action('init', 'mtl_register_todo');
includes/my-todo-list-fields.php
<?php function mtl_add_fields_metabox(){ add_meta_box( 'mtl_todo_fields', __('Todo Fields'), 'mtl_todo_fields_callback', 'todo', 'normal', 'default' ); } add_action('add_meta_boxes', 'mtl_add_fields_metabox'); // Display Fields Metabox Content function mtl_todo_fields_callback($post){ wp_nonce_field(basename(__FILE__), 'wp_todos_nonce'); $mtl_todo_stored_meta = get_post_meta($post->ID); ?> <div class="wrap todo-form"> <div class="form-group"> <label for="priority"><?php esc_html_e('Priority', 'mtl_domain'); ?></label> <select name="priority" id="priority"> <?php $option_values = array('Low', 'Normal', 'High'); foreach($option_values as $key => $value){ if($value == $mtl_todo_stored_meta['priority'][0]){ ?> <option selected><?php echo $value; ?></option> <?php } else { ?> <option><?php echo $value; ?></option> <?php } } ?> </select> </div> <div class="form-group"> <label for="details"><?php esc_html_e('Details', 'mtl_domain'); ?></label> <?php $content = get_post_meta($post->ID, 'details', true); $editor = 'details'; $settings = array( 'textarea_rows' => 5, 'media_buttons' => true ); wp_editor($content, $editor, $settings); ?> </div> <div class="form-group"> <label for="due_date"><?php esc_html_e('Due Date', 'mtl_domain'); ?></label> <input type="date" name="due_date" id="due_date" value="<?php if(!empty($mtl_todo_stored_meta['due_date'])) echo esc_attr($mtl_todo_stored_meta['due_date'][0]); ?>"> </div> </div> <?php } function mtl_todos_save($post_id){ $is_autosave = wp_is_post_autosave($post_id); $is_revision = wp_is_post_revision($post_id); $is_valid_nonce = (isset($_POST['wp_todos_nonce']) && wp_verify_nonce($_POST['wp_todos_nonce'], basename(__FILE__)))? 'true' : 'false'; if($is_autosave || $is_revision || !$is_valid_nonce){ return; } if(isset($_POST['priority'])){ update_post_meta($post_id, 'priority', sanitize_text_field($_POST['priority'])); } if(isset($_POST['details'])){ update_post_meta($post_id, 'details', sanitize_text_field($_POST['details'])); } if(isset($_POST['due_date'])){ update_post_meta($post_id, 'due_date', sanitize_text_field($_POST['due_date'])); } } add_action('save_post', 'mtl_todos_save');
Forum: Developing with WordPress
In reply to: Dont display post with no contentI had to un resolve this post . The filter ‘posts_where’ is working but I am unable to understand what “AND trim(coalesce(post_content, ”)) <>”” does even after much googling around . My SQL is not that great , I understand coalesce(post_content, ”) will return the first non-NULL character between post_content and ‘ ‘ but what does “AND trim(coalesce(post_content, ”)) <>”” actually do and what is <> for ?
The posts_where is pretty cool and I hope to make use of it more in the future .
Forum: Developing with WordPress
In reply to: Dont display post with no contentThanks.
Forum: Developing with WordPress
In reply to: $wp_rewrite->rules is always NULLCould you please explain what do you mean by
That doesn’t happen until WordPress parses the URL.
?
If I am var_dumping $wp_rewrite in functions.php of the theme is’nt the URL parsed by then ?Forum: Fixing WordPress
In reply to: Custom Theme and front pageAfter you reply I’d gone on a research spree . WordPress is very different from what I thought it to be . Everything is slowly beginning to false into place .
Thank you for your detailed reply . I will have this closed .Forum: Developing with WordPress
In reply to: esc_attr() on hard coded stringYes you have thanks and sorry for the late reply
Forum: Fixing WordPress
In reply to: Custom Theme and front pageI am just two months into WordPress , learning it from home alone so please bear with my ignorance . Kindly correct me if I am wrong .
After your reply I went around digging a bit , so what I understand is themes( in
the Wp repository only ? ) are generic in nature made to display different types
of content . They are not meant for a single site and static pages .Static pages
are coded ( in for eg page-slug.php) or made using page builders. Theme’s main
functions seems to be enqueueing all the scripts and styles , create the header ,
footer , sidebar , create the blog index page template ( which you can overwrite
) and some generic page , archive , 404 etc templates .The only options WP
repository themes can store/read are the customizer options using which we decide
on the display inside a template file .Suppose I have static code for different websites of a particular niche ( eg.
lawyers) .They have similar pages ( eg . about us , front page , our team etc) but different layouts , assets and content all hard coded . I want to turn them to WP sites and give users the ability to choose from the different static pages and change the assets and content in the HTML . Is this not normal in WP development ?What I understand is if I want to do something like above I can either ( for WP
repository themes) make use of the customizer settings and use appropriate
templates based on the customizer settings or if I am distributing it outside the WP repository I can just include all the different templates and ask the end user to rename the files they need to make use of the template hierarchy . Is that correct ?Except the blog posts and blog index page all the content will be in the template files and not in the WP database . So , if these are coded in custom page templates or template files and if admins changes the theme or if a visitor to a website can change the theme ( I am assuming by visitor you mean WordPress registered users for that site ) all my content will not be available . Is’nt it the same thing as adding content using a page builder and uninstalling the page builder ?
Lastly if I have to store the content for the static pages in the WP database and show them using my templates so they are available on theme change I need to make users enter them using the Add Page or Edit Page screen but later while showing the content how do I differentiate between different sections of content which has been entered all together ? Eg . I have a Our Team page with different team members , If users enter all the information in the Page Editor together while displaying how do I differentiate between the team members ?
I hope my question makes sense . Also want to thank you for your time , learnt a lot from your replies .
- This reply was modified 5 years ago by Rajarshi Bose.
Forum: Fixing WordPress
In reply to: Custom Theme and front pageActually I just realized I do not quite understand the theme hierarchy … lol …
I am going through the link you ‘d sent making sense of it (again) .. but I would really appreciate if you could tell me how to go about doing what I want to in my previous post.