IT Knowledge Base

  • Blog
  • Technology
    • Architecture
    • CMS
    • CRM
    • Web
    • DotNET
    • Python
    • Database
    • BI
    • Program Language
  • Users
    • Login
    • Register
    • Forgot Password?
  • ENEN
    • ENEN
Experience IT
In a World of Technology, People Make the Difference.
Plugin

Entering large number of Envira Galleries at a time

Problem Over a few years there are large number of photos in facebook. The MPP want to copy all the photos in facebook to his own gallery on his website. The gallery on the site is using plugin - Envira Gallery. Normally, we create a gallery by drag-drop photos one by one, then place the shortcode on to a post or page. Now we have created all the gallery, the next step is to create posts to acommodate these galleries. The problems left are create posts for each gallery how to please handreds of gallery posts to the menu add featured image to each post Basic informaiton Envira Gallery stores gallery in wp_posts table with post_type = 'envira'. Regular posts are stored in the same table with post_type='post'. The data for the photos in a gallery is stored in wp_postmeta table with meta_key = '_eg_gallery_data' Category information is stored in wp_term_replationships table with object_id = post_id, term_taxonomy_id identifies its category, for gallery term_taxonomy_id=32. Solution Create post list using plugin Advanced Post List. Add posts for each gallery in batch List gallery title, gallery ID in excel in order to generate sql statement to create posts. The formula for cell D3 as following. =$D$1&"(1,'"&YEAR(C3)&"-"&MONTH(C3)&"-"&DAY(C3)&"', '"&YEAR(C3)&"-"&MONTH(C3)&"-"&DAY(C3)&"','[envira-gallery id=\"""&A3&"\""]','"&B3&"','','publish','closed', 'closed','','"&SUBSTITUTE(LOWER(B3)," ","-")&"','','','"&YEAR(C3)&"-"&MONTH(C3)&"-"&DAY(C3)&"','"&YEAR(C3)&"-"&MONTH(C3)&"-"&DAY(C3)&"','',0,'http://domain.com/?page_id=', 0,'post');" The formula on cell C3 as following. ="2018-"&IFERROR(MONTH(LEFT(RIGHT(B3,6),3)&" 1"),MONTH(LEFT(RIGHT(B3,5),3)&" 1"))&"-"&RIGHT(RIGHT(B3,6),2) Change create date for galleries. This is not necessory, but to do this we can use this script in excel cell F3. ="update wp_posts set post_date='"&YEAR(C3)&"-"&MONTH(C3)&"-"&DAY(C3)&"' where id="&A3&";" Set Featured Image to posts Using the first photo in gallery as the featured image.…

2020年03月30日 0条评论 19点热度 0人点赞 阅读全文
Plugin

Adding Featured Image for Envira Gallery posts in batch

Featured Image Featured images are stored in meta_value with meta_key='_thumbnail_id' in wp_postmeta table. SELECT * FROM wp_postmeta WHERE meta_key='_thumbnail_id' and post_id=@post_id Add featured image direct into database Find out the id of the image that you want to be a featured image in wp_post table, then insert a record into wp_postmeta table with meta_key='_thumbnail_id' @image_id = select id from wp_post where post_type='attachment' and post_mime_type='image/jpeg' insert into wp_postmeta (post_id,meta_key,meta_value) values (147, '_thumbnail_id',@image_id); Gallery Photos Photos in Envira Gallery are stored in meta_value with meta_key='_eg_gallery_data' in wp_postmeta table. select * from wp_postmeta where meta_key='_eg_gallery_data' Data stored looks like this: a:3:{s:2:"id";i:3972;s:7:"gallery"; a:8:{i:3973;a:7:{ s:6:"status";s:6:"active"; s:3:"src"; s:102:"http://vincentkempp.com/wp-content/uploads/2020/03/85092119_2768984699811558_8547879668101939200_n.jpg"; s:5:"title";s:47:"85092119_2768984699811558_8547879668101939200_n"; s:4:"link";s:102:"http://vincentkempp.com/wp-content/uploads/2020/03/85092119_2768984699811558_8547879668101939200_n.jpg"; s:3:"alt";s:0:"";s:7:"caption";s:0:"";s:5:"thumb";s:0:"";} Get the first image inside the gallery: SELECT p.id gallery_id, substring(meta_value, locate(':"http://', m.meta_value)+2, locate('";s:5:"title";', m.meta_value)-locate(':"http://',m.meta_value)-2) featured_image FROM wp_posts p JOIN wp_postmeta m on m.post_id=p.id and p.post_type='envira' and p.post_status='publish' and m.meta_key='_eg_gallery_data' ORDER BY p.id Check if the gallery post already has featured image. SELECT m.post_id,post_title, m.meta_value image_id FROM wp_posts p JOIN wp_postmeta m on m.post_id=p.ID and p.post_type='post' and p.post_content LIKE '[envira-gallery id=%' and p.post_status='publish' WHERE meta_key='_thumbnail_id' Get relationship between post_id and gallery_id SELECT p.id,post_title, substring(p.post_content, 21, locate('"]',p.post_content)-21) gallery_id, p.post_content FROM wp_posts p LEFT JOIN wp_postmeta m on m.post_id=p.ID and meta_key='_thumbnail_id' WHERE p.post_type='post' and p.post_content LIKE '[envira-gallery id=%' and p.post_status='publish' and meta_key is null ORDER by p.id Adding featured images INSERT INTO wp_postmeta (post_id,meta_key,meta_value) SELECT p1.id,'_thumbnail_id',img.id FROM ( SELECT p.id,post_title, substring(p.post_content, 21, locate('"]',p.post_content)-21) gallery_id FROM wp_posts p LEFT JOIN wp_postmeta m on m.post_id=p.ID and meta_key='_thumbnail_id' WHERE p.post_type='post' and p.post_content LIKE '[envira-gallery id=%' and p.post_status='publish' and meta_key is null ) p1 -- post_id JOIN ( SELECT p.id gallery_id,…

2020年03月29日 0条评论 229点热度 0人点赞 阅读全文
Database

Covid-19 open data

新冠疫情Covid-19公开的数据源 Novel Coronavirus (COVID-19) Cases Data https://data.humdata.org/dataset/novel-coronavirus-2019-ncov-cases COVID-19 开放研究数据集地址: https://pages.semanticscholar.org/coronavirus-research COVID-19 开放研究数据集挑战赛地址: https://www.kaggle.com/allen-institute-for-ai/CORD-19-research-challenge 北美新型冠状肺炎COVID-19疫情实时动态| 一亩三分地 https://coronavirus.1point3acres.com/?from=groupmessage

2020年03月28日 0条评论 424点热度 0人点赞 阅读全文
Wordpress

WordPress Featured Image in database

How featured image stored in MySQL database? Featured image in wp_posts table: post_author = '77777' post_parent = [post_id] guid = [image url] post_type = 'attachement' post_mime_type = 'image/jpeg' Featured image in wp_postmeta table: There are 3 meta_keys hold the image information. post_id, meta_key, meta_value = [post id], '_thumbnail_id', [featured image post id] post_id, meta_key, meta_value = [featured image post id], '_wp_attached_file', [image url] post_id, meta_key, meta_value = [featured image post id], '_wp_attachment_image_alt', [image alt] Optimize data structure Move the featured image record right next to the post. set @id = 2334; -- post id set @id1 = 2335; -- new image post id set @id2= 2339; -- old image post id update wp_posts set id=@id1 where id=@id2; update wp_postmeta set post_id=@id1 where post_id=@id2 and meta_key like '_wp_attach%'; update wp_postmeta set meta_value=@id1 where post_id=@id and meta_key='_thumbnail_id';

2020年02月20日 0条评论 582点热度 0人点赞 阅读全文
Plugin

Add further reading list after post

Further reading content should be based on the post category in order to get the title and permalinks of the related posts. First approach We could use filter to change the post contents. But it does not work as expected. The result is the new contents are added on each paginated page, and break the pagination link block. function my_content_filter($content) { $content .= further_reading(); return $content; } function stringInsert($str,$insertstr,$pos) { $str = substr($str, 0, $pos) . $insertstr . substr($str, $pos); return $str; } add_filter( 'the_content', 'my_content_filter', 1 ); //set priority to 1 in order to add the new content right after post content from database. Second approach The alternative way is to modify paging plugin directly. Plugin: automatically-paginate-posts File to change: /wp-content/plugins/automatically-paginate-posts/automatically-paginate-posts.php Inside paging plugin, it uses 'the_post' filter to make pagination. What we need to do is to change the post content directly in the $post object in filter_the_posts function. $the_post->post_content .= further_reading(); $content = $the_post->post_content; Avoid plugin auto-update In order to keep the custom changes we need to avoid the plugin update. Change the plugin version number to a big number. Add 9 prefix in this case. Version: 90.2 further_reading function function further_reading(){ global $wpdb, $post; $post_id = get_the_ID(); $categories = get_the_category(); $category_id = $categories[0]->cat_ID; $slug = $categories[0]->slug; $args = array( 'posts_per_page' => 6, 'category_name' => $categories[0]->slug ); $myposts = get_posts( $args ); $max = 0; foreach ( $myposts as $pst ){ $len = strlen(get_the_title($pst)); $max = max($len, $max); } $width = 350; if($max>50) $width = 400; if($max>60) $width = 450; if($max>70) $width = 500; if($max>80) $width =…

2020年01月30日 0条评论 262点热度 0人点赞 阅读全文
Web

Viewing old web pages

With web page history we can see how the page involved over time. If we found issues on current version web page, we still can compare to the previous version of the page and fix it easily. On google search we can get google cached pages. Just click on the little green down arrow, then cached. Tool: https://cachedview.com/ We can get google cached pages, or archive.org cached pages. Tool: http://www.cachedpages.com/ Google cached only get the latest version page before current one. Archive.org provides more versions of pages. Note that it is not cached very day! For example, articles that reference wechat images may encountered this situation all the sudden: Search the archieved page would give you idea how to fix it. Google the article title and look at the images. You could download the old images and upload it again to fix the issue.

2020年01月28日 0条评论 528点热度 0人点赞 阅读全文
Technology

WordPress cron job best practice

In WordPress all scheduled events are controled by wp-cron.php file. How cron job work in WordPress The file wp-cron.php is the part of WordPress that handles scheduled events within a WordPress site. Anything that has to do with scheduling posts or publications and really anything date/time oriented is governed by the wp-cron.php file. In order for wp-cron.php to work properly, it needs to be executed frequently, but no more than once per minute. However, the default behavior does not require you to set up a real system level cron job on your server. Instead, it uses a piggyback method on every incoming request. When a request comes into the site, WordPress will generate an additional request from itself to the wp-cron.php file over HTTP(S). It is invoked by http(s) each request. If no any request all events would never run. What if a large number of requests in a short period of time? It would become DDOS attack. Alternatives The best practice for scheduled jobs is to setup system cron job on server side that executes the wp-cron.php script directly through PHP in certain interval. This ensures that any scheduled tasks are indeed executed at their scheduled time. Cron functions Create cron hook add_action( 'hostlike_cron_hook', 'wp_cron_function' ); Schedule a task wp_schedule_event ( time(),  'hourly',  'hostlike_cron_hook' );  //may register duplicate event wp_next_scheduled ( 'hostlike_cron_hook' );   //return next execution timestamp, it check if a particular hook is already scheduled to ensure the event only be registerred once Recurring event if ( ! wp_next_scheduled( 'hostlike_cron_hook' ) ) { wp_schedule_event( time(), 'hourly', 'hostlike_cron_hook' );…

2020年01月24日 0条评论 379点热度 0人点赞 阅读全文
Wordpress

Event Calendar got 500 error

Symptom Event Calendar stop working. /events/, and event page shows 500 error. /contact/ page shows 500 error. Problem .htaccess file was changed. Working file: # HTTPS forced by SG-Optimizer <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] </IfModule> # END HTTPS # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress It was changed to # This file was updated by Duplicator on 2019-12-30 00:19:21. See .htaccess.orig for the original .htaccess file. # Please note that other plugins and resources write to this file. If the time-stamp above is different # than the current time-stamp on the file system then another resource has updated this file. # Duplicator only writes to this file once during the install process while running the installer.php file. # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /s/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /s/index.php [L] </IfModule> # END WordPress Related note Pages and posts are getting 404 Note This change is sespected as hacker action. It was imposible to use duplicator installer on the date.

2020年01月07日 0条评论 340点热度 0人点赞 阅读全文
Theme

Theme Demo Setup - BeautyPack

Download package file from DownloadFreeThemes and unzip the file. Installation guide video on youtube.  Install wordpress as normal, then activate BeautyPack theme, goto dashboard to import files. Install required plugins Clear existing posts and pages Files in theme package Import theme options Import sliders Import menu, posts, pages Page builder settings Change wp settings Final demos

2020年01月03日 0条评论 301点热度 0人点赞 阅读全文
Web

Domain redirection

There are a few way to redirect a site. 1. using meta refresh. Meta refresh is a method of instructing a web browser to automatically refresh the current web page or frame after a given time interval, using an HTML meta element with the http-equiv parameter set to "refresh" and a content parameter giving the time interval in seconds. It is also possible to instruct the browser to fetch a different URL when the page is refreshed, by including the alternative URL in the content parameter. By setting the refresh time interval to zero (or a very low value), meta refresh can be used as a method of URL redirection. <meta http-equiv="refresh" content="0;url=http://www.mortgageedge.ca/Judy-Yin"/> 2. using .htaccess file. The .htaccess editor is a powerful tool with which advanced users can customize their website. When using this tool, your first step will always be to select the domain and directory where you are applying the changes. Add one of the following code snippets into your .htaccess file (based on what you want to do. Old to new domain - Update "OLDDOMAIN" to the old domain you want to redirect to and update the "NEWDOMAIN" to the new domain it is redirecting to. RewriteEngine on RewriteCond %{HTTP_HOST} ^OLDDOMAIN.com [NC,OR] RewriteCond %{HTTP_HOST} ^www.OLDDOMAIN.com [NC] RewriteRule ^(.*)$ http://NEWDOMAIN.net/$1 [L,R=301,NC] HTTPS - Redirect for SSL Certificate, update the "DOMAIN" to the domain that requires the redirect from HTTP to HTTPS Click Save. RewriteEngine On RewriteCond %{HTTP_HOST} ^DOMAIN.com [NC] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.DOMAIN.com/$1 [R=301,L] 3. using 301 redirect 301 is one of the HTTP response status code used for permanent URL redirection. This type of redirect is best for SEO purposes and also…

2019年12月04日 0条评论 727点热度 0人点赞 阅读全文
12345…16
最新 热点 随机
最新 热点 随机
Remote connection to MySQL on SiteGround Hide author information from WordPress How to do some trick to improve WordPress performance Recovering user role in WordPress Sending email using gmail SMTP Restrict WordPress user access some contents
How to do some trick to improve WordPress performanceRemote connection to MySQL on SiteGroundSending email using gmail SMTPRecovering user role in WordPressHide author information from WordPress
Covid-19 open data Hide empty custom fields in Ultimate product catelog plugin WordPress cron job best practice Using widget components in any place Crawling 51job in Python JQuery set selected option for supporting multi-language
Categories
  • AdSense
  • Architecture
  • BI
  • C#
  • CSS
  • Database
  • Digital Marketing
  • DotNET
  • Hosting
  • HTML
  • JavaScript
  • PHP
  • Program Language
  • Python
  • Security
  • SEO
  • Technology
  • Web
  • Wordpress

COPYRIGHT © 20203-2021 Hostlike.com. ALL RIGHTS RESERVED.