Skip to content

Instantly share code, notes, and snippets.

@na0x2c6
na0x2c6 / functions.php
Created March 21, 2020 11:08
WordPress: get the paged number
<?php
add_action('wp_head', function() {
$paged = get_query_var('paged');
});
@na0x2c6
na0x2c6 / functions.php
Last active March 21, 2020 10:02
WordPress: An example for adding noindex attribute to a page
<?php
add_action( 'wp_head', function() {
if(!(is_single() || is_page())){
return;
}
$value = get_post_meta(get_the_ID(), 'is_noindex', true );
if(!((int)$value)) {
return;
}
wp_no_robots();
@na0x2c6
na0x2c6 / HOCSample-3_2.jsx
Created October 31, 2018 02:32
Inheritance Inversion Sample 2
function addPrefixToName(WrappedComponent, prefix) {
return class extends WrappedComponent {
render() {
const wrappedTree = super.render()
let newProps = {}
if (wrappedTree && wrappedTree.type === 'input') {
newProps = {name: `${prefix}-${wrappedTree.props.name}`}
}
const props = { ...wrappedTree.props, ...newProps } // Object.assign({}, wrappedTree.props, newProps) と同様
const newTree = React.cloneElement(wrappedTree, props, wrappedTree.props.children)
@na0x2c6
na0x2c6 / HOCSample-3_1.jsx
Created August 28, 2018 09:21
Inheritance Inversion Sample 1
function showMessageWhenDataIsEmpty(WrappedComponent) {
return class extends WrappedComponent {
render() {
if (this.props.data.length > 0) { // データが存在するときだけ表示
return super.render()
}
else {
return <span>データが存在しません!</span>
}
}
@na0x2c6
na0x2c6 / HOCSample-3.jsx
Created August 28, 2018 07:55
HOC Sample 3:Inheritance Inversion
function withSubscription(WrappedComponent, selectData) {
return class extends WrappedComponent {
constructor(props) {
super(props)
this.handleChange = this.handleChange.bind(this)
this.state = {
data: selectData(DataSource, props)
}
}
function withSubscription(WrappedComponent, selectData) {
return class extends React.Component {
constructor(props) {
super(props)
this.handleChange = this.handleChange.bind(this)
this.state = {
data: selectData(DataSource, props)
}
}
@na0x2c6
na0x2c6 / HOCSample-2.jsx
Last active August 24, 2018 09:09
HOC Sample 2: Props Proxy
function withSubscription(WrappedComponent, selectData) {
return class extends React.Component {
constructor(props) {
super(props)
this.handleChange = this.handleChange.bind(this)
this.state = {
data: selectData(DataSource, props)
}
}
@na0x2c6
na0x2c6 / HOCSample-1.jsx
Created August 22, 2018 09:01
HOC Sample 1: No HOC
const Card = ({ card }) => (
<div className="card">
<div className="card-content" style={{ color: card.color }}>
{card.name}
</div>
</div>
)
class List extends React.Component {
constructor(props) {
@na0x2c6
na0x2c6 / .htaccess
Last active April 10, 2018 04:33
【改訂版】WordPressテーマを一般ファイルで使う ref: https://qiita.com/cellolism/items/4d06ff73779c8da2e170
<IfModule mod_rewrite.c>
### WordPress 用 ####
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index\.php$ - [L]
#####################
@na0x2c6
na0x2c6 / .htaccess
Last active April 3, 2018 15:16
WordPressテーマを一般ファイルで使う ref: https://qiita.com/cellolism/items/ddcbf6d9726189aa0e37
<IfModule mod_rewrite.c>
### WordPress 用 ####
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index\.php$ - [L]
#####################