不确定这是否与高级自定义字段有关,但我会保持这一点。我对PHP比较陌生,想知道接近这个任务的最佳方式。 此外,这是一个WordPress(4.1.1)环境。
我发送所有帖子类型的查询以及相关的类别类型以便拉入并显示。如果查询可以找到帖子,则会生成< article>阻止每个结果的附加html。不要复杂吧?
现在,我想在/当查询产生超过8个结果时创建一个分页元素。
可以找到具有查询结果前端的环境: http://test-hdwg.pantheon.io/news/
此页面使用的模板(news.php)包含以下内容:
<?php /* Template Name: News */ ?>
<?php get_header(); ?>
<main id="primary" class="content-area">
<div class="jumbotron">
<div class="row">
<div class="intro">
<p><?php the_field('news_heading') ?></p>
</div>
</div>
</div>
<div class="news">
<div class="row news-articles">
<div class="column-wrapper">
<div class="small-4 columns news-left-column">
<div class="select-dropdown">
<button href="#" data-dropdown="dropdown-items" aria-controls="dropdown-items" aria-expanded="false" class="dropdown">Select a news category</button>
<ul id="dropdown-items" data-dropdown-content class="f-dropdown" aria-hidden="true" tabindex="-1">
<?php $args = array(
'exclude' => '',
'title_li' => __( '' ),
'show_option_none' => __( '<li><a href="#primary">No categories</a></li>' ),
'taxonomy' => 'category',
'child_of' => 2,
'current_category' => 0
); ?>
<?php wp_list_categories($args); ?>
<li class="cat-item cat-item-all-news"><a href="/news" alt="View all News" title="View all News">All News</a>
</ul>
</div>
<div class="news-block">
<span class="news-block-heading">Email Newsletters</span>
<div class="news-inner-block">
<?php if( have_rows('newsletters_list') ): ?>
<?php while( have_rows('newsletters_list') ): the_row(); ?>
<span class="year"><?php the_sub_field('newsletter_year'); ?></span>
<?php if( have_rows('newsletter_resource') ): ?>
<ul>
<?php while( have_rows('newsletter_resource') ): the_row(); ?>
<li><a href="<?php the_sub_field('newsletter_url'); ?>" target="_blank"><?php the_sub_field('newsletter_title'); ?></a></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
</div>
<div class="small-8 columns news-right-column">
<?php query_posts( 'post_type=post&cat=' ); ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<article class="large-6 columns ui-article-block">
<h3><?php echo get_the_date( 'd M Y' ); ?></h3>
<hr/>
<h2><?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?></h2>
<h1><?php the_title(); ?></h1>
<p>
<?php
$content = get_the_content();
$content = strip_tags($content);
echo substr($content, 0, 175) . "..."; // set a character cut-off at 175 characters
?>
</p>
<a href="<?php the_permalink(); ?>" alt="Read more about the article: <?php the_title_attribute(); ?>" title="Read more about the article: <?php the_title_attribute(); ?>" class="button postfix">Read More</a>
</article>
<?php endwhile; ?>
<?php else : ?>
<div class="large-8 columns">
<p class="lead">Well this is embarrassing. There are currently no news articles.</p>
</div>
<?php endif; ?>
<?php wp_reset_query(); ?>
</div>
</div>
</div>
</div>
</main>
<?php get_footer(); ?>
为了清楚起见,这不是一个问题,但更多的是来自更多经验的开发人员关于如何利用高级自定义字段元素(如果重要)处理任务的请求。
非常感谢任何帮助!