In HTML, some URL or long sentence sticks out of the parent box. The following is an example.
<div class="box">
<p>This is an example of short message</p>
</div>
<br/>
<div class="box">
<p>ThisIsAnExampleOfLongMessage</p>
</div>
.box{
width:120px;
border: 2px solid #111;
}
Result
The cause of this problem
This is because of the settings of word-break or overflow-wrap (or word-wrap). Define word break point by word-break css property or define when the browser should insert line breaks within an otherwise unbreakable string.
post_password_required() is used to protect contents (posts) with password. This function detect whether post requires password and correct password has been provided.
This function checks a post type’s support for a given feature. The first argument $post_type is the post type being checked and the second one $feature is the feature being checked.
In my case, get the post type of the current post with get_post_type(), and check if it is ‘comments’.
comment_form() is used to output a complete commenting form for use within a template.
This function is used to displays a list of comments for current post or page. The argument array $args defines default arguments and form fields to override. You can use it to change class and id names.
Reference: Parameters of comment_form() in wordpress.org
This is one of the articles about project “Create Original Theme in WordPress”.
GOAL
To create sidebar.php
Environment
WordPress 5.5.1 XAMPP 7.4.10
sidebar.php
<?php
/**
* The template used for the sidebar
*@package WordPress
*@subpackage Techblog
*@since Techblog 1.0
*/
?>
<?php if ( is_active_sidebar('sidebar') ) : ?>
<aside id="sidebar">
<?php dynamic_sidebar('sidebar'); ?>
</aside>
<?php endif; ?>
functions.php
‘widgets_init’
‘widgets_init’ is the hook to initialize widgets such as sidebar. You should hook the register function register_sidebar() with add_action(). Please check the article “What is Hook in WordPress?” for detail about hook in WordPress.
In my case, techblog_widgets_init() is the function to register sidebar.
The function wp_head() should be in <head></head>. This is initially the same as do_action(‘wp_head’).
function wp_head() {
/**
* Prints scripts or data in the head tag on the front end.
*
* @since 1.5.0
*/
do_action( 'wp_head' );
}
This function fire functions attached to the hook ‘wp_head’. For example, some functions are added to the hook ‘wp_head’ in wordpress\wp-includes\default-filters.php as below.
The function body_class() is displays the class names for the body element.
function body_class( $class = '' ) {
// Separates class names with a single space, collates class names for body element.
echo 'class="' . esc_attr( implode( ' ', get_body_class( $class ) ) ) . '"';
}
The following is an example of actual HTML output.
<body class="home blog logged-in admin-bar no-customize-support">
wp_nav_menu() is the function to display navigation menu. the arguments list can be seen here.
How to import style.css in the header
It is recommended to use wp_enqueue_scripts instead of embedding <link rel=”stylesheet” href=”wordpress/wp-content/themes/techblog/style.css” type=”text/css”/> in header.php directly.
Add add_action( ‘wp_enqueue_scripts’, ‘<enque_function_name>‘ ); in functions.php of your theme.
add_action( 'wp_enqueue_scripts', 'techblog_scripts' );
function techblog_scripts() {
// Add main theme stylesheet
wp_enqueue_style( 'techblog-main-style', get_stylesheet_uri(), null);
}
In many WordPress themes, the link tag <link rel=”profile” href=”http://gmpg.org/xfn/11″> is contained within <head>. This tag is used for making relationship to XMDP (Xhtml Meta Data Profiles). You don’t need include this. You can see more information in “What rel=profile is for?“.
To understand what wp_enqueue_scripts() is and how to use it in WordPress
Environment
WordPress5.5.3
What is wp_enqueue_scripts?
‘wp_enqueue_scripts’ is one of the hooks built in WordPress. It can be used by hooking some function. Please visit “What is Hook in WordPress?” for details about hooks.
‘wp_enqueue_scripts’ can be used to register and enqueue When calledscripts(.js) or stylesheet(.css) to your theme. It call attached function with add_action( ‘wp_enqueue_scripts’, ‘attached_function_name‘ );
Register functions registers a script(js file) or stylesheet(css file) to use later on WordPress.
enqueue
Enqueue function add registered script or stylesheet to the queue in which enqueued scripts and stylesheets are outputted in the header.
Why is is used?
That’s because it is better to register script once and use it in some different pages. While if you embed scripts and stylesheets directly in header php file, the scripts and stylesheets are loaded in all pages, sometimes you’d like to use scripts only one page or use different scripts in a special case.
How to use wp_enqueue_scripts
Add add_action( ‘wp_enqueue_scripts’, ‘my_enque_function’ ); in functions.php of your theme and define my_enque_function to register and enqueue scripts and stylesheets.
If you just detect enter key pressed at any time, use getchar() or cin.get() function.
C language
#include <stdio.h>
#include <windows.h> // for Sleep function
int main(void)
{
while(true){
if (getchar() == '\n') {
printf("Enter key is pressed");
Sleep(1000); //wait for check printed message.
break;
}
}
return 0;
}
C++
#include <iostream>
using namespace std;
int main() {
while (1) {
if (cin.get() == '\n') {
cout << "Enter key is pressed" << endl;
break;
}
}
return 0;
}
Method 2. get line
If you’d like to detect that only enter key is pressed without input another key before enter, use scanf() , fgets() or gets() in C language or getline() in C++
C language
#include <stdio.h>
#include <string.h>
#include <windows.h> // for Sleep function
int main(void)
{
while (1) {
//if (getchar() == '\n') {
char str[32];
gets(str);
if(strcmp(str,"")==0){
printf("Enter key is pressed");
Sleep(1000); //wait for check printed message.
break;
}
}
return 0;
}
C++
#include <iostream>
using namespace std;
int main() {
string str;
while (1) {
getline(cin, str);
if (str == "") {
cout << "Enter key is pressed" << endl;
break;
}
}
return 0;
}
Method 3. GetKeyState
GetKeyState() is only provided on Windows. You can get the current “state” of the key. It returns 0 when the key is not pressed.
2. Create <domain>.pot file with pygettext.py that is in Python<version>\Tools\i18n directory. The pot file myapplication.pot will be generated in the directory “locale_dir”.
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2020-07-20 01:35+0900\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=cp932\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"
#: gettext_test.py:7
msgid "Hello World!"
msgstr ""
3. Create po file and put it in the language directory.
Change the charset into utf-8, input the translation and save it chadnged myapplication.po. In my case, the Japanese “こんにちは世界!” that means “Hello World!” is put in msgstr.
Put the chadnged myapplication.po in the <directory_name>/language/LC_MESSAGES. The language is <language codes>_<country codes>. I put it in locale_dir/ja_JP/LC_MESSAGES. The list of language code and country code: ISO-3166 Country Codes and ISO-639 Language Codes
4. Generate mo file from po file with Python<version>\Tools\i18n\msgfmt.py
When I create a new C/C++ project in VisualStudio, an header file named “pch.h” is generated.
GOAL
To understand what is pch.h and how to use it.
Environment
Windows 10 VisualStudio 2017
What is pch.h
pch.h is a precompiled header that is an header file where any stable header files such as Standard Library headers are included. You can add header files you’d like to pre compile. The precompiled header is compiled only when it, or any files it includes, are modified.
Start an application and kill it after a certain time.
Environment
macOS Catalina 10.15.5
ShellScript
sleep.sh
#!/bin/sh
open -a MyApp
sleep 60
killall MyApp
echo "stop"
open
The command “open” can open files and it takes some options. You can see options here. The -a option is for application.
open -a MyApp
kill/killall
The commands “kill” and “killall” can kill processes. “kill” takes PID(process id) and “killall” takes process name. You can stop and close an application with this command.
killall MyApp
sleep
The command “sleep” can delay for a specified time. Though “sleep” can take quantifiers such as 10s(second), 10m(minutes) and 10h(hours) in Linux, it can take number as seconds in OSX ([Tips]Why command “sleep 1m” doesn’t work in mac).
sleep 60
Execution
Open the terminal and input the sh file name.
% Documents/sh/sleep.sh
If the permission error occurred, change access permission with “chmod” command.