• 解決済 モグラ

    (@tenpra)


    <ul>
    <li><a href="<?php echo add_query_arg( array('sort' => 'date', 'order' => 'DESC') ); ?>">投稿が新しい順</a></li>
    <li><a href="<?php echo add_query_arg( array('sort' => 'date', 'order' => 'ASC') ); ?>">投稿が古い順</a></li>
    </ul>
    
    	<ul>
    		<?php
    		$type = get_query_var( "news-cat" );
    		$args = array(
    			"post_type" => array( "news" ),
    			"tax_query" => array(
    				"relation" => "OR",
    				array(
    					"taxonomy" => "news-cat",
    					"field" => "slug",
    					"terms" => $type,
    				),
    			),
    			"paged" => $paged,
    			"posts_per_page" => "-1"
    		);
    		$the_query = new WP_Query( $args );
    		if ( $the_query->have_posts() ): ?>
    		<?php while ($the_query->have_posts()): $the_query->the_post(); ?>
    		<li> ~ </li>
    		<?php endwhile; ?>
    		<?php wp_reset_postdata(); ?>
    		</ul>

    上記ソースで、タクソノミー一覧ページで日付順ソートボタンを設置したいのですが、ソートボタンが効きません。

    記事一覧に影響を及ぼすプラグインも仕様していません。

    どなたか同じような現象をご存じでしょうか?

    ご教授頂けると助かります。

    • このトピックはモグラが9ヶ月前に変更しました。
1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック投稿者 モグラ

    (@tenpra)

    <ul>
    <li><a href="<?php echo add_query_arg( array('sort' => 'date', 'order' => 'DESC') ); ?>">投稿が新しい順</a></li>
    <li><a href="<?php echo add_query_arg( array('sort' => 'date', 'order' => 'ASC') ); ?>">投稿が古い順</a></li>
    </ul>
    <?php $url = $_SERVER['REQUEST_URI']; ?>
    <?php if ( strstr($url,'?sort=date&order=DESC')==true ):
    	$orderbySet = 'date';
    	$orderSet = 'DESC';
    	elseif ( strstr($url,'?sort=date&order=ASC')==true ):
    	$orderbySet = 'date';
    	$orderSet = 'ASC';
    	else:  endif; ?>
    	<ul>
    		<?php
    		$type = get_query_var( "news-cat" );
    		"order" => $orderSet,
    		"orderby" => $orderbySet,
    		$args = array(
    			"post_type" => array( "news" ),
    			"tax_query" => array(
    				"relation" => "OR",
    				array(
    					"taxonomy" => "news-cat",
    					"field" => "slug",
    					"terms" => $type,
    				),
    			),
    			"paged" => $paged,
    			"posts_per_page" => "-1"
    		);
    		$the_query = new WP_Query( $args );
    		if ( $the_query->have_posts() ): ?>
    		<?php while ($the_query->have_posts()): $the_query->the_post(); ?>
    		<li> ~ </li>
    		<?php endwhile; ?>
    		<?php wp_reset_postdata(); ?>
    		</ul>

    上記コードで自己完結しました。

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック「タクソノミー一覧ページで日付順ソートボタンが効かない」には新たに返信することはできません。