ThemeShaper Forums » Thematic

[closed]

index page as category page

(14 posts)
  • Started 2 years ago by AnotherAndrew
  • Latest reply from diverge
  • This topic is resolved
  1. AnotherAndrew
    Member

    Trying to think this one through. Please help me if you have any ideas.

    I want to have an index page with content that links to other areas of the site. The links may be to pages or posts. Doesn't matter. At any rate, I want to have four unique areas of content. And the content areas might be sized differently. I guess that can be done with CSS.

    I am thinking that the index page could be a category page with posts assigned to an "index" or "home" category, and they could include thumbnails or images.

    To implement, I need a custom category page (with full width), correct?

    What / how would I specify a category page for the "front page displays" in the admin section for the "reading sections"?

    But how do I add just four posts associated to that category page?

    Posted 2 years ago #
  2. kwight
    Member

    Hi,
    I'm not sure I follow you. Your "four unique areas of content" on this page contain links to one page or post each, or a bunch of posts?.. Can you provide a link to an example?

    Posted 2 years ago #
  3. AnotherAndrew
    Member

    They would contain links to different sections of the site, so a bunch of posts that would link to a variety of categories.

    Sorry, I don't have an example.

    But think of a dynamic layout, like a news website front page (NY times, CNN, etc). There might be some extended text that links to the article and the particular section of the site.

    That's what I would like to do.

    Posted 2 years ago #
  4. middlesister
    Member

    You could target the index page with some filters in functions.php, then you would not need a page template.

    function remove_sidebar_on_frontpage() {
        global $post;
    	if ( is_front_page()) {
    		return FALSE;
    	} else {
    		return TRUE;
    	}
    }
    add_filter('thematic_sidebar', 'remove_sidebar_on_frontpage');
    
    function childtheme_override_index_loop() {
    	if( is_front_page() ) {
    		// code for your different sections
    	} else {
    		// your normal index loop goes here
    	}
    }

    The code for your different sections could be anything you like, one loop fetching four posts from a certain category, or four different loops fetching one post each, or static content, or a custom posts type. Like you said, just give the sections a distinct css class/ID and you can style them to your hearts content.

    I guess this is how some news themes deal with "featured" posts/news, give them a certain category and they will show up on the front page featured area. If you have, say three "slots" for featured news, then the loop would fetch the three last posts from the featured category. Is that what you are after?

    Posted 2 years ago #
  5. AnotherAndrew
    Member

    middlesister,

    Exactly what I am aiming for. And better.

    I didn't think of having the most recent posts displaying, just a unique category page for the index....

    But I do want the areas on the index to display some of the latest posts from a particular category, so your idea will work. I will give it a shot. Thanks.

    However, what if I wanted to display some static content, that's not related to any category? And not have it hard coded? Is that possible?

    Posted 2 years ago #
  6. Sounds about right middlesister, if that is what he's after. A bunch of little loops like so:

    $featured = new WP_Query( 'category_name=Featured&posts_per_page=6&orderby=rand' );
    if ( $featured->have_posts() )
    {
    	while ( $featured->have_posts() )
    	{
    		$featured->the_post(); // fill $post with data
    		$content = $post->post_content;
    
    		/* assign styling */
    	}
    	rewind_posts();
    }

    I have demo site that might fit what he means. There is a main featured category up top (the images). The bottom section shows the latest 2 posts from another category on the left, and a latest list of titles from blog posts (another category) to the right of that. The right sidebar lists the latest from yet another category, but it all could be anything he wants.

    -Jeff

    Posted 2 years ago #
  7. middlesister
    Member

    If you want non-hardcoded 'static' content, just use a wordpress Page. Make the loop fetch a page based on page ID or slug and you are good to go. Using Jeff's loop code, let the query be 'pagename=NAME' or 'page_id=NUMBER'. If you don't link to the page from any menus or from anywhere else, the only place where it would be visible would be on the front page.

    Posted 2 years ago #
  8. AnotherAndrew
    Member

    Jeff,

    Yes, that is what I am after! But how do you have multiple loops on a page?

    Hmm, if I was to use your example could I just make it into a function, and customize it so that I have four different categories (and 4 different functions, obviously), and call it in my page?

    Also I don't understand why you commented out "assign styling" in your code. Would that be the containing div that held the loop content?

    Posted 2 years ago #
  9. lol. I commented it out because it's a big long mess of a thing. :)

    Here is the chunk that fills the 2 bottom left posts:

    <div class="recentmiddle">
    <?php
    	$questions = new WP_Query( 'category_name=Questions&posts_per_page=2' );
    	if ( $questions->have_posts() )
    	{
    		$questions->the_post(); // fill $post with data
    		?>
    			<div class="post" id="post-<?php the_ID(); ?>">
    				<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title() ?>"><?php the_title() ?></a></h3>
    				<?php the_excerpt() ?><span><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title() ?>">Read More ...</a></span>
    			</div>
    		<?php
    	}
    	rewind_posts();
    ?>
    </div>

    This is 4 separate loops all in index.php That demo site is not a Thematic site, but using middlesister's code, you would put it all in the 'if ( is_front_page()) {' section in your functions.php.

    -Jeff

    Posted 2 years ago #
  10. AnotherAndrew
    Member

    Jeff,

    That works, but I want to pull content from two separate / different categories.

    So, I guess I need the ability to have four independent loops, on the index page.

    Is this beyond the capability of wordpress, or can it be done?

    Posted 2 years ago #
  11. AnotherAndrew
    Member

    Nevermind, I spoke to soon. Error on my part, using wrong call to categories. Does work.

    But I am only getting one entry per category and not 2 or X.

    Posted 2 years ago #
  12. AnotherAndrew
    Member

    Almost there!

    Now to include the post thumbnail with an excerpt?

    Posted 2 years ago #
  13. AnotherAndrew
    Member

    Got it!

    I love you guys and thematic!

    Thanks!!

    Posted 2 years ago #
  14. Excellent! Good to hear. :)

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.