Forums

Pages content relative to author/category/tag (2 posts)

  1. Noromami
    Member
    Posted 2 years ago #

    So here's the breakdown. I'm working on a website for my church, and learning WordPress at the same time. It's a challenge, for sure. I'm using Celestial Aura by dkszone.net as the base theme. It's pretty bare bones on extra template files, which is fine. I'm trying to build Pages that will display:

    The Page Title
    The Page Contents
    Posts related to this page.

    The catch is, of course, that I would like the template to match the page title to the posts. I've read the posts on the forums related to doing this with a category,(http://wordpress.org/support/topic/318531
    ) and have successfully gotten that working. (though I'll admit I have no idea how it does what it does)

    Next, I would like to re-purpose this code on two more custom page templates to work in the same way for the author's user names and tags. The idea is that we'll be providing a different user name for each department/ministry/etc., providing their main page. Then sub-pages will be separated by categories, and tags may be used traditionally, but I'm not sure and would prefer to be prepared in case they get used as another page option.

    The current code for categories is:

    <?php
    /*
    Template Name: Category 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 &raquo;', '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>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 &raquo;', '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>

    and that template in use can be seen at: http://northrunbaptist.org/wordpress/ministries/music

    Thanks in advance for any help on this!

  2. Noromami
    Member
    Posted 2 years ago #

    bump

    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 &raquo;', '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 &raquo;', '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>

Topic Closed

This topic has been closed to new replies.

About this Topic