フォーラムへの返信

15件の返信を表示中 - 1 - 15件目 (全77件中)
  • トピック投稿者 meijinochoco

    (@meijinochoco)

    何を意味するか…すみません。かなりわからないです(>_<)
    お助け頂けませんでしょうか…。。

    トピック投稿者 meijinochoco

    (@meijinochoco)

    ありがとうございます!
    >WordPressのパーマリンクを自由自在にカスタマイズ
    これはイケそうな手ごたえですね。

    ①functions.phpへの追記
    ②管理画面のパーマリンク設定で「変更を保存」をクリック
    ③arcive.phpへの追記

    のうち、

    ①②によって、
    ・http://example.com/fluits/apple
    ・http://example.com/fluits/grape
    ・http://example.com/fluits/banana
    いずれにアクセスしても404にはいかなくなりました。

    どうやら「http://example.com/meta_key/meta_value」というルールの追加はできたようす。

    問題は③です。(>_<)

    arcive.phpへの記載ですが、たとえば次のようなテンプレートでは、どこかおかしいところはございますでしょうか…?

    下記ですと「content-none.php」が読み込まれてしまうという状況です。

    ▼arcive.php

    
    <?php get_header(); ?>
    
    <!--今回の追記部分-->
    <?php
    if ( $meta_key = get_query_var('fluits') && $meta_value = get_query_var('apple') ) {
      query_posts( array('meta_key'=>$meta_key, 'meta_value'=>$meta_value) );
    }
    ?>
    
    <!--以下は元々あるもの-->
    <div id="contents">
    	
      <div class="listtitle">			
        <h2><?php echo $tag ?>の記事一覧</h2>
      </div>			
    
      <div id="container">		
    		
        <?php if ( have_posts() ) : ?>
    		
          <div class="masonry" class="clearfix">
            <?php while ( have_posts() ) : the_post(); ?>
              <?php get_template_part( 'template-parts/content', get_post_format() );	?>
            <?php endwhile; ?>
    		
    	<?php else : ?>
    
              <?php get_template_part( 'template-parts/content', 'none' ); ?>
    
    	<?php endif; ?>
    	
          </div>
    		
            <?php pingraphy_the_posts_navigation(); ?>
    		
      </div>
    
    </div>
    	
    <?php get_footer(); ?>
    トピック投稿者 meijinochoco

    (@meijinochoco)

    ありがとうございます。
    「なぜ、タグでもカテゴリでもカスタム分類でもなく、カスタムフィールドなのか?」と言うと、ユーザーが投稿するサイトでして、そのユーザー投稿機能を実装するにあたってカスタムフィールドしか選択できない仕様になっているからなのです。タグを選択できれば解決なのですが、それは前提としてナシなのです。すみません。
    いつもアドバイス感謝です。

    トピック投稿者 meijinochoco

    (@meijinochoco)

    初心者の不勉強なコードと意見で大変恐縮なのですけれど、なにかもっと、こう、、、

    たとえばカテゴリアーカイブページって、「テンプレート1枚(arcive.php)」で作動するじゃないですか?

    でも現状の私の解決策だと「テンプレート1枚(page-tags.php)+カスタムフィールドの値の数と同じ数の固定ページ(apple.banana,grape)」が必要でして、これではカスタムフィールドの値を追加するたびにいちいち固定ページを作らなくちゃならないところがちょっとイヤな感じなのです。(;’∀’)

    リンク先ありがとございます。勉強してきます。

    トピック投稿者 meijinochoco

    (@meijinochoco)

    はい。事情ありです。どうしてもカスタムフィールド名をタグとして扱いたいのです。
    せっかくアドバイス頂いたのにすみません。。

    ちなみに現状では、タグとして扱っているカスタムフィールド名の数だけ固定ページを作り、
    ・http://example.com/fluits/apple
    ・http://example.com/fluits/grape
    ・http://example.com/fluits/banana
    これらの共通テンプレート「page-tags」に下記を書いて対応しております。

    もし下記について、「もっとこうしたらどう?」などのご意見をいただけましたら幸いです。

    <?php
    /*
    Template Name: page-tags
    */
    get_header(); ?>
    
    <?php 			
      $url = $_SERVER["REQUEST_URI"];
      $str = str_replace('/', '', $url);
      $tag = urldecode($str);
    ?>
    
    <div id="contents">
    	
      <div class="listtitle">			
        <h2><?php echo $tag ?>の記事一覧</h2>
      </div>			
    
      <div id="container">
    		
        <!--post-->
        <?php $args = Array(		
          'post_type' => 'post',
          'posts_per_page' => -1,
          'meta_key' => 'tag_post',
          'meta_value' => $tag
        );
        $the_query = new WP_Query($args);
        if($the_query -> have_posts()):
          while($the_query -> have_posts()): $the_query -> the_post();
    
            get_template_part( 'template-parts/list', 'post' );
    
          endwhile;
        endif;
        wp_reset_postdata(); ?>
    		
        <!--custom1-->
        <?php $args = Array(			
          'post_type' => 'custom1',
          'posts_per_page' => -1,
          'meta_key' => 'tag_custom1',
          'meta_value' => $tag
        );
        $the_query = new WP_Query($args);
        if($the_query -> have_posts()):
          while($the_query -> have_posts()): $the_query -> the_post();
    
            get_template_part( 'template-parts/list', 'custom1' );
    
          endwhile;
        endif;
        wp_reset_postdata(); ?>
    
        <!--custom2-->
        <?php $args = Array(			
          'post_type' => 'custom2',
          'posts_per_page' => -1,
          'meta_key' => 'tag_custom2',
          'meta_value' => $tag
        );
        $the_query = new WP_Query($args);
        if($the_query -> have_posts()):
          while($the_query -> have_posts()): $the_query -> the_post();
    
            get_template_part( 'template-parts/list', 'custom2' );
    
          endwhile;
        endif;
        wp_reset_postdata(); ?>
    		
      </div>
    	
        <?php pingraphy_the_posts_navigation(); ?>
    		
    </div>
    
    <?php get_footer(); ?>
    フォーラム: 使い方全般
    返信が含まれるトピック: 「wp list comments」でアバターを指定する方法
    トピック投稿者 meijinochoco

    (@meijinochoco)

    できました。めっっっっちゃうれしいです。

    <div class="author_left">
    	<?php $user = get_userdata( $post->post_author );
    	gravatarToID($post->txt_name, 50, 'identicon'); ?>			
    </div>

    仕様をご説明いただいたからこそ、じゃあここに$post->txt_nameって書けばいいのかな、と意味がわかりました。m(_ _)m

    なんどもなんどもご返信頂き本当にどうもありがとうございます!
    心から感謝申し上げます。

    • この返信は4年、 10ヶ月前にmeijinochocoが編集しました。
    フォーラム: 使い方全般
    返信が含まれるトピック: 「wp list comments」でアバターを指定する方法
    トピック投稿者 meijinochoco

    (@meijinochoco)

    なるほどなるほど。そのような仕様が理由でしたか。お聞きしなければ絶対にわかりませんでした。ありがとうございます。少しわかってきました。

    さて、次のようにしたところ「私の名前」がaltやtitleに入るようになりました。

    <div class="author_left">
    	<?php $user = get_userdata( $post->post_author );
    	gravatarToID($user->display_name, 50, 'identicon'); ?>			
    </div>

    ただ、ユーザーが投稿する記事なので「ユーザーが入力した名前」がaltやtitleには入ってほしいと思いっております。つまり、

    // 下記のどれか必要なものをご自身で選んで使います
    // $user->xxx_xxxx : WP user frontedでユーザーが入力した名前

    という感じのものはありませんでしょうか?
    (ないですよね、そんな都合のよいものは…)

    尚、名前の入力はカスタムフィールド名「txt_name」に入っています。
    下記の参考リンクにある「カスタムフィールド追加時の注意点」という副題で記載されているMeta Keyとして設定したのが「txt_name」です。

    ※WP user fontedというのはユーザーが記事を投稿できるようになるプラグインです。
    参考:https://website-homepage.com/wordpress/plugin/useful/user-frontend/#i

    フォーラム: 使い方全般
    返信が含まれるトピック: 「wp list comments」でアバターを指定する方法
    トピック投稿者 meijinochoco

    (@meijinochoco)

    はい。こちらからコピペしたものです。
    https://webbingstudio.com/weblog/cms/entry-113.html

    その部分を「$post->post_author」にすると、アバター画像のaltとtitileに「1」が入りました。ただし、アバター画像は変化なしで、どんな投稿者名でも同じアバター画像が出力されてしまうのです。「global $post;$post->post_author」としても同様です。

    • この返信は4年、 10ヶ月前にmeijinochocoが編集しました。
    • この返信は4年、 10ヶ月前にmeijinochocoが編集しました。
    • この返信は4年、 10ヶ月前にmeijinochocoが編集しました。
    • この返信は4年、 10ヶ月前にmeijinochocoが編集しました。
    フォーラム: 使い方全般
    返信が含まれるトピック: 「wp list comments」でアバターを指定する方法
    トピック投稿者 meijinochoco

    (@meijinochoco)

    親身になってご回答くださっていつもありがとうございます。

    あれからコメント部分のアバターは下記のようにして、名前ごとに変わるようにできました。
    【comments.php】に「callback」を付けて、【functions.php】の「mytheme_comment」を呼び出した形です。

    しかし、記事部分の投稿者アバターが全て一緒になってしまうという症状に悩んでいます。
    <!–★–>の部分です。
    ちなみにこの部分を「$post->post_author」にすると、アバターのaltとtitileに「1」が入りました。
    「$comment->comment_author」のままだとなんの値も入らず空っぽです。
    もちろん実際には1でも空っぽでもなく、投稿者名が入ってほしいのですが。

    どうしたら記事部分の投稿者アバターも名前ごとに変わるようにできるのかについて、何かご指導いただけませんでしょうか…

    ▼【functions.php】

    /*-------------------------------------------*/
    /*	投稿者名でアバター生成
    /*-------------------------------------------*/		
    function gravatarToID($id="名無しさん", $size=50, $type="identicon") {
    	$hashid = md5(md5($id));
    	if ($size > 512) { $size = 512; }
    
    	$img = "<img src=\"";
    	$img .= "https://www.gravatar.com/avatar/";
    	$img .= $hashid;
    	$img .= "?d=";
    	$img .= $type;
    	$img .= "&?s=";
    	$img .= $size;
    	$img .= "\" width=\"";
    	$img .= $size;
    	$img .= "\" height=\"";
    	$img .= $size;
    	$img .= "\" alt=\"";
    	$img .= $id;
    	$img .= "\" title=\"";
    	$img .= $id;
    	$img .= "\" class=\"comment-avatar\" />";
    	echo $img;
    }
    /*-------------------------------------------*/
    /*	コメントフォーム変更
    /*-------------------------------------------*/	
    function mytheme_comment($comment, $args, $depth) {
        if ( 'div' === $args['style'] ) {
            $tag       = 'div';
            $add_below = 'comment';
        } else {
            $tag       = 'li';
            $add_below = 'div-comment';
        }
        ?>
        <<?php echo $tag ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID() ?>">
        <?php if ( 'div' != $args['style'] ) : ?>
            <div id="div-comment-<?php comment_ID() ?>" class="comment-body">
        <?php endif; ?>
     
    			<div class="author_flex">
    			<!-- アバター -->		
    				<div class="author_left">
    					<?php echo gravatarToID($comment->comment_author, 50, 'identicon'); ?>
    				</div>
    				<div class="author_right">
    			<!-- 名前 -->
    					<div class="author_name">
    						<?php printf( __( '%s' ), get_comment_author_link() ); ?>
    					</div>			
    			<!-- 日付 -->
    					<div class="author_date"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>">
    						<?php
    						/* translators: 1: date, 2: time */
    						printf( __('%1$s at %2$s'), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), '  ', '' );
    						?>
    					</div>
    				</div>
    			</div>
    			<!-- 内容 -->
    			<div class="comment-content">
    				<?php comment_text(); ?>
    			</div>
    			<!-- 返信ボタン -->
    			<div class="reply">
    				<?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
    			</div>	
    		
    		<?php if ( 'div' != $args['style'] ) : ?>
    		</div>
    		<?php endif; ?>
    <?php
    }

    ▼【comments.php】

    <?php if ( have_comments() ) : ?>
    	<ol class="comment-list">
    		<?php
    			wp_list_comments( array(
    				'style'      => 'ol',
    				'max_depth'  => '2',
    				'callback'   => 'mytheme_comment', 
    				'per_page'   => '100',
    				'reply_text' => 'コメント <i class="fa fa-comment"></i>',
    				'short_ping' => true,
    				'reverse_top_level' => true,
    				'reverse_children' => true 
    			) );
    		?>
    	</ol><!-- .comment-list -->
    <?php endif; // Check for have_comments(). ?>

    ▼【content-custom.php】

    <div class="author_flex">
    	<div class="author_left">
    		<!--★-->
    		<?php gravatarToID($comment->comment_author, 50, 'identicon'); ?>			
    	</div>
    	<div class="author_right">
    		<div class="author_name"><?php echo esc_html( $post->txt_name ); ?></div>
    		<div class="author_date"><?php the_time('Y/m/d g:i A') ;?></div>
    	</div>
    </div>	
    • この返信は4年、 10ヶ月前にmeijinochocoが編集しました。
    • この返信は4年、 10ヶ月前にmeijinochocoが編集しました。
    フォーラム: 使い方全般
    返信が含まれるトピック: 「wp list comments」でアバターを指定する方法
    トピック投稿者 meijinochoco

    (@meijinochoco)

    ありがとうございます。参考にがんばってみます。

    トピック投稿者 meijinochoco

    (@meijinochoco)

    「WP Random Post Thumbnails」で投稿タイプを指定するときに、通常の投稿タイプも指定しておくことで解決いたしました。

    • この返信は4年、 10ヶ月前にmeijinochocoが編集しました。
    フォーラム: 使い方全般
    返信が含まれるトピック: 配列[0]の中身を分割する方法
    トピック投稿者 meijinochoco

    (@meijinochoco)

    できました!わざわざ書かせてしまってすみません。いつもどうもありがとうございます。

    フォーラム: 使い方全般
    返信が含まれるトピック: 投稿時に、自動でタグにチェックを入れる方法
    トピック投稿者 meijinochoco

    (@meijinochoco)

    いえ、予想でもプロの方のご意見というのはいつだって参考になります。ありがとうございます。

    無料版の使用にあたり一部機能が薄いグレーで表示されており、クリックすると「この機能を使いたかったらプロ版をよろしくね」という案内が表示されるのですが、どうも薄いグレーとしてさえタグは表示されていないようなので、ちょっと突っ込んで聞いてしまいました。失礼しました。

    フォーラム: 使い方全般
    返信が含まれるトピック: 配列[0]の中身を分割する方法
    トピック投稿者 meijinochoco

    (@meijinochoco)

    ありがとうございます。挑戦中です。なかなか難しいですね。

    フォーラム: 使い方全般
    返信が含まれるトピック: 投稿時に、自動でタグにチェックを入れる方法
    トピック投稿者 meijinochoco

    (@meijinochoco)

    ありがとうございます。ほんとですか!?タグ機能がそもそもないように思えるのですが、それはどこに書いてありますでしょうか?

15件の返信を表示中 - 1 - 15件目 (全77件中)