Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Center area post/pages (http://forum.bytesforall.com/forumdisplay.php?f=32)
-   -   Limit number of sticky posts on home page (http://forum.bytesforall.com/showthread.php?t=8368)

True Jul 19, 2010 01:30 PM

Limit number of sticky posts on home page
 
Hi there,

I am busy working on my site and I want to be able to limit the amount of sticky posts shown on the homepage.

In other words, on the homepage, I want there to be the 4 most sticky posts and then the rest of the posts in date order below them. I want this only on the homepage (on on other pages the normal posts in date order must be shown).

I know I probably need to edit the loop. Can you please advise? This is what I currently have in the loop:

PHP Code:

<?php /* For SINGLE post pages if activated at ATO -> Next/Previous Navigation: */
bfa_next_previous_post_links('Top'); ?>

<?php /* Post Container starts here */
if ( function_exists('post_class') ) { ?>
<div <?php if ( is_page() ) { post_class('post'); } else { post_class("$odd_or_even"); } ?> id="post-<?php the_ID(); ?>">
<?php } else { ?>
<div class="<?php echo ( is_page() ? 'page ' '' ) . $odd_or_even ' post" id="post-'the_ID(); ?>">
<?php ?>

<?php bfa_post_kicker('<div class="post-kicker">','</div>'); ?>

<?php bfa_post_headline('<div class="post-headline">','</div>'); ?>

<?php bfa_post_byline('<div class="post-byline">','</div>'); ?>

<?php bfa_post_bodycopy('<div class="post-bodycopy clearfix">','</div>'); ?>

<?php bfa_post_pagination('<p class="post-pagination"><strong>'.__('Pages:','atahualpa').'</strong>','</p>'); ?>

<?php bfa_post_footer('<div class="post-footer">','</div>'); ?>

</div><!-- / Post -->

Thanks for your time :)

lmilesw Jul 19, 2010 02:15 PM

You might want to look at AStickyPostOrderER plugin as opposed to fiddling with code.

True Jul 19, 2010 02:27 PM

I have given that plugin a try - but its way more than I need. In fact, its just an extra step and I would prefer the loop code to do it automatically.

All I want to do is limit the number of sticky posts shown.

This site shows the code to insert: http://justintadlock.com/archives/20...s-in-wordpress

However, Atahualpa uses a loop code that seems to be different from other loops that I have seen.

Can anyone else help? I will be so thankful!

lmilesw Jul 19, 2010 02:41 PM

Have you tried sticking that code in the "ATO>Style & edit CENTER COLUMN>Content ABOVE the LOOP" box? I just did that and it worked pretty sweet. Nice catch on that code. That's a keeper.

lmilesw Jul 19, 2010 02:46 PM

I just discovered that the stickies are not limited to the Home page. I will have to test a bit.

lmilesw Jul 19, 2010 02:58 PM

This works. I just put at the bottom of the ATO>Style & edit CENTER COLUMN>Content ABOVE the LOOP" box
HTML Code:

<?php if ( is_front_page() ) { ?>
<?php
    /* Get all sticky posts */
    $sticky = get_option( 'sticky_posts' );

    /* Sort the stickies with the newest ones at the top */
    rsort( $sticky );

    /* Get the 2 newest stickies (change 2 for a different number) */
    $sticky = array_slice( $sticky, 0, 2 );

    /* Query sticky posts */
    query_posts( array( 'post__in' =>
$sticky, 'caller_get_posts' => 1 ) );
?>
<?php } ?>


True Jul 19, 2010 04:45 PM

lmilesw, I did that exactly as you said and it works. However, it shows just the sticky posts and thats it.
What I would love now is for the rest of the blog posts to show under these sticky posts.

Any ideas?

lmilesw Jul 19, 2010 06:02 PM

I see what you mean and I have been fiddling with this code for a couple of hours now. I did find that the following works as the previous but has a bit less code.
HTML Code:

<?php    if ( is_front_page ){
    /* Get all sticky posts */
    $sticky = get_option( 'sticky_posts' );

    /* Sort the stickies with the newest ones at the top */
    rsort( $sticky );

    /* Get the 2 newest stickies (change 2 for a different number) */
    $sticky = array_slice( $sticky, 0, 2 );

    /* Query sticky posts */
    query_posts( array( 'post__in' =>
$sticky, 'caller_get_posts' => 1 ) ); }
?>

I put this in the "ABOVE the LOOP" box but cannot figure out how to get it to continue with the regular posts.

Are there any coders out there who can help?


All times are GMT -6. The time now is 03:41 AM.

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