个性化阅读
专注于IT技术分析

如何修复自定义wordpress项目组合分页

如何修复自定义wordpress项目组合分页?下面是我的代码, 可以正常工作, 但分页不会到来。我可以通过WP PageNavi这样的插件来实现吗?

以下是我的自定义模板名称:Portfolio

<?php
/*
Template Name: Portifolio
*/
?>
<?php
get_header(); ?>

<div class="single-full-width-container single-page-header-container">
  <header class="container">
    <?php
the_title('<h1 class="single-page-heading">', '</h1>'); ?>
    <ul class="single-page-breadcrumbs">
      <?php

if (function_exists('bcn_display') && !is_front_page())
    {
    bcn_display();
    }

?>
    </ul>
  </header>
</div>
<div class="container">
  <div class="row">
    <main role="main" class="isotope-portfolio portfolio-wrapper four-cols-portfolio span12">
      <div class="row">
        <?php
$terms = get_terms("tagportifolio");
$count = count($terms);
echo '<ul id="isotope-filters" class="pagination-centered unstyled">';
echo '<li><a href="#all" data-filter="*">Show All</a></li>';

if ($count > 0)
    {
    foreach($terms as $term)
        {
        $termname = strtolower($term->name);
        $termname = str_replace(' ', '-', $termname);
        echo '<li><a href="#' . $termname . '" data-filter=".' . $termname . '" rel="' . $termname . '">' . $term->name . '</a></li>';
        }
    }

echo "</ul>";
?>
        <div id="container">
          <?php
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$loop = new WP_Query(array(
    'post_type' => 'project', 'posts_per_page' => 5, 'paged' => $paged
));
$count = 0;
?>
          <?php

if ($loop):
    while ($loop->have_posts()):
        $loop->the_post(); ?>
          <?php
        $terms = get_the_terms($post->ID, 'tagportifolio');
        if ($terms && !is_wp_error($terms)):
            $links = array();
            foreach($terms as $term)
                {
                $links[] = $term->name;
                }

            $links = str_replace(' ', '-', $links);
            $tax = join(" ", $links);
        else:
            $tax = '';
        endif;
?>
          <article class="portfolio-article item <?php
        echo strtolower($tax); ?> span4">
            <?php
        $infos = get_post_custom_values('_url'); ?>
            <div class="portfolio-content article-content">
              <?php
        if (has_post_thumbnail())
            {
            $large_image_url = wp_get_attachment_image_src(get_post_thumbnail_id() , 'large');
            echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" rel="lightbox" class="portfolio-teaser-pic fancybox">';
            the_post_thumbnail(array(
                370, 370
            ));
            echo '</a>';
            }

?>
              <div class="meta-info"> <span class="meta-info-buttons likes-no">
                <?php
        echo $term->name; ?>
                </span> <span class="meta-info-buttons comments-no"><a href="<?php
        echo $infos[0]; ?>">Live Preview</a></span> <span class="meta-info-buttons more-details"><a href="<?php
        the_permalink() ?>">More Details</a></span></div>
              <div class="portfolio-content-wrap">
                <h1 class="portfolio-heading article-heading"> <a href="<?php
        the_permalink() ?>">
                  <?php
        the_title(); ?>
                  </a> </h1>
                <p>
                  <?php
        echo get_the_excerpt(); ?>
                </p>
              </div>
            </div>
          </article>
          <?php
    endwhile;
else: ?>
          <p>Sorry, no portfolio entries for while.</p>
          <?php
endif; ?>
          <?php
wp_reset_query(); ?>
        </div>
        <?php

if (function_exists('wp_pagenavi'))
    {
    wp_pagenavi();
    wp_reset_postdata(); // avoid errors further down the page
    }

?>
      </div>
    </main>
  </div>
</div>
<?php
get_footer(); ?>

#1


你需要使用以下

  echo paginate_links( array(
                    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged') ), 'total' => $loop->max_num_pages, 'next_text'    => __('Next »'), ) );

这是在Wordpress中如何实现此示例。

赞(0)
未经允许不得转载:srcmini » 如何修复自定义wordpress项目组合分页

评论 抢沙发

评论前必须登录!