• Resolved joyner.cn

    (@joynercn)


    I’m developing a site that I’d like to have different styles of listing different categories. So, my plan is to simply have a statement in entry.php that redirects to the entry file for the proper category.

    I’m doing this:

    <?php
    	echo 'Home';
    
    	if(in_category('people'))
    	{
    		include(TEMPLATEPATH.'/includes/entry-people.php');
    	}
    	else if(in_category('projects'))
    	{
    		include(TEMPLATEPATH.'/includes/entry-projects.php');
    	}
    	else if(in_category('blog'))
    	{
    		include(TEMPLATEPATH.'/includes/entry-blog.php');
    	}
    	else if(in_category('media'))
    	{
    		include(TEMPLATEPATH.'/includes/entry-media.php');
    	}
    	else if(in_category('news'))
    	{
    		include(TEMPLATEPATH.'/includes/entry-news.php');
    	}
    	else if(in_category('publications'))
    	{
    		include(TEMPLATEPATH.'/includes/entry-publications.php');
    	}
    	else
    	{
    		include(TEMPLATEPATH.'/includes/entry-default.php');
    	}
    ?>

    However, the other pages don’t seem to load. How many things am I doing wrong? I’ve verified that the if statements are correctly triggering for each category, and that the path included in the include statement is indeed the right path to the file.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter joyner.cn

    (@joynercn)

    Never mind. The above code works perfectly. I had copied a file several times to create the entry- files, and that file itself had an error in it — so while I assume it was the redirect failing, it was every page the redirect could lead to.

    Howdy joyner.cn,

    I don’t have enough info to answer your question straight away, but I have a few questions to clarify. Of course, as with many things in theming, there are several ways to approach this.

    1. what template is entry.php used for in your theme, or is it a page template?
    2. did you know you can make separate category templates? For a general implementation, you could use category.php and put conditional(s) in to serve your different categories, or you can use the more specific category-id.php or category-slug.php, where the id or slug match the category for which you’re making the template.

    You might also consider using the WP function get_template_part() to pull in partial templates, rather than a straight include. If you did, it might look like this:

    <?php get_template_part( 'includes/entry', 'default' ); ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Developing different page listings for each category?’ is closed to new replies.