IT Blog

  • 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.
Wordpress

Controling Category List on Sidebar Widget

Category list on sidebar widget will display all categories on post category hierarchy by default. However, we do not want to display all of them for some reason. Here is simple technique to achieve this goal. Find category IDs First thing to do is to find out all category IDs that we don't want them to show on the sidebar. Run the following script against WordPress MySQL database. SELECT t.term_id catID,t.name FROM wp_terms t join wp_term_taxonomy tax on tax.term_id=t.term_id where tax.taxonomy='category' Snippets //Hide categories from WordPress category widget function exclude_widget_categories($args){ $exclude = "4,6,7,8,9,10,13,14,15,16"; $args["exclude"] = $exclude; return $args; } add_filter("widget_categories_args","exclude_widget_categories"); Apply the snippets There are many ways to apply the snippets. You could add it to theme functions.php file or using snippets plugin to apply the snippets code. In my case, I'm using snippets to apply the code. This way is better organized for reusing the snippets. Last words, This is the simplest way to contorl the category list on sidebar, but you may use other ways to control the category list on sidebar, for instance, find a proper plugin or write your own plugin to achieve it.

2021-03-04 0条评论 14点热度 0人点赞 阅读全文
Wordpress

Restoring the Links Manager

WordPress Links Manager is a tool to manage a set of links. You can add, modify, and remove a link easily from admin dashboard. By default, WordPress come with a widget to add a sidebar, where the links will be shown. The Links Manager is provided by default in earlier versions of WordPress than Version 3.5. However, the WordPress Links Manager and blogroll are hidden for new installs. Moreover, if you used an earlier version than 3.5 and upgraded your installation, then the Links Manager was removed if you don’t have any links. Restoring the Links Manager 1. Using filter Add the following line to your theme’s functions.php file to enable WordPress Links Manager if you are using WordPress version 3.5 or higher To enable Links Manager in version 3.5+, just add the following code to one of the following locations: functions.php file of the theme; php snippets plugin; your own plugin; add_filter( 'pre_option_link_manager_enabled', '__return_true' ); Once enabled, you can see a Links tag in the left panel of the dashboard. 2. Change option value from database If you can access the database you could enable it pritty easy by changing the option value in the database directly. There is an option_name = 'link_manager_enabled' in wp_options table. You can set this value to 1 directly. update wp_options set option_value=1 where option_name='link_manager_enabled'; What Link Manager plugin does is just to change this value in wp_option table behind the scene using filter function. Displaying Links in sidebar WordPress provides a widget within its Links Manager. So you can easily locate links in the sidebar…

2021-02-08 0条评论 34点热度 0人点赞 阅读全文
Plugin

Adding reCaptcha for user forms in WordPress

Google reCAPTCHA uses an advanced risk analysis engine and adaptive challenges to keep malicious software from engaging in abusive activities on your website. UserWP plugin come with anther plugin that support reCaptcha. Here's the steps to setup. Search for UserWP reCaptcha plugin Install and activate UserWP reCaptcha plugin Go to google reCaptcha admin console Find the link to google admin console under Addons tab, and click on the link. Get key from google provider and fill into plugin settings In google admin console, click on plus sign to add a site, then copy the keys. Enter the site key and secret key into plugin settings Check result on the form

2021-02-08 0条评论 25点热度 0人点赞 阅读全文
Wordpress

Scheduling Background Job in WordPress

There are many things have to be done on background, for instance, version check, update theme, delete posts, delayed posting, delete transients, etc. In WordPress this background job is performed by WP-Cron, witch is defined in wp-cron.php file. WordPress cron is the system built-in process that handles the scheduling of time-based tasks. Out-of-the-box, WordPress performs a number of scheduled tasks, they include: WordPress core update checks Plugin update checks Theme update checks Publishing of scheduled posts WP-Cron takes its name from cron, which is a time-based job scheduler in Unix-like systems. However, WP-Cron is designed to work on any hosting provider (including shared hosting) without using any external software or tools for scheduling events. Problem of WP-Cron The wp-cron.php is triggered on every http request. If any scheduled event is due, the event is spawned to wp-cron.php for processing, so the event is triggered to run. This is unreliable, espectially for low traffic sites, or heavily cached sites, cause scheduled events to be missed if no traffic is received for a prolonged period of time. For high-traffic sites, WP-Cron is extremely inefficient. This is because WP-Cron will check for scheduled events on every page load. This could mean that the cron schedules are being checked multiple times per second. This is unnecessary and highly redundant, as scheduled events typically run in minutes or hourly, even monthly interval. Even wp-cron.php creates a lock in WordPress transient, witch stored in wp_options table, but for high traffice sites the high concurrent requests may still spawn multiple requests to wp-cron.php, thus increasing server load.…

2021-02-07 1条评论 79点热度 1人点赞 阅读全文
Technology

WordPress database access with $wpdb

What is in $wpdb object WordPress provides a global object, $wpdb , which is an instantiation of the wpdb class. By default, $wpdb is instantiated to access the WordPress database, but it can be used to manipulate any table in the WordPress database, not just those created by WordPress itself. With the following code include "../../wp-config.php"; print_r($wpdb); We will get result as wpdb Object ( [show_errors] => [suppress_errors] => [last_error] => [num_queries] => 42 [num_rows] => 0 [rows_affected] => 0 [insert_id] => 0 [last_query] => SELECT option_value FROM wp_options WHERE option_name = 'pods_upload_require_login_cap' LIMIT 1 [last_result] => Array ( ) [result:protected] => mysqli_result Object ( [current_field] => 0 [field_count] => 1 [lengths] => [num_rows] => 0 [type] => 0 ) [col_meta:protected] => Array ( ) [table_charset:protected] => Array ( ) [check_current_query:protected] => 1 [checking_collation:wpdb:private] => [col_info:protected] => [queries] => [reconnect_retries:protected] => 5 [prefix] => wp_ [base_prefix] => wp_ [ready] => 1 [blogid] => 0 [siteid] => 0 [tables] => Array ( [0] => posts [1] => comments [2] => links [3] => options [4] => postmeta [5] => terms [6] => term_taxonomy [7] => term_relationships [8] => termmeta [9] => commentmeta ) [old_tables] => Array ( [0] => categories [1] => post2cat [2] => link2cat ) [global_tables] => Array ( [0] => users [1] => usermeta ) [ms_global_tables] => Array ( [0] => blogs [1] => blogmeta [2] => signups [3] => site [4] => sitemeta [5] => sitecategories [6] => registration_log ) [comments] => wp_comments [commentmeta] => wp_commentmeta [links] => wp_links [options] => wp_options [postmeta] => wp_postmeta [posts] => wp_posts [terms] => wp_terms…

2021-02-01 0条评论 36点热度 0人点赞 阅读全文
CSS

CSS Tricks

Instead of JavaScript, CSS also can do some tricks to make magic happen. CSS can maintain counter variables to inrease the value, and also add some content before and after a block, emphasize first letter of a paragraph, mandatory fields validation, etc. Counters Demo 1 Effect Code <head> <style> body { counter-reset:sec-counter; /* Set "sec-counter" to 0 */ } h2::before { counter-increment:sec-counter; /*Increment "sec-counter" by 1*/ content:"Section " counter(sec-counter) ". "; } </style> </head> <body> <h2>HTML Tutorial</h2> <h2>CSS Tutorial</h2> <h2>JavaScript Tutorial</h2> <h2>Bootstrap Tutorial</h2> <h2>SQL Tutorial</h2> <h2>PHP Tutorial</h2> </body> Demo 2 Effect Code <head> <style> body{ counter-reset:section; /* define counter */ counter-reset:heading; } h1:before{ counter-increment: heading; content:counter(heading) " - "; } h1{ counter-reset: subheading; } h2:before{ content: counter(heading) "." counter(subheading) ") "; counter-increment: subheading; } h2{ counter-reset: section; /* define counter */ } h3:before{ content: counter(heading) "." counter(subheading) "." counter(section) ") "; /*content: counter(section) ": ";*/ counter-increment: section; } </style> </head> <body> <h3>Heading 3, no counter</h3> <h3>Heading 3, no counter</h3> <h1>Heading 1</h1> <h2>Subheading</h2> <h2>Subheading</h2> <h3>Heading 3</h3> <h3>Heading 3</h3> <h1>Heading 1</h1> <h2>Subheading</h2> <h2>Subheading</h2> </body> Demo 3 Effect Code <dhead> <style> ol{ counter-reset: counter; list-style-type: none; } li::before{ counter-increment: counter; content: counters(counter, ".") " "; } </style> </head> <body> <ol> <li>item</li> <li>item</li> <ol> <li>item</li> <li>item</li> <li> <ol> <li>item</li> <li>item</li> <li>item</li> </ol> </li> <li>item</li> </ol> <li>item</li> <li>item</li> </ol> <ol> <!-- restart counter --> <li>item</li> <li>item</li> </ol> </body> Mask Effect Code <head>     <style>         body{             background-color: rgb(124, 156, 216);         }         img{             width:900px;             mask-image:linear-gradient(to top,transparent 25%, rgb(50, 13, 184) 75%);             -webkit-mask-image: linear-gradient(to left,transparent 25%, #000 75%);         }     </style> </head> <body>     <img src="toronto city hall.jpg"> </body> First Letter…

2021-01-24 0条评论 60点热度 1人点赞 阅读全文
SQL Server

Generating Test Data with SQL Scripts

<<< These scripts were tested on MS SQL Server  2019 >>> From time to time we need to generate huge data for testing. Without any data generating tool we can achieve it by using some SQL Scripts. these scripts are different from regular query scripts. Generate list of data CREATE TABLE #accounts ( fname VARCHAR(20), lname VARCHAR(20)) GO INSERT #accounts VALUES ('Fred', 'Flintstone') GO 1000 SELECT TOP 10 * FROM #accounts fname lname Fred Flintstone Fred Flintstone Fred Flintstone Fred Flintstone Fred Flintstone Fred Flintstone Fred Flintstone Fred Flintstone Fred Flintstone Fred Flintstone ALTER TABLE #accounts ADD id INT IDENTITY(1,1) SELECT TOP 10 * FROM #accounts GO fname lname     id Fred Flintstone 1 Fred Flintstone 2 Fred Flintstone 3 Fred Flintstone 4 Fred Flintstone 5 Fred Flintstone 6 Fred Flintstone 7 Fred Flintstone 8 Fred Flintstone 9 Fred Flintstone 10 ALTER TABLE #accounts ADD id INT DECLARE @id INT SET @id = 0 UPDATE #accounts SET @id = id = @id + 1 OPTION ( MAXDOP 1 ) GO SELECT * FROM #accounts GO fname lname     id Fred Flintstone 1 Fred Flintstone 2 Fred Flintstone 3 Fred Flintstone 4 Fred Flintstone 5 Fred Flintstone 6 Fred Flintstone 7 Fred Flintstone 8 Fred Flintstone 9 Fred Flintstone 10 Note: MAXDOP is max degree of parallelism, set it to 1 to avoid duplicate value if running on multiple processors machine. Read article 1 for detail. Generate sequence numbers Using sys.all_columns table SELECT TOP (1000) ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) FROM sys.all_columns Generate huge Rows using CROSS JOIN SELECT ROW_NUMBER()…

2021-01-20 0条评论 63点热度 0人点赞 阅读全文
Technology

Remote connection to MySQL on SiteGround

1. Install MySQL ODBC Connector. Download it here: https://dev.mysql.com/downloads/connector/odbc/ 2. Run ODBC Search for ODBC Data Source, select 32 or 64 bit based on your OS. My OS is Windows 10 64bit, so I select 64-bit. 3. Add a new DSN Click on Add button to add a new DSN select MySQL ODBC Driver Enter parmeters to the screen. In order to complete the PCI compliance requirements the remote MySQL connection to the server's primary IP is blocked. For establishing a remote MySQL connection to a database you have to use the server's secondary IP. The secondly IP is shown on Remote database access hosts screen. 4. Test connection Click on Test button to verify the connection is working. DONE.

2021-01-11 0条评论 73点热度 0人点赞 阅读全文
Wordpress

Hide author information from WordPress

Author information is an important part of a blog, but for some reason you have to hide it. For example, the blog is a result of multiple authors. 1. Simply hide author information using stylesheet. Add custom css (look like the following): .author,.postauthor-container { display:none; visibility:hidden; } .uwp_widget_author_box { display:none; visibility:hidden; } /* UserWP plugin */ 2. Using "Hide/Remove Metadata" plugin 3. Change code The author information is written by theme, so you have to find out the php code location in order to make change. The possible location is on the following files: single.php, content.php, archive.php, index.php, functions.php, template-tags.php For example, in the theme "Twenty Nineteen" the code is on "twentynineteen_posted_by" function in template-tags.php file. Note that, before making any change on the theme code please make a full backup.   Hope this informaiton will help some people :)

2021-01-03 1条评论 135点热度 1人点赞 阅读全文
Wordpress

How to do some trick to improve WordPress performance

There are many ways to improve WordPress performance. But here I would introduce a trick to dramatically improve the page loading speed. Convert to html page As a web page the ultimate content is html code. If we could response in html directly without bothering the server code and database to run the page would be loaded really quick. make sure the web page working as expected use browser developer tool to view the source copy the html source code go to File Manager of the CPanel, manually create folders and index.html file according to the url pathFor example: for url "https://hostlike.com/zh/web-hosting/"create folder /zh/web-hosting/, then create file index.html under the new folder open index.html with file editor paste the copied content to the index.html file save the content. Dynamic content trick If there is dynamic content, e.g. shopping cart item number. We can use JavaScript to update the value. Add the following JavaScript code to the end of index.html content. function getCookie(name) { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) return parts.pop().split(';').shift(); } var cart_count = getCookie('woocommerce_items_in_cart'); $('.wcmenucart-details').text(cart_count);

2020-12-29 2条评论 684点热度 1人点赞 阅读全文
12345…16
最新 热点 随机
最新 热点 随机
Controling Category List on Sidebar Widget Restoring the Links Manager Adding reCaptcha for user forms in WordPress Scheduling Background Job in WordPress WordPress database access with $wpdb CSS Tricks
Scheduling Background Job in WordPressRestoring the Links Manager恢复链接管理器AdSense合规指南Controling Category List on Sidebar WidgetAdding reCaptcha for user forms in WordPress
Embed google map in a page Undo product custom field value in Ultimate Product Catalog WordPress database access with $wpdb Setting Up Mail for [Contact Form 7] Restrict guest to view only blog posts Solving SSMS diagram error
Categories
  • Architecture
  • BI
  • C#
  • CSS
  • Database
  • Digital Marketing
  • DotNET
  • Hosting
  • HTML
  • JavaScript
  • PHP
  • Program Language
  • Python
  • Security
  • SEO
  • Technology
  • Web
  • Wordpress

COPYRIGHT © 2021 Hostlike IT Blog. All rights reserved.