Support » Developing with WordPress » Customising how a post from a paticular category is viewed on homepage

  • Resolved John


    Is there a way to change the behavior and look of a post from a particular category on the homepage or within the loop?

    Let me be more specific. I’m a webmaster for a website/blog for a pastor who wants to have a sermon posted on a weekly basis. The sermon starts with the verse the sermon is about then the scripture reading followed by the message. On the homepage and/or on the month archive pages I would like to have the posts which fall in the sermon category (or in sub categories thereof) to show the verse which is at the top and an excerpt of the message.
    How can I do this without changing the way posts form other categories look and behave?
    Secondly there is an audio version of the sermon posted in FLV form using the Flash Video Player plugin. I would like this player to be at the top of the post’s page but on that page only (not on any archive, category or any list pages) I’m good with XHTML an CSS but PHP is new to me. I can however understand PHP when I see the code. I just don’t know how to write PHP from scratch.
    I know I’m asking for a lot but anything that will bring me closer to my goal would be much appreciated.

Viewing 6 replies - 1 through 6 (of 6 total)
  • I did it this way:

    <?php query_posts('category_name=YOURCATEGORYSLUGHERE&showposts=2'); ?>
    		$wp_query->is_category = false;
    		$wp_query->is_archive = false;
    		$wp_query->is_home = true;
    	<?php while (have_posts()) : the_post(); ?>
    		<div class="post" id="post-<?php the_ID(); ?>">
    		<h2 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    		<p><a href="<?php the_permalink(); ?>"><?php the_excerpt(); ?></a></p>
    	<?php endwhile; ?>

    The first section ($wp_query-> etc) is explained here

    Thanks ChantalC for the code. But I’m unsure about if it’ll do what I’m looking for.
    If I understand the code correctly it will display only the posts of one category listed separately in it’s own list. I don’t want to create a separate list for a specified category. I don’t want to change the chronological order of the posts nor skip categories from appearing in the list.
    I want all posts, regardless of category, to show up on the home and archive pages in the default way like it does on any clean install of WordPress. Then I want one of the categories (+sub categories) to display the optional excerpt in the list on the home and archive pages instead of the full posts that the other categories have.
    Maybe I’m approaching it in a too complicated way.

    If I could have one of my categories (+sub categories)to display the content of the optional excerpt field instead of the full post that would be a good solution for me.

    I was having a little trouble wording my question in my initial post. My bad if it was unclear or confusing.

    If all you require is to handle the display of posts in a category different from all others, see:

    Thank you so much Kafkaesqui. This is what I’m looking for. I’m new to WordPress and therefore have occasional problems finding what I’m looking for in the Doc’s section.

    Is there a way around the having to list each child category? The category I want to display differently has 68 sub categories and that’s gonna get real messy if I have to list each one with the PHP || (logical OR) expression.

    Again thanks for your help.

    Could I achieve the same thing if I used a specific tag for all the posts in these categories and use the is_tag instead of in_category ?

    Okay, forget the ignorant question about the is_tag.
    After a tedious struggle with the PHP syntax, I got it to work on the frontpage (index.php) using the in_category function. I’m still struggling with the syntax in archive.php but I’ll figure it out. I’ll be making a category template for the single.php. My initial question was answered in the link Kaf provided.

    Thanks Kaf.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Customising how a post from a paticular category is viewed on homepage’ is closed to new replies.