我正在试着按泽西号码来排序这个花名册,但一直没能让它工作。我不是一个程序员,我已经搜索并尝试过多次让它工作。
非常感谢你的帮助。
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(); ?> #<?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') ): ?>
~ <?php the_field('author'); ?>
<?php endif; ?><?php endif; ?></li>
</ul>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>发布于 2017-04-19 04:47:56
你要做的事情看起来很简单,使用正确的工具也很简单,但尝试做一些事情,比如提取泽西号,然后按此对帖子进行排序,将会留下一个混乱的WP_Query,这是一个可怕的想法。
在邮购方面,有几种方法可以“作弊”。
你可以得到一个插件,它允许你创建一个自定义的post订单,但这打破了通过WP_Query的排序并“锁定”它,所以我总是在我可能的时候避免这样做。
你可以创建一个名为'Advanced Custom Fields‘的插件,然后创建一个新的字段,你可以在其中写下文章的Jersey编号,然后按该字段对查询进行排序,这可能是最好的方法。
我还喜欢创建一个无限的重复字段,允许我为每个重复字段选择一个帖子,并按我想要的顺序一个接一个地添加帖子-这改变了查询和模板的结构方式,所以它有点复杂。
(此外,开头的if链看起来也很可怕。这将导致以后在管理方面的痛苦。我希望我可以编写模板并对其进行测试:( )
https://stackoverflow.com/questions/43481282
复制相似问题