2017-04-18 20 views
0

私はこの名簿をJersey Numberで注文しようとしていますが、それを動作させることはできませんでした。私はプログラマーではなく、この作品を何度も検索して試してみました。このPHPコードで変数を使用して注文するにはどうすればよいですか?

ありがとうございました。ここで

http://onramp.website/rosters-2017/17u-navy/

出力のPHPコードです:あなたが何をしようとして

<?php get_header(); ?> 

<?php wp_reset_query(); ?> 


<?php 
$post_name = $post->post_name; 

if ($post_name == "17u-navy") { 
$post_type = "17u_navy"; 
} 

elseif ($post_name == "15u-navy") { 
$post_type = "15u_navy"; 
} 

elseif ($post_name == "17u-red") { 
$post_type = "17u_red"; 
} 

elseif ($post_name == "17u-white") { 
$post_type = "17u_white"; 
} 

elseif ($post_name == "17u-gold") { 
$post_type = "17u_gold"; 
} 

$args = array('post_type'=>$post_type,'posts_per_page'=>-1, 'orderby' => 'number', 'order' => 'ASC',); 
$the_query = new WP_Query($args); 
$flag = 0; 

if ($the_query->have_posts()): 
?> 




<?php while ($the_query->have_posts()): $the_query->the_post(); ?> 

<?php 
$flag++; 
?> 

<?php if ($flag == 999): ?> 

<?php $flag = 0; ?> 





<?php endif; ?> 



<h3 class="h-custom-headline cs-ta-left h4 accent"><span><?php the_title(); ?> &nbsp; #<?php the_field('number'); ?></span></h3> 

<div id="x-section-2" class="x-section" style="margin: 0px 0px 25px 0px;padding: 0px; background-color: transparent; margin-bottom: 50px;"> 
<div class="x-column x-sm x-1-5" style="padding: 0px;"> 
<img class="x-img x-img-none" src="<?php the_field('profilephoto'); ?>"> 
</div> 
<div class="x-column x-sm x-4-5" style="padding: 0px;"> 
<ul class="x-block-grid two-up"> 
<li class="x-block-grid-item"><strong>Class of <?php the_field('gradyear'); ?></strong><br /> 
<strong>Height:</strong> <?php the_field('height'); ?><br /> 
<strong>Position:</strong> <?php the_field('position'); ?><br /> 
<?php if(get_field('bballhonors')): ?> 
<strong>Basketball Honors:</strong> <?php the_field('bballhonors'); ?><br /> 
<?php endif; ?> 
<?php if(get_field('ncaaclearing')): ?> 
<strong>NCAA Clearing House:</strong> <?php the_field('ncaaclearing'); ?><br /> 
<?php endif; ?> 
<?php if(get_field('highlightfilm')): ?> 
<strong>Highlight Film:</strong> <a href="<?php the_field('highlightfilm'); ?>" target="_blank">link</a> 
<?php endif; ?> 
<?php if(get_field('hobbies')): ?> 
<strong>Hobbies:</strong> <?php the_field('hobbies'); ?> 
<?php endif; ?> 
</li> 
<li class="x-block-grid-item"> 
<strong>High School:</strong> <?php the_field('highschool'); ?><br /> 
<strong>Hometown:</strong> <?php the_field('citystate'); ?><br /> 
<?php if(get_field('gpa')): ?> 
<strong>GPA:</strong> <?php the_field('gpa'); ?><br /> 
<?php endif; ?> 
<?php if(get_field('sat')): ?> 
<strong>SAT:</strong> <?php the_field('sat'); ?><br /> 
<?php endif; ?> 
<?php if(get_field('schoolhonors')): ?> 
<strong>School Honors:</strong> <?php the_field('schoolhonors'); ?><br /> 
<?php endif; ?> 
<?php if(get_field('favoritequote')): ?> 
<strong>Favorite Quote:</strong><em><br />"<?php the_field('favoritequote'); ?>"</em><br /> 
<?php if(get_field('author')): ?> 
~&nbsp;<?php the_field('author'); ?> 
<?php endif; ?><?php endif; ?></li> 
</ul> 
</div> 
</div> 





<?php endwhile; ?> 

<?php endif; ?> 

答えて

0

は、単純なようで、適切なツールと非常にシンプルですが、のような何かをしようとしていますジャージー番号を抽出し、WP_Queryの混乱を残すことになっている投稿を注文すると、ちょっとひどい考えです。

投稿の順番で「ごまかす」にはいくつかの方法があります。

カスタムポストオーダーを作成できるプラグインを手に入れることができますが、これはWP_Queryを使用して注文を破棄して 'ロック'するので、できる限り避けるようにしています。

「高度なカスタムフィールド」と呼ばれるプラグインを入手し、新しいフィールドを作成して、そこにジャーナル番号を書き込んで、そのフィールドでクエリを並べ替えることができます。

繰り返しフィールドごとに1つの投稿を選択して、必要な順序で投稿を1つずつ追加することができる無制限のリピータフィールドを作成することもできます。これにより、クエリとテンプレートを構造化する方法が変わりますそれは少し複雑です。

(また、冒頭にIFSの連鎖が見て恐ろしいです。それは、後の管理の面で痛みにつながるだろう。私は:(私はちょうどテンプレートを書いて、それをテストすることができたいと思います)

+0

感謝Joris! $ args = array( 'post_type' => $ post_type、 'posts_per_page' => - 1、 'meta_key' => '数字'、 'orderby' => 'len(数値)、meta_value'、 '注文'=> 'ASC'); $ the_query =新しいWP_Query($ argsを); $フラグ= 0; 私は実際にはほとんども、高度なカスタムフィールドを使用して、ちょうど働いていたものを見つけてい 私が使用していました。 aロブスターは番号に基づいて再注文されました。 しかし、正確には正しくありません。あなたが見ると、彼らはすべて上昇するが、#5は最後にある。数字を「文字通り」注文する方法はありますか? @ joris-g –

+0

私が探しているのは、 "Natural"の代わりに "Standard"ソートを使用する方法です。 –

+0

プログラミング言語では、文字列の間に違いがあります。文字列には、「hello2」などのテキストと、5などの純粋な整数が含まれます(「 'がないことに注意してください)。 'number'フィールドは実際には#で始まる文字列として解釈されます。ソートアルゴリズムのチェックでは、最初はすべて#であることが分かり、2番目の 'letter'が取り出されます。これは数字であり、それによってソートされます。 17Uネイビーのページにあるジャージーの数字で分かるように、1 1 1 2 2 2 3 3 4 5です。 –

関連する問題