商品新規追加における投稿フォーマット(post_formats)

フォーラム 使い方全般 商品新規追加における投稿フォーマット(post_formats)

  • このトピックには3件の返信、2人の参加者があり、最後にthetarbreにより11年、 7ヶ月前に更新されました。
4件の投稿を表示中 - 1 - 4件目 (全4件中)
  • 投稿者
    投稿
  • #51809
    thetarbre
    参加者

    初めまして。

    Welcartを最近利用させていただき始めました。作りこんであり、とても便利なプラグインなのでとても助かっております!!

    Welcartでは商品情報の記載はポスト形式を利用していると理解しておりますが、新規商品追加の際、投稿フォーマットを商品情報に適用することは可能なのでしょうか?

    私が使用しているテーマは投稿フォーマットを使用して各ポストのスタイルを変えられ、商品によって、投稿スタイルを変えたいのですが。。。

    初心者なりにグーグルなどで調べた結果、

    if (current_theme_supports( ‘post-formats’ , $post_type)) {

    add_theme_support( ‘post-formats’, array( ‘aside’, ‘gallery’, ‘link’, ‘image’, ‘quote’, ‘video’, ‘audio’ ) );

    }

    if ( current_theme_supports( ‘post-formats’ ) && post_type_supports( $post->post_type, ‘post-formats’ ) && get_option( ‘default_post_format’ ) )

    set_post_format( $post, get_option( ‘default_post_format’ ) );

    などを’admin_func.php’にインサートしてみましたが、効果がありませんでした。

    もし可能であればアドバイスをお願いいたします。

    動作に関するご質問の場合は必ずご記入ください。


    WordPress のバージョン:3.4.1

    Welcart のバージョン:1.1.10

    ご利用のテーマ:smartstart

    症状を確認したブラウザ:chrome, firefox, ie, safari

    サーバー(会社名、サービス名):localhost(xampp)

    SSLの利用: 無し

    WordPress のパーマリンク設定:/%category%/%year%/%postname%/


    #65395
    nanbu
    キーマスター

    こんにちは。

    Welcartの商品のpost_typeはpostで固定となっております。また、残念ながらpost-formatsのも対応しておりません。

    #65396
    thetarbre
    参加者

    早速の回答ありがとうございました。

    また何かありましたら、ご指導お願い致します。

    #65397
    thetarbre
    参加者

    プラグインファイルにコードを挿入するのは最善の方法でないのは理解しておりますが、検索の結果、上記の質問の臨時対処法を見つけましたのでそのコードスニペットをお知らせいたします。

    (カスタマイズ時におけるプラグインのプラグイン制作などのアドバイスやよい情報のサイトがあれば是非ご指導願います。)

    ソース元の内容は私の質問と少し違いがありますがこちらがソースのURLです。

    http://wordpress.stackexchange.com/questions/16136/different-post-format-options-per-custom-post-type

    // Register all post types that we will use

    add_action( ‘after_setup_theme’, ‘wpse16136_after_setup_theme’, 11 );

    function wpse16136_after_setup_theme()

    {

    add_theme_support( ‘post-formats’, array( ‘aside’, ‘gallery’, ‘video’ ) );

    }

    // Register our custom post type, and link the post formats to the post types

    // Yes, you can (ab)use add_post_type_support to save extra data like this

    add_action( ‘init’, ‘wpse16136_init’ );

    function wpse16136_init()

    {

    register_post_type( ‘wpse16136’, array(

    ‘public’ => true,

    ‘label’ => ‘WPSE 16136’,

    ‘supports’ => array( ‘title’, ‘editor’ ),

    ) );

    add_post_type_support( ‘wpse16136’, ‘post-formats’, array( ‘gallery’, ‘video’ ) );

    add_post_type_support( ‘post’, ‘post-formats’, array( ‘aside’, ‘gallery’ ) );

    }

    // Replace the standard meta box callback with our own

    add_action( ‘add_meta_boxes’, ‘wpse16136_add_meta_boxes’ );

    function wpse16136_add_meta_boxes( $post_type )

    {

    if ( ! get_post_type_object( $post_type ) ) {

    // It’s a comment or a link, or something else

    return;

    }

    remove_meta_box( ‘formatdiv’, $post_type, ‘side’ );

    add_meta_box( ‘wpse16136_formatdiv’, _x( ‘Format’, ‘post format’ ), ‘wpse16136_post_format_meta_box’,

    $post_type, ‘side’, ‘core’ );

    }

    // This is almost a duplicate of the original meta box

    function wpse16136_post_format_meta_box( $post, $box ) {

    if ( current_theme_supports( ‘post-formats’ ) && post_type_supports( $post->post_type, ‘post-formats’

    ) ) :

    $post_formats = get_theme_support( ‘post-formats’ );

    // This is our extra code

    // If the post type has registered post formats, use those instead

    if ( is_array( $GLOBALS[$post->post_type] ) ) {

    $post_formats = $GLOBALS[$post->post_type];

    }

    if ( is_array( $post_formats[0] ) ) :

    $post_format = get_post_format( $post->ID );

    if ( !$post_format )

    $post_format = ‘0’;

    $post_format_display = get_post_format_string( $post_format );

    // Add in the current one if it isn’t there yet, in case the current theme doesn’t support it

    if ( $post_format && !in_array( $post_format, $post_formats[0] ) )

    $post_formats[0][] = $post_format;

    ?>

    <div id=”post-formats-select”>

    <input type=”radio” name=”post_format” class=”post-format” id=”post-format-0″ value=”0″ <?php

    checked( $post_format, ‘0’ ); ?> /> <label for=”post-format-0″><?php _e(‘Standard’); ?></label>

    <?php foreach ( $post_formats[0] as $format ) : ?>

    <input type=”radio” name=”post_format” class=”post-format” id=”post-format-<?php echo

    esc_attr( $format ); ?>” value=”<?php echo esc_attr( $format ); ?>” <?php checked( $post_format, $format

    ); ?> /> <label for=”post-format-<?php echo esc_attr( $format ); ?>”><?php echo esc_html(

    get_post_format_string( $format ) ); ?></label>

    <?php endforeach; ?>

    </div>

    <?php endif; endif;

    }

    重ね重ね、素晴らしく助けになるプラグインの開発本当に有難うございます。

4件の投稿を表示中 - 1 - 4件目 (全4件中)
  • このトピックに返信するにはログインが必要です。