我们的网站是由一位程序员建立的,他不再能够帮助我们。我从他那里得到了足够多的教程来维护我们的网站。
他创建了一个自定义模板(posts1.php),可以按字母顺序排列特定类别内的帖子。然而,模板只有一个参数(姓氏),我们想按名字对帖子进行进一步排序。
以下是模板的完整内容。你能告诉我如何编辑模板,允许网站按姓和名对帖子进行排序吗?非常感谢。
<?php
/*
Template Name Posts: posts1
*/
?>
<?php get_header(); ?>
<div id="mainCol">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<p class="title"><?php
// Get the ID of a given category
$category_id = get_cat_ID( \'Enshrined Officers\' );
// Get the URL of this category
$category_link = get_category_link( $category_id );
?>
<!-- Print a link to this category -->
<a href="<?php echo $category_link; ?>" title="Enshrined Officers"><span class="back">← Return To List</span></a>
<?php next_post_link_plus( array(
\'order_by\' => \'custom\',
\'meta_key\' => \'Last Name\',
\'loop\' => false,
\'end_post\' => false,
\'thumb\' => false,
\'max_length\' => 0,
\'format\' => \'%link\',
\'link\' => \'<span class="enshr_next">Next »</span>\',
\'tooltip\' => \'\',
\'in_same_cat\' => true,
\'num_results\' => 1,
\'echo\' => true
) ); ?>
<?php previous_post_link_plus( array(
\'order_by\' => \'custom\',
\'meta_key\' => \'Last Name\',
\'loop\' => false,
\'end_post\' => false,
\'thumb\' => false,
\'max_length\' => 0,
\'format\' => \'%link\',
\'link\' => \'<span class="enshr_prev">« Previous |</span>\',
\'tooltip\' => \'\',
\'in_same_cat\' => true,
\'num_results\' => 1,
\'echo\' => true
) ); ?></p>
<div class="post" id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<div class="entry">
<?php the_content(\'Read the rest of this entry »\'); ?>
<?php wp_link_pages(array(\'before\' => \'<p><strong>Pages:</strong> \', \'after\' => \'</p>\', \'next_or_number\' => \'number\')); ?>
<br />
<div class="back"<?php
// Get the ID of a given category
$category_id = get_cat_ID( \'Enshrined Officers\' );
// Get the URL of this category
$category_link = get_category_link( $category_id );
?>
<!-- Print a link to this category -->
<a href="<?php echo $category_link; ?>" title="Enshrined Officers"><span class="back">←<span> Return To List</a>
</div>
<br />
<?php the_tags(\'<div class="tags"><p><strong>Tags:</strong> \', \' , \' , \'</p></div>\'); ?>
</div>
</div>
<?php endwhile; else: ?>
<h2 class="center">Oops...</h2>
<p class="center">Sorry, no posts matched your criteria.</p>
<?php include (TEMPLATEPATH . "/searchform.php"); ?>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
SO网友:rudtek
能否尝试更改这些行:
\'order_by\' => \'custom\',
\'meta_key\' => \'Last Name\',
在上述各节中,使用此代码:
\'meta_query\' => array(
\'relation\' => \'AND\',
\'last_name_sort\' => array(
\'key\' => \'last_name\',
\'compare\' => \'EXISTS\',
),
\'first_name_sort\' => array(
\'key\' => \'first_name\',
\'compare\' => \'EXISTS\',
),
),
\'orderby\' => array(
\'last_name_sort\' => \'ASC\',
\'first_name_sort\' => \'ASC\',
),
(假设您的名字键为“first\\u name”)