WordPress.org

Ready to get started?Download WordPress

Forums

One category on Home page, all else on Blog page (7 posts)

  1. sethsinner
    Member
    Posted 4 years ago #

    Hi there,

    I am wondering if it is possible to set only one category to show on my Home page and all the other ones on my Blog page. I'm using WordPress as CMS, and configured it to display my home page as Home and the posts page as Blog.
    I've tried to use the Frontpage Manager plugin, but it doesn't work like this. Hope you guys out there have a solution.
    Thanks!

    EDIT: I need to show only one post, the latest one.

  2. Michael Fields
    Themer
    Posted 4 years ago #

    I'm using WordPress as CMS

    I think that it's safe to say that we are all using wordpress as a CMS.

    I am wondering if it is possible to set only one category to show on my Home page and all the other ones on my Blog page. I'm using WordPress as CMS, and configured it to display my home page as Home and the posts page as Blog.

    Yes this is possible. You will want to add the following code to your theme's page.php file:

    <?php
    $front_page_category = get_posts( 'category=14' );
    if( is_front_page() && $front_page_category ) {
    	foreach( $front_page_category as $post ) {
    		setup_postdata( $post );
    		/* do loop stuff here */
    	}
    }
    ?>

    You should change the value of "category" in the query_posts() function to the category id that you wish to have displayed.

  3. sethsinner
    Member
    Posted 4 years ago #

    Well I have already found many solutions like this on Google, and every time I try any it gives me the same result: still no posts on my Home page. But when I go to the Blog page, there the changes were made. I don't know how this happens, but I think it has something to do with the "reading" settings, where I set Home as frontpage and Blog as my posts pages.
    Anyway, thanks for your help mfields. But I'm still looking for an answer on forums, google, etc.

  4. Michael Fields
    Themer
    Posted 4 years ago #

    Very strange. Are you sure that you are adding the code to page.php and not index.php? Also does your theme have a home.php file? If so, try to temporarily rename it to __home.php. That file is sneaky and can sometimes cause unintended headaches. Best of luck.

  5. sethsinner
    Member
    Posted 4 years ago #

    Well, thanks mfields, I managed to do it with a small mod on the code. I used this:

    if (is_front_page()) {
            query_posts('cat=3&showposts=1');
  6. jeremygillies
    Member
    Posted 4 years ago #

    Sorry to resurrect this post - I want to achieve the same result as the OP (albeit not just showing 1 post on the homepage) but unable to get any success. I'm no PHP expert, more of a tinkerer. So apologies in advance for fundamental errors.

    In WP admin: Settings > Reading I've set front page as "Home" and posts page as "Blog". I'm editing page.php and adding the above code to the page. I'm struggling with exactly where to add it.

    If start with ...

    <div id="content" class="narrowcolumn">
    		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<div class="post" id="post-<?php the_ID(); ?>">
    		<h2><?php the_title(); ?></h2>
    			<div class="entry">
    				<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    				<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    			</div>
    		</div>
    		<?php endwhile; endif; ?>
    	<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    	</div>

    should I end with ...

    <div id="content" class="narrowcolumn">
    		<?php
    		$front_page_category = get_posts( 'category=19' );
    		if( is_front_page() && $front_page_category ) {
    			foreach( $front_page_category as $post ) {
    				setup_postdata( $post );
    
    				/* do loop stuff here */
    				<div class="post" id="post-<?php the_ID(); ?>">
    					<h2><?php the_title(); ?></h2>
    					<div class="entry">
    					<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    					<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    					</div>
    				</div>
    				}
    			}
    			?>
    		<?php endwhile; endif; ?>
    	<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    	</div>
    ?
    This returns an error (blank page)

    Any help greatly appreciated

  7. jeremygillies
    Member
    Posted 4 years ago #

    No worries - sorted it now, code in wrong place - learned much in the process!

Topic Closed

This topic has been closed to new replies.

About this Topic