我有一个函数,可以创建自定义帖子类型的列表,并按字母顺序排序。它还将这些帖子中的第一个字母显示为标题。出于某种原因,它会在某个时候停止在字母F中添加帖子,然后继续创建另一个F并在那里添加其余的帖子,而不是将所有帖子添加在一起,我真的不知道为什么会发生这种情况。功能如下:
function alfabetic_order( $cat_n = "")
{
if(isset($_REQUEST[\'post_type\'])) {
global $query_string;
$args=($query_string.\'&taxonomy=type&term=\'.$cat_n.\'&orderby=name&order=ASC&post_status=publish\' );
$new_empresas = get_posts( $args);
} else {
$args = array(\'post_type\' => \'las-empresas\',
\'taxonomy\' => \'type\',
\'term\' => $cat_n,
\'post_status\' => \'publish\',
\'posts_per_page\' => -1,
\'orderby\' => \'name\', \'order\' => \'ASC\',
);
$new_empresas = get_posts( $args);
}
// echo "maulik".$cat_n;
//}
$i = 1;
$l = 0;
$html .= \'<div class="tabs-section">\';
foreach ($new_empresas as $empresas) {
$this_char = strtoupper(mb_substr($empresas->post_title, 0, 1, \'UTF-8\'));
if ($this_char != $last_char) {
if ($last_char != \'\') {
$html .= \'</div>\';
$html .= \'</div>\';
}
$last_char = $this_char;
if ($l % 3 == 0) {
$html .= \'</div><div class="tabs-section">\';
}
$l++;
$html .= \'<div class="bx-section fadeInIn-Big">\';
$html .= \'<h1>\' . $last_char . \'</h1>\';
$html .= \'<div class="ctn-section">\';
$html .= \'<a href="\' . get_permalink($empresas->ID) . \'">\' . $empresas->post_title . \'</a>\';
} else {
$html .= \'<a href="\' . get_permalink($empresas->ID) . \'">\' . $empresas->post_title . \'</a>\';
}
$i++;
}
$html .= \'</div>\';
$html .= \'</div>\';
$html .= \'</div>\';
return $html;
}
以下是在模板中调用它的HTMl:
<div id="tabs-1">
<?php //echo $html;
echo alfabetic_order( $cat_name="") ?>
</div>
<div id="tabs-2">
<?php echo alfabetic_order( $cat_name="empresas") ?>
</div>
<div id="tabs-3">
<?php echo alfabetic_order( $cat_name="centros-educativos") ?>
</div>
<div id="tabs-4">
<?php echo alfabetic_order( $cat_name="asociaciones-empresariales") ?>
</div>
<div id="tabs-5">
<?php echo alfabetic_order( $cat_name="instituciones") ?>
</div>
这一页的问题很明显:
http://www.alianzafpdual.es/miembros/instituciones/