WordPress.org

Forums

One page per year. Category (21 posts)

  1. DaniSainz
    Member
    Posted 1 year ago #

    Hi!
    I want one page in category to each year.
    I have category.php and only category ("All").

    First Page (category.php):
    Year 2014:
    Februar
    - 9 Post
    Januar
    - 8 Post
    - 7 Post
    - 6 Post

    Second Page (category.php):
    Year 2013
    December
    - 5 Post
    November
    - 4 Post
    -3 Post
    .....

    I´ve readed this post but i want one page-one year

    Thanks!

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    Try it with a plugin:
    http://keesiemeijer.wordpress.com/date-pagination/

    Activate the plugin and put this in your theme's functions.php to paginate categories by year:

    add_action( 'pre_get_posts', 'yearly_paginated_home_query' );
    function yearly_paginated_home_query( $query ) {
    
        // not a wp-admin page and the query is for the main query
        if ( !is_admin() && $query->is_main_query() ) {
    
            //  paginate by year on category pages
    
            if ( is_category() ) {
    
                // 'yearly', 'monthly', 'daily'
                $query->set('date_pagination_type', 'yearly');
    
                // set other parameters here
            }
    
        }
    }

    btw:
    consider creating a child theme instead of editing your theme directly - if you upgrade the theme all your modifications will be lost.

  3. DaniSainz
    Member
    Posted 1 year ago #

    First, thanks to your answer!

    Have you tested this plugin?

    I can´t see anything.
    I put your code in function.php and active the plugin.
    Also include in my category.php only "echo km_dp_get_current_date_label()" to see the actual date, but this don´t work for me.

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    I've got this working on my testsite.

    Can you post a link to a category page?

  5. DaniSainz
    Member
    Posted 1 year ago #

    Yes, i can use a normal category pagination:

    <?php
    global $wp_query;
    $args = array_merge( $wp_query->query, array('posts_per_page'=> 2 ) );
    query_posts( $args );
     if (have_posts()): ?>
        <h2><?php echo "DATE: ".km_dp_get_current_date_label(); ?></h2>
              <?php while (have_posts()): the_post(); ?>
                <div id="post">
                  <div class="post-title">
                    <a href="<?php the_permalink() ?>"><h2><?php the_title(); ?></h2></a>
                  </div>
                  <div class="post-content"><?php the_excerpt(); ?></div>
                </div>
              <?php endwhile; ?>
    
            <div class="navigation">
              <div class="alignleft static-scroll"><?php next_posts_link('&laquo; Alte Beiträge') ?></div>
              <div class="alignright static-scroll"><?php previous_posts_link('Neue Beiträge &raquo;') ?></div>
            </div>
    <?php else: ?>
            <p><?echo __("Keine Nachricht"); ?></p>
    <?php endif; ?>

    but when i use not working:

    <?php
    global $wp_query;
    $args = array_merge( $wp_query->query, array('posts_per_page'=> 2 ) );
    query_posts( $args );
     if (have_posts()): ?>
        <h2><?php echo "DATE: ".km_dp_get_current_date_label(); ?></h2>
              <?php while (have_posts()): the_post(); ?>
                <div id="post">
                  <div class="post-title">
                    <a href="<?php the_permalink() ?>"><h2><?php the_title(); ?></h2></a>
                  </div>
                  <div class="post-content"><?php the_excerpt(); ?></div>
                </div>
              <?php endwhile; ?>
              <?php
    
              $next_label = 'Previous Month';
              $prev_label = 'Next Month';
    
              if ( function_exists( 'km_dp_get_next_date_label' ) ) {
                  $next_label = km_dp_get_next_date_label( 'F Y' );
              }
    
              if ( function_exists( 'km_dp_get_previous_date_label' ) ) {
                  $prev_label = km_dp_get_previous_date_label( 'F Y' );
              }
              ?>
    
            <div class="navigation">
              <div class="alignleft static-scroll"><?php next_posts_link($next_label) ?></div>
              <div class="alignright static-scroll"><?php previous_posts_link($prev_label) ?></div>
            </div>
    <?php else: ?>
            <p><?echo __("Keine Nachricht"); ?></p>
    <?php endif; ?>

    I´ve checked the if(function_exists('km_dp_get_nex_date_label')) and work.

  6. keesiemeijer
    moderator
    Posted 1 year ago #

    Try it without the query, remove this

    global $wp_query;
    $args = array_merge( $wp_query->query, array('posts_per_page'=> 2 ) );
    query_posts( $args );
  7. DaniSainz
    Member
    Posted 1 year ago #

    I have checked this option but it doesn´t work.

    I think this line <?php echo "DATE: ".km_dp_get_current_date_label(); ?> should be enough to checked...

    I don´t know what is the problem, I have the code in category.php and a normal pagination ist right.
    The plugin is installed and the function

    add_action( 'pre_get_posts', 'yearly_paginated_home_query' );
    function yearly_paginated_home_query( $query ) {

    // not a wp-admin page and the query is for the main query
    if ( !is_admin() && $query->is_main_query() ) {

    // paginate by year on category pages

    if ( is_category() ) {

    // 'yearly', 'monthly', 'daily'
    $query->set('date_pagination_type', 'yearly');

    // set other parameters here
    }

    }
    }

    is in function.php

  8. keesiemeijer
    moderator
    Posted 1 year ago #

    Is it in function.php or functions.php? It needs to go in functions.php.

  9. DaniSainz
    Member
    Posted 1 year ago #

    Really is in global.php wich is included in functions.php.
    I have checked in functions.php too, but not.

    I'm totally frustated with this problem.

  10. keesiemeijer
    moderator
    Posted 1 year ago #

    What theme are you using? And where did you download it from?

  11. DaniSainz
    Member
    Posted 1 year ago #

    The theme is mine, i've made it totally.

  12. keesiemeijer
    moderator
    Posted 1 year ago #

    Ok, can you remove the code from global.php/functions.php and use this for your category.php template:

    <?php
    // set the paged variable (see: http://codex.wordpress.org/Pagination )
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    
    // example args
    $args = array(
        // 'yearly', 'monthly', 'daily'
        'date_pagination_type' => 'yearly',
        'paged' => $paged,
    );
    
    // the custom query
    $the_query = new WP_Query( $args );
    ?>
    
    <?php
    
     if ( $the_query->have_posts() ) : ?>
        <h2><?php echo "DATE: " . km_dp_get_current_date_label('Y', $the_query); ?></h2>
              <?php while ( $the_query->have_posts() ) : $the_query->the_post();  ?>
                <div id="post">
                  <div class="post-title">
                    <a href="<?php the_permalink() ?>"><h2><?php the_title(); ?></h2></a>
                  </div>
                  <div class="post-content"><?php the_excerpt(); ?></div>
                </div>
              <?php endwhile; ?>
              <?php
    
              $next_label = 'Previous Month';
              $prev_label = 'Next Month';
    
              if ( function_exists( 'km_dp_get_next_date_label' ) ) {
                  $next_label = km_dp_get_next_date_label( 'F Y' );
              }
    
              if ( function_exists( 'km_dp_get_previous_date_label' ) ) {
                  $prev_label = km_dp_get_previous_date_label( 'F Y' );
              }
              ?>
    
            <div class="navigation">
              <div class="alignleft static-scroll"><?php next_posts_link($next_label, $the_query->max_num_pages ); ?></div>
              <div class="alignright static-scroll"><?php previous_posts_link($prev_label); ?></div>
            </div>
            <?php wp_reset_postdata(); ?>
    <?php else: ?>
            <p><?echo __("Keine Nachricht"); ?></p>
    <?php endif; ?>
  13. DaniSainz
    Member
    Posted 1 year ago #

    thanks but neither serves me, I don't know the conflict.
    Hopefully get fix... is really necesary

  14. DaniSainz
    Member
    Posted 1 year ago #

    Hi again keesiemeijer!

    I'm trying run once again yours plugin, i have tried desactivating plugins, changing my code, but i don't get.
    Maybe, do you know other solution with your plugin or other method?

    Thanks!

  15. DaniSainz
    Member
    Posted 1 year ago #

    Some Opinion?

  16. keesiemeijer
    moderator
    Posted 1 year ago #

    I have no idea why it shouldn't work. Can you post the full code from your theme template.

  17. DaniSainz
    Member
    Posted 1 year ago #

    Ok, i post my category.php

    <?php
    /*
    Template Name: Lorem
    */

    get_header();

    ?>
    <div class="main-content-wrapper beige">

    <div class="main-content-center-page">

    <h1><?php echo get_the_title(18); ?></h1>
    <div id="subnav">
    <ul id="menu-submenu">
    <?php
    if(!$_subnav = get_subnav_by_location('primary', 2, false)){
    if(!$_subnav = get_subnav_by_location('footer', 2)){
    $_subnav = "";//get_subnav_by_location('temp', 2);
    }
    }
    echo $_subnav;
    ?>
    <li class="clear">

    </div>

    </div>

    </div>

    <div class="main-content-wrapper category">
    <div class="main-content-center-page">
    <div class="subpage_year">
    <?php
    // if(){
    // $today = getdate();
    // echo $year=$today["year"];
    // }else{

    // }
    ?>
    </div>
    <div class="white-content">
    <div class="wrapper-post">
    <?php
    // set the paged variable (see: http://codex.wordpress.org/Pagination )
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;

    // example args
    $args = array(
    // 'yearly', 'monthly', 'daily'
    'date_pagination_type' => 'yearly',
    'paged' => $paged,
    );

    // the custom query
    $the_query = new WP_Query( $args );
    ?>

    <?php

    if ( $the_query->have_posts() ) : ?>
    <h2><?php echo "DATE: " . km_dp_get_current_date_label('Y', $the_query); ?></h2>
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <div id="post">
    <div class="post-title">
    "><h2><?php the_title(); ?></h2>
    </div>
    <div class="post-content"><?php the_excerpt(); ?></div>
    </div>
    <?php endwhile; ?>
    <?php

    $next_label = 'Previous Month';
    $prev_label = 'Next Month';

    if ( function_exists( 'km_dp_get_next_date_label' ) ) {
    $next_label = km_dp_get_next_date_label( 'F Y' );
    }

    if ( function_exists( 'km_dp_get_previous_date_label' ) ) {
    $prev_label = km_dp_get_previous_date_label( 'F Y' );
    }
    ?>

    <div class="navigation">
    <div class="alignleft static-scroll"><?php next_posts_link($next_label, $the_query->max_num_pages ); ?></div>
    <div class="alignright static-scroll"><?php previous_posts_link($prev_label); ?></div>
    </div>
    <?php wp_reset_postdata(); ?>
    <?php else: ?>
    <p><?echo __("Keine Nachricht"); ?></p>
    <?php endif; ?>
    </div>
    </div>
    <div class="white-sidebar">
    <div class="sidebar_article_year">
    <?php $sidebar_year = get_page_by_title( "$year Artikel", OBJECT, 'sidebar_content' ); ?>
    <?php
    echo $sidebar_year->post_content;
    $sidebar = get_field('sidebar',$sidebar_year);
    if( $sidebar ):
    foreach( $sidebar as $content):
    setup_postdata($post);
    ?>
    </div>

    <div class="sidebar_article"><?php //echo the_field('template', $content->ID); ?>
    <h2><?echo __("Vorgestellter Artikel");?></h2>
    <div class="post">
    <div class="post-title">ID) ?>"><h2><?php echo $content->post_title;?></h2></div>
    <div class="post-content"><?php the_excerpt();?> </div>
    </div>
    </div>
    <?php
    endforeach;
    endif;
    ?>
    </div>
    </div>
    </div>
    <br class="clear" />

    <?php get_footer(); ?>

  18. onebitrocket
    Member
    Posted 1 year ago #

    Hey keesiemeijer,

    I just stumbled across this plugin.
    Wow, I solves so many problems that I was trying to resolve.

    I achieved exactly what I wanted with the pagination of my posts.

    Is it possible to modify the url structure to follow this monthly navigation?

    Thanks

  19. keesiemeijer
    moderator
    Posted 1 year ago #

    What url structure do you have in mind? Take in account that urls like example.com/%year%/ (example.com/2014/) are reserved for the date archives for the post type post.

  20. onebitrocket
    Member
    Posted 1 year ago #

    I want essentially archive within a category, tag, page etc

    /page/2 doesn't really work for the site I'm migrating in to WordPress.

    The current site enables visitors to go directly to a month/year, where as is if the default pagination is used in WordPress, the page that January 2013 content lives on would be a complete guess.

    SO the URL structure I'm looking to achieve follows:
    example.com/%taxonomy%/month/year rather than example.com/%taxonomy%/page/2/

    Primarily I'll be using categories to build my URLs in my menus.

    Does that make sense?

    Thanks

  21. keesiemeijer
    moderator
    Posted 1 year ago #

    Sorry for the late reply.

    This plugin does not support custom permalinks. I think you can do this with the rewrite api
    http://codex.wordpress.org/Rewrite_API

    And maybe this plugin does what you want.
    http://wordpress.org/plugins/date-based-taxonomy-archives/

Topic Closed

This topic has been closed to new replies.

About this Topic