noromami
Forum Replies Created
-
Forum: Themes and Templates
In reply to: Link to more posts(category archive) if more than # postsUpdate!
I’ve made a little more progress on this problem. I have a link working now that takes the category of the posts and places it in a link at the bottom of the page. (Thanks to another bit of code I found on the forums) All I’d like to do now is to have the link only show up when there are more posts than the page is set to display (in the current form, more than 5 posts).
I assume I need some sort of conditional statement that compares ‘showposts’ to the number of posts in he category. Then if the posts in the category is greater than showposts, it will output the div. Otherwise it will leave the space blank. Anyone good with their PHP and can help me with this, It would be greatly appreciated!
Here’s the current code. The div with the class ‘catlink’ contains the archive link:
<?php /* Template Name: Categories As Blog Page */ ?> <?php get_header(); ?> <?php include (TEMPLATEPATH . '/sidebarLeft.php'); ?> <div id="content"> <?php if (have_posts()) : while (have_posts()) : the_post();?> <?php $blogheader = get_post_meta($post->ID, 'blog-header', true); ?> <div class="post" id="post-<?php the_ID(); ?>"> <h1 class="post"><?php the_title(); ?></h1> <p> <?php edit_post_link(__( 'Edit', 'default' ), '', ''); ?></p> <div class="entry"> <div class="article"><?php the_content((__( 'Continue Reading »', 'default')) . the_title('', '', false)); ?></div> <?php wp_link_pages(); ?> </div> </div> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> <?php // This displays posts with the same category as the title of the page if ( is_page() ) { $page_name = $posts[0]->post_name; //or use $posts[0]->post_title $category = get_term_by('slug',$page_name,'category'); if ($category) { $args=array( 'category__in' => array($category->term_id), 'post_type' => 'post', 'post_status' => 'publish', 'showposts' => 5, 'caller_get_posts'=> 1 ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { echo '<h2>'.$blogheader.'</h2>'; while ($my_query->have_posts()) : $my_query->the_post(); ?> <div class="post" id="post-<?php the_ID(); ?>"> <table class="subhead"><tr><td class="subheadleft"> <h3 class="post"><?php the_title(); ?></h3> </td><td class="subheadright"> <p><?php the_date( 'F d , Y', $before, $after, true ); ?></p> </td></tr></table> <p> <?php edit_post_link(__( 'Edit', 'default' ), '', ''); ?></p> <div class="entry"> <div class="article"><?php the_content((__( 'Continue Reading »', 'default')) . the_title('', '', false)); ?></div> <?php wp_link_pages(); ?> </div> </div> <?php $cat = get_the_category(); $cat = $cat[0]; ?> <?php endwhile; } } } wp_reset_query(); // Restore global post data stomped by the_post(). ?> <div class="catlink"> <p class="catlink">Read more from the <a class="catlink" href="<?php echo get_category_link($cat->cat_ID);?>"><?php echo $cat->cat_name; ?></a> Archives</p> </div> </div> <?php include (TEMPLATEPATH . '/sidebarRight.php'); ?> <?php get_footer(); ?> </div><!--/Wrapper--> <div id="footershadow"></div> </div><!--/Container--> </body> </html>Forum: Themes and Templates
In reply to: Pages content relative to author/category/tagbump
Still haven’t made much progress on this, really could use the help.
This was my attempt at repurposing to use the author instead of a category. It doesn’t work at all, but I’m not surprised as I’m scraping my way through the codex with only a vague understanding of how anything works. I think I sort of figured out what the category one was doing, but I don’t think I have the right tags for this one.
<?php /* Template Name: Author Page */ ?> <?php get_header(); ?> <?php include (TEMPLATEPATH . '/sidebarLeft.php'); ?> <div id="content"> <?php if (have_posts()) : while (have_posts()) : the_post();?> <div class="post" id="post-<?php the_ID(); ?>"> <h1 class="post"><?php the_title(); ?></h1> <p> <?php edit_post_link(__( 'Edit', 'default' ), '', ''); ?></p> <div class="entry"> <div class="article"><?php the_content((__( 'Continue Reading »', 'default')) . the_title('', '', false)); ?></div> <?php wp_link_pages(); ?> </div> </div> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> <?php // This displays posts with the same category as the title of the page if ( is_page() ) { $page_name = $posts[0]->post_name; //or use $posts[0]->post_title $author = get_userdata($page_name); if ($author) { $args=array( author_name= $author, 'post_type' => 'post', 'post_status' => 'publish', 'showposts' => 5, 'caller_get_posts'=> 1 ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { echo '<h2>Recent Activity</h2><hr>'; while ($my_query->have_posts()) : $my_query->the_post(); ?> <div class="post" id="post-<?php the_ID(); ?>"> <h3 class="post"><?php the_title(); ?></h3> <p> <?php edit_post_link(__( 'Edit', 'default' ), '', ''); ?></p> <div class="entry"> <div class="article"><?php the_content((__( 'Continue Reading »', 'default')) . the_title('', '', false)); ?></div> <?php wp_link_pages(); ?> </div> </div> <?php endwhile; } } } wp_reset_query(); // Restore global post data stomped by the_post(). ?> </div> <?php include (TEMPLATEPATH . '/sidebarRight.php'); ?> <?php get_footer(); ?> </div><!--/Wrapper--> <div id="footershadow"></div> </div><!--/Container--> </body> </html>