Advertisement
Guest User

Twetny Twelve Sticky style.css, index.php, functions.php

a guest
Feb 8th, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. # # # # # # # # # # style.css
  2.  
  3. /*
  4. Theme Name: Twenty Twelve Sticky New
  5. Template: twentytwelve
  6. */
  7.  
  8. @import url("../twentytwelve/style.css");
  9.  
  10.  
  11.  
  12. # # # # # # # # # # index.php
  13.  
  14. <?php get_header(); ?>
  15.  
  16. <div id="primary" class="site-content">
  17. <div id="content" role="main">
  18. <?php
  19. // don't edit this
  20. global $wp_query;
  21. $first_page_total= 9; // total number of posts on first page
  22. $paginated_total = 10;
  23. $found_posts = $wp_query->found_posts;
  24. $pages = 1 + ceil(($found_posts - $first_page_total) / $paginated_total);
  25. $wp_query->max_num_pages = $pages;
  26. // start editing
  27. ?>
  28. <?php if ( have_posts() ) : ?>
  29.  
  30. <?php /* Start the Loop */ ?>
  31. <?php while ( have_posts() ) : the_post(); ?>
  32. <?php get_template_part( 'content', get_post_format() ); ?>
  33. <?php endwhile; ?>
  34.  
  35. <?php if(!is_paged()) : ?>
  36. <?php
  37. $sticky = get_option( 'sticky_posts' );
  38. $args = array(
  39. 'posts_per_page' => 1,
  40. 'post__in' => $sticky,
  41. 'ignore_sticky_posts' => 1
  42. );
  43. $the_query = new WP_Query( $args); ?>
  44. <?php /* Start the sticky post loop */ ?>
  45. <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
  46. <?php
  47. if ( $sticky[0] ) {
  48. get_template_part( 'content', get_post_format() );
  49. }
  50. ?>
  51. <?php endwhile; ?>
  52. <?php endif; ?>
  53.  
  54. <?php twentytwelve_content_nav( 'nav-below' ); ?>
  55.  
  56. <?php else : ?>
  57.  
  58. <article id="post-0" class="post no-results not-found">
  59.  
  60. <?php if ( current_user_can( 'edit_posts' ) ) :
  61. // Show a different message to a logged-in user who can add posts.
  62. ?>
  63. <header class="entry-header">
  64. <h1 class="entry-title"><?php _e( 'No posts to display', 'twentytwelve' ); ?></h1>
  65. </header>
  66.  
  67. <div class="entry-content">
  68. <p><?php printf( __( 'Ready to publish your first post? <a href="%s">Get started here</a>.', 'twentytwelve' ), admin_url( 'post-new.php' ) ); ?></p>
  69. </div><!-- .entry-content -->
  70.  
  71. <?php else :
  72. // Show the default message to everyone else.
  73. ?>
  74. <header class="entry-header">
  75. <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentytwelve' ); ?></h1>
  76. </header>
  77.  
  78. <div class="entry-content">
  79. <p><?php _e( 'Apologies, but no results were found. Perhaps searching will help find a related post.', 'twentytwelve' ); ?></p>
  80. <?php get_search_form(); ?>
  81. </div><!-- .entry-content -->
  82. <?php endif; // end current_user_can() check ?>
  83.  
  84. </article><!-- #post-0 -->
  85.  
  86. <?php endif; // end have_posts() check ?>
  87.  
  88. </div><!-- #content -->
  89. </div><!-- #primary -->
  90.  
  91. <?php get_sidebar(); ?>
  92. <?php get_footer(); ?>
  93.  
  94.  
  95.  
  96. # # # # # # # # # # functions.php
  97.  
  98. <?php
  99.  
  100. function my_post_queries( $query ) {
  101.  
  102. // not an admin page and it is the main query
  103. if (!is_admin() && $query->is_main_query()){
  104.  
  105. // query for the home page
  106. if(is_home()){
  107.  
  108. $first_page_total= 9; // total number of posts on first page
  109. $paginated_total = 10; // total number of posts on paginated pages
  110. $posts_to_skip = $paginated_total - $first_page_total;
  111.  
  112. // pagination for custom page(s)
  113. if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
  114. elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
  115. else { $paged = 1; }
  116.  
  117. // page query args
  118.  
  119. $query->set('posts_per_page', $first_page_total);
  120. $query->set('post__not_in', get_option( 'sticky_posts' ));
  121.  
  122. if(is_paged()) {
  123. // paginated query args
  124. $offset = (($paged - 1) * $paginated_total)- $posts_to_skip;
  125. $query->set('offset', $offset);
  126. $query->set('posts_per_page', $paginated_total);
  127. }
  128.  
  129. }
  130. }
  131. }
  132.  
  133. add_action( 'pre_get_posts', 'my_post_queries' );
  134.  
  135. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement