主页上的分页WordPress

时间:2019-02-05 10:26:06

标签: php wordpress pagination wordpress-theming

我在尝试分页以便在我正在工作的网站的主页上工作时遇到问题。

这是我正在使用的代码,当然已简化:

如何对此进行分页?

var size    = width * height * 1.25f; // 10-bit depth
var pData   = new List<short>();

for (int i = 0; i < size; i += 5)
{
    pData.Add((short)(data[i] << 2 | ((data[i + 4] >> 0) & 3)));
    pData.Add((short)(data[i + 1] << 2 | ((data[i + 4] >> 2) & 3)));
    pData.Add((short)(data[i + 2] << 2 | ((data[i + 4] >> 4) & 3)));
    pData.Add((short)(data[i + 3] << 2 | ((data[i + 4] >> 6) & 3)));
}

var mBayer = new Mat(width, height, CvType.Cv16u);
mBayer.Put(0, 0, pData.ToArray());

var mRgb = new Mat(width, height, CvType.Cv8u);
Imgproc.CvtColor(mBayer, mRgb, Imgproc.COLORBayerGR2RGB);

3 个答案:

答案 0 :(得分:0)

<?php $args = array('cat' => '3, 7, 10, 12', 'posts_per_page'=> 3); ?>
    <?php query_posts($args); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post();    ?>

            <article class="col-md-12">
                <a href="<?php the_permalink(); ?>" >
                    <div class="image"><img class="img-responsive" src="<?php echo the_post_thumbnail_url( 'medium' ); ?>"></div></a>
                    <div class="entry entry-table">
                        <div class="title">
                          <a href="<?php the_permalink(); ?>" ><h3 class="h5"><?php the_title(); ?></h3></a>
                          <span class="cateogry<?php echo get_the_category( $id )[0]->cat_ID; ?>"><?php echo get_the_category( $id )[0]->name; ?></span>
                       <p><?php echo get_excerpt(228, 'content'); ?>
                        <a class="linkmore" href="<?php the_permalink() ?>">Czytaj dalej ...</a>
                       </p>
                        </div>
                    </div>

            </article>

        <?php endwhile; ?> 
<div class="navigation">
  <div class="alignleft"><?php previous_posts_link('&laquo; Previous') ?></div>
  <div class="alignright"><?php next_posts_link('More &raquo;') ?></div>
</div>
<?php endif; ?>

答案 1 :(得分:0)

首先,您必须正确设置查询:

$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array('cat' => '3, 7, 10, 12', 'posts_per_page'=> 3, 'paged' => $paged);

第二,您需要在循环外添加分页链接

<div class="navigation">
  <div class="alignleft"><?php previous_posts_link('&laquo; Previous') ?></div>
  <div class="alignright"><?php next_posts_link('More &raquo;') ?></div>
</div>

整个代码如下:

<?php
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $args = array('cat' => '3, 7, 10, 12', 'posts_per_page'=> 3, 'paged' => $paged);
?>
    <?php query_posts($args); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post();    ?>

            <article class="col-md-12">
                <a href="<?php the_permalink(); ?>" >
                    <div class="image"><img class="img-responsive" src="<?php echo the_post_thumbnail_url( 'medium' ); ?>"></div></a>
                    <div class="entry entry-table">
                        <div class="title">
                          <a href="<?php the_permalink(); ?>" ><h3 class="h5"><?php the_title(); ?></h3></a>
                          <span class="cateogry<?php echo get_the_category( $id )[0]->cat_ID; ?>"><?php echo get_the_category( $id )[0]->name; ?></span>
                       <p><?php echo get_excerpt(228, 'content'); ?>
                        <a class="linkmore" href="<?php the_permalink() ?>">Czytaj dalej ...</a>
                       </p>
                        </div>
                    </div>

            </article>

        <?php endwhile; ?> 
<div class="navigation">
  <div class="alignleft"><?php previous_posts_link('&laquo; Previous') ?></div>
  <div class="alignright"><?php next_posts_link('More &raquo;') ?></div>
</div>
<?php endif; ?>

答案 2 :(得分:0)

问题已解决:

<?php
global $paged, $wp_query, $wp;
$args1 = array('cat' => '3, 7, 10, 12');

$args = wp_parse_args($wp->matched_query);
if ( !empty ( $args['paged'] ) && 0 == $paged ) {
$wp_query->set('paged', $args['paged']);
$paged = $args['paged'];
}
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('paged='.$paged.'&showposts=3&cat=3,7,10,12');
?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<article class="col-md-12">
                <a href="<?php the_permalink(); ?>" >
                    <div class="image"><img class="img-responsive" src="<?php echo the_post_thumbnail_url( 'medium' ); ?>"></div></a>
                    <div class="entry entry-table">
                        <div class="title">
                          <a href="<?php the_permalink(); ?>" ><h3 class="h5"><?php the_title(); ?></h3></a>
                          <span class="cateogry<?php echo get_the_category( $id )[0]->cat_ID; ?>"><?php echo get_the_category( $id )[0]->name; ?></span>
                       <p><?php echo get_excerpt(228, 'content'); ?>
                        <a class="linkmore" href="<?php the_permalink() ?>">Czytaj dalej ...</a>
                       </p>
                        </div>
                    </div>

            </article>
 <?php endwhile; ?>
 <?php wp_pagenavi(); ?>
 <?php $wp_query = null; $wp_query = $temp;?>