Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Post-Kicker, -Byline & -Footer (http://forum.bytesforall.com/forumdisplay.php?f=17)
-   -   [SOLVED] How to show single post special category on static home page?? (http://forum.bytesforall.com/showthread.php?t=837)

Shepherd Jim Mar 17, 2009 09:52 AM

[SOLVED] How to show single post special category on static home page??
 
I've set up the home/landing page as a static page. Most of what will show on that "Home" will be static "Welcome to our website....etc".

But, in the middle of the page I want to have a "News from the Shop" announcement (might even be in a framed "box").

I thought the "Inline Post" plugin would be the solution, but in order to update what post would show on the page, I would have to go to the Dashboard, edit the page's html, changing the post number contained between the double square brackets "[[post##]]"

That's clunky. I want to be able to publish the "news annoucement" as a post, using a special category. The most recent post in that category will show up in the "News" box on the home page.

I found this code:

<?php
query_posts('showposts=1&cat=3');
while(have_posts()) : the_post();
?>
<ul>
<li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>

<ul><li><?php the_content_limit(520); ?></li>
</ul>
</li>
</ul>
<?php endwhile; ?>
by Mr. Balkhis at http://www.balkhis.com/web-designs-r...-in-wordpress/.

In the line -- query_posts('showposts=1&cat=3');, the showposts= value sets how many posts will be displayed and cat= value specs which single category the displayed post(s) come from.

This sounds like it will work, but I can't figure out where to put it. :o :confused:

Flynn Mar 18, 2009 10:04 AM

Put the following in index.php, for instance right before <?php get_footer(); ?>

PHP Code:

<?php if ( is_front_page() ) { ?>
<?php $my_query 
= new WP_Query('category_name=featured&showposts=5');
while (
$my_query->have_posts()) : $my_query->the_post(); ?>

All the code parts from index.php here, depending on what you want to display
I.e. Post Kicker, Post, Post Footer...

What you put here will be repeated for every post as specified above 
(5 posts from the category "featured")

category_name is the URL name of the category i.e.:
 /.../category/featured/.../ 
and not the category title: 
"Featured"

<?php endwhile; ?>
<?php 
?>

This would display 5 posts from the category "Featured".

Replace <?php if ( is_front_page() ) { ?> with
<?php if ( is_page() ) { ?> to display on all pages
<?php if ( is_page('17') ) { ?> to display on the page with the ID 7

query_posts would be used to modify the main post loop, but that's already being used to display the post (= "Page" page content) on the page.

Shepherd Jim Mar 18, 2009 11:21 PM

Okay! With what you provided I've figured out how to make a single post (and/or parts thereof) in my "Announcements" category appear either right after the header or right before the footer of my static pages. ...but unfortunately it appears on ALL the pages.

How can I just have the "announcements" post display on the home page and NOT on ALL of the other pages?

strangelove Mar 19, 2009 06:17 AM

Jim,

Provide a link to your blog please. I would like to follow what you are doing with it.

Thanks,

Michael

Flynn Mar 19, 2009 06:44 AM

Quote:

Originally Posted by Shepherd Jim (Post 3234)
Okay! With what you provided I've figured out how to make a single post (and/or parts thereof) in my "Announcements" category appear either right after the header or right before the footer of my static pages. ...but unfortunately it appears on ALL the pages.

How can I just have the "announcements" post display on the home page and NOT on ALL of the other pages?

Sorry, I missed that part. I updated the code above with if ( is_front_page() )

is_front_page works from WP 2.5 on, with a static page set as the the homepage, at Site Admin -> Settings -> Reading -> Front page displays -> A static page

Shepherd Jim Mar 19, 2009 07:42 AM

Quote:

Originally Posted by strangelove (Post 3241)
Jim,

Provide a link to your blog please. I would like to follow what you are doing with it.
<snip>

Ouch! This is like letting someone watch as you try on new underwear -- boxers or briefs?

Please understand that some day "Shepherd Jim dot com" will be my personal blog. But, right now I'm using it as a WP testbed -- trying stuff out in prep for installation on the real website which is now live and visible to the world.

I've attempted on two occasions to create a "local" installation of WP following instructions in the Codex, but both times it got scary and I gave up.
-- Maybe Flynn will type us up an easy to follow and understand "how to"? hint hint :o ;) --

So, NOTHING on "Shepherd Jim" is real. I've created great blocks of text/content by copying and pasting, pasting and pasting.

http://shepherdjim.com/wp/


All times are GMT -6. The time now is 07:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.