自定义WordPress分页

时间:2016-06-02 08:33:00

标签: wordpress plugins pagination

美好的一天,我正在创建一个插件,它将使用<!--nextpage-->自动发布带有分页符的幻灯片文章,我的问题是我想要自定义分页样式而不是页面:1,2我想要显示作为下一页和上一页。我怎么能实现这一个?我想把代码放在插件中,我不想在主题中添加代码。

我已经尝试在我的插件中添加此代码,但无效:

$defaults = array(
    'before'           => '<h1>' . __( 'Pages:' ),
    'after'            => '</h1>',
    'link_before'      => '',
    'link_after'       => '',
    'next_or_number'   => 'next',
    'separator'        => ' ',
    'nextpagelink'     => __( 'Next page' ),
    'previouspagelink' => __( 'Previous page' ),
    'pagelink'         => 'Page %',
    'echo'             => 1
);
wp_link_pages( $defaults ); 

这是我的插件中的代码:

    $x = "";

 foreach ($leadamajig_data->questions as $post)
{

$lead_title =  '<p><h1 id="title">' . $post->title . '</a></h1></p>';
$lead_choices = '<p><h1 id="clicked"><a hre="#">' . $post->choices->a . '</a></h1></p>';
$lead_choices2 ='<p><h1 id="clicked2"><a hre="#">' .$post->choices->b . '</a></h1></p>';
$lead_choices3 = '<p><h1 id="clicked3"><a hre="#">' . $post->choices->c . '</a></h1></p>';

$x = $x . $lead_title . $lead_choices . $lead_choices2 . $lead_choices3 . '<!--nextpage-->';

}


$my_post = array(
  'post_title'    => questions,
  'post_content'  => $x,
  'post_status'   => 'publish',
  'post_author'   => 1
);

 wp_insert_post( $my_post );

1 个答案:

答案 0 :(得分:0)

$default返回您使用wp_link_pages()参数数组定义的分页标记。因此,您可能已经拥有了要从wp_link_pages()函数返回的html。

$defaults = array( 'before' => '<h1>' . __( 'Pages:' ), 'after' => '</h1>', 'link_before' => '', 'link_after' => '', 'next_or_number' => 'next', 'separator' => ' ', 'nextpagelink' => __( 'Next page' ), 'previouspagelink' => __( 'Previous page' ), 'pagelink' => 'Page %', 'echo' => 1 ); $pagination = wp_link_pages( $defaults ); //Put this where you want your pagination to appear: echo $pagination; 分配给变量,然后回显或打印出您想要分页的内容。

像这样:

public class Example {

    static int[] a = { 2, 3, 4, 3, 3, 5, 4, 10, 9, 1, 9, 11, 15 };
    static int[] b = new int[a.length];
    static int count = 0;

    public static void main(String[] args) {
        counting();
        printCount();
    }

    private static void printCount() {
        int k = 0;
        for (int i = 0; i < b.length; i++) {
            System.out.print("number" + " " + a[k] + " " + "is found" + " "); 
            System.out.println(b[i] + " " + "times");
            k++;
        }
        System.out.println();

    }

    private static void counting() {
        for (int i = 0; i < a.length; i++) {
            for (int k = 0; k < a.length; k++) {
                if (a[i] == a[k]) {
                    b[i] = ++count;
                }
            }
            count = 0;
        }

    }
}
相关问题