Skip to content

Instantly share code, notes, and snippets.

@marushu
marushu / past_date.php
Created November 18, 2011 21:26
投稿日付の計算
<?php $posts = get_posts(array('post_type' => 'one_line_comment', 'taxonomy' => 'span', 'posts_per_page' => 5, 'order' => 'ASC')); foreach($posts as $post) : setup_postdata($post); //1行コメントの改訂版 ?>
<?php
$key = "表示期間"; //カスタムフィールドの項目名(label)
$value = get_post_meta($post->ID, $key, true); //カスタムフィールドに入れた日数を格納
//↑↑ココまでがカスタムフィールドの項目を出力する部分
$value_unix = $value * 24 * 60 * 60;
//▼ここで日付を整形。sbustrで最初の文字から○文字を抜き出し(一文字目は「0(ゼロ)」)、str_replaceで置き換えたい文字と置き換える文字を指定。
$toukoubi = str_replace("-", "/", substr($post->post_date, 0, 10)); //投稿日の日付 YYYY/mmmm/dddd
$last_modified_day = str_replace("-", "/", substr($post->post_modified, 0, 10)); //最終編集日の日付 YYYY/mmmm/dddd
//▲ここで日付を整形。sbustrで最初の文字から○文字を抜き出し(一文字目は「0(ゼロ)」)、str_replaceで置き換えたい文字と置き換える文字を指定。
@marushu
marushu / gist:1378425
Created November 19, 2011 04:05 — forked from miya0001/gist:1378387
指定された期限内の記事だけを取得する
<?php
/*
現在の日時から2日後のタイムスタンプを保存する
$d = 2 * 60 * 60 * 24; // 2日間
$expire = current_time('timestamp', get_option("gmt_offset")) + $d;
update_post_meta($post->ID, '_expire', $expire);
@marushu
marushu / gist:1385012
Created November 22, 2011 06:02
get_postsを使って投稿を投稿日から指定した期間投稿を表示させる
<?php
$args = array (
'post_type' => 'one_line_comment',
'taxonomy' => 'span',
'post_per_page' => 5,
'order' => 'ASC',
'meta_key' => $disply_limit,
'meta_value' => $now,
'meta_compare' => '>'
@marushu
marushu / add_custom_field_meta_box
Created November 23, 2011 14:47
テキストボックスをカスタムフィールドへ追加する(register_meta_box_cbではない)
<?php
//▼テキストボックスをカスタムフィールドへ追加する
/* フォーム表示 */
function html_source_for_layout_custom_box() {
$c_text = get_post_meta( $_GET['post'], 'c_text' );
echo '<label for="c_text">テキスト</label> ';
echo '<input type="text" name="c_text" value="'.$c_text[0].'">';
}
@marushu
marushu / gist:1389104
Created November 23, 2011 16:20
register_post_type()の引数であるregister_meta_box_cbのコールバック巻数
<?php
/****************************************************************************/
/* ! ▼register_post_typeのregister_meta_box_cbのコールバックここから
参考URL:http://wpxtreme.jp/how-to-use-custom-post-types-in-wordpress-3-0-beta1
http://wpdocs.sourceforge.jp/関数リファレンス/add_meta_box
http://ja.forums.wordpress.org/topic/4693?replies=4
*/
@marushu
marushu / list_fade
Created November 24, 2011 02:17
リストをfadeIn, fadeOutさせる。リストが一つの場合fadeなし
<script type="text/javascript">
$(function() {
$.fn.slide = function(config) {
// 引数がない場合のデフォルト値の設定
config = $.extend({
loopSpeed: 3000,
fadeInSpeed: 2000,
fadeOutSpeed: 2000
}, config);
@marushu
marushu / future_delete.php
Created December 3, 2011 01:36
指定した日数投稿を非表示にする
<?php
/****************************************************************************/
/* ! ▼register_post_typeのregister_meta_box_cbのコールバックここから
参考URL:http://wpxtreme.jp/how-to-use-custom-post-types-in-wordpress-3-0-beta1
http://wpdocs.sourceforge.jp/関数リファレンス/add_meta_box
http://ja.forums.wordpress.org/topic/4693?replies=4
*/
@marushu
marushu / list_animateion.js
Created December 3, 2011 01:41
リストをアニメーションさせる。右から左へ
<script type="text/javascript">
$(function() {
var _li = $("li.one_line_news");
var _ul = $("#one_line");
var _li_width = 877;
var _li_size = _li.size();
var _numberOf_li = _li_size - 1;
var _count = 0;
var _ul_width = _li_width * _li_size;
var _ul_margin = 0;
<?php
/**
* The main template file.
*
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* E.g., it puts together the home page when no home.php file exists.
* Learn more: http://codex.wordpress.org/Template_Hierarchy
*
@marushu
marushu / gist:4199313
Created December 4, 2012 00:19
PHP: test php code
<?php //its a test php code ?>