WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Suburbia theme - sticky post problem (15 posts)

  1. Monkeywiz
    Member
    Posted 1 year ago #

    Not sure if this has already been answered anywhere, can't find it if it has.

    I'm modifying the suburbia theme for a test blog site, by default it shows the two most recent posts as 'featured/sticky'.

    I want to specify which posts show there instead, so I set a couple of them as sticky posts in the admin, but now instead of having two large 'featured/sticky' posts showing, it shows 4 large posts at the top. (the two featured posts, and the the two most recent).

    It then also shows the sticky posts in the normal run of posts below the featured ones.

    Anyone know how/where I need to make changes so that only posts I set as sticky show as 'featured/sticky' and if possible, also no longer display those in the timeline till they're un-stickied?

    Cheers.

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    There are literally thousands of WordPress themes - which means that many people won't be familiar with your particular theme. So a link to your site where people can see the theme might result in more responses.

  3. Monkeywiz
    Member
    Posted 1 year ago #

    D'oh, links below of the theme's demo page showing how it should appear (two large posts with a row of smaller posts below) and a link to my test site with 4 large posts.

    Theme Demo - http://suburbia.wpshower.com/
    My Site - http://test.monkeywiz.com/

    I've tried joining their support forum without success, was hoping someone here might know how to achieve what I'm after (still very new at php, but willing to hack away if anyone can point me in the right direction).

  4. Monkeywiz
    Member
    Posted 1 year ago #

    Managed to find a solution, I've wedged in some code I found about sticky posts here:- http://codex.wordpress.org/Sticky_Posts into the themes displays loops, so the first set only calls sticky posts and the second calls everything apart from sticky posts.

    I'm sure I now have tons of redundant code, and I'm fairly certain it's not the best solution for my particular problem, only time will tell if my implementation of it is robust enough to last, but for now at least it works.

    If anyone needs me to post specific examples, or indeed finds a better way, just let me know.

  5. willynast
    Member
    Posted 1 year ago #

    Would you mind telling us which code from the codex link you posted, and where exactly? I'm having the exact same problem with the 4 big posts instead of just the two stickies at the top.

    I assume you mean the code needs to get posted into the "Loop 1" and "Loop 2" sections of home.php, but not sure exactly which code you used or where to stick it.

  6. Monkeywiz
    Member
    Posted 1 year ago #

    You're exactly right, I added the following above the loops (after the 'offset' block). :-

    <?php
    $sticky = get_option( 'sticky_posts' );
    $args = array(
    	'posts_per_page' => 2,
    	'post__in'  => $sticky,
    	'ignore_sticky_posts' => 2
    );
    query_posts( $args );
    if ( $sticky[0] ) {
    	// insert here your stuff...
    }?>

    And then in the first loop to include only sticky posts I replaced:-

    <?php query_posts('posts_per_page=2&offset='.$offset1); ?>

    with:-

    <?php query_posts($args); ?>

    And in the second loop to not show sticky posts I replaced:-

    <?php query_posts('posts_per_page=5&offset='.$offset2); ?>

    with:-

    <?php query_posts(array( 'post__not_in' => get_option( 'sticky_posts' ) )); ?>

    Make sure you make a backup so you can always change it back if this turns out to not be what you're after, but I hope it gives the desired result for you too.

    Quick note, I've not tried it on extra pages of posts etc as I'm planning on only having one page showing all posts.

  7. willynast
    Member
    Posted 1 year ago #

    Okay - this is *almost* working like a charm.

    This sorted out the mess with the stickies. Which is great.

    The problem I'm running into now is that my third row stops after 2 additional posts. So I have: 2 Stickies in the top row, 5 posts in the second row, and 2 posts in the third row, and then nothing.

    I'm totally fine with just having three rows, but I'd like the third row to be filled.

    I went into Settings > Reading and tried to change the number of posts shown on the front page from 7 to 12, but it keeps bumping the number back to 7 for some reason. (Also, there are 9 posts on the front page, so not really sure what the deal is with that.)

    Check out my page to see what I'm looking at: http://www.allwrite-already.com/

  8. Monkeywiz
    Member
    Posted 1 year ago #

    The 9/7 post thing is because it's not counting the sticky posts (I think at least), so when it says 7 it means 7 + 2 sticky posts.

    Not sure why it won't show more than 7 (9 total) though, not in front of a comp right now, (and on holiday from about 5hrs ago), but if the place I'm saying at from tomorrow has wifi (or at least decent enough 3G) I'll try adding extra posts to my test site to see if I have the same problem, and if not, why not.

    Your site sounds very interesting from the blurb, my wife works in a library and more than once has threatened to start her own novel (usual around nanowrimo), hope all the bugs get worked out.

  9. Monkeywiz
    Member
    Posted 1 year ago #

    Kept bugging me as I may well be out of internet range for 7 days had to check, it's hard coded in the theme functions.php

    Line 52, change posts per page to your desired num (not incl sticky posts).

    Hope that helps.

  10. willynast
    Member
    Posted 1 year ago #

    Yaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay.

    It worked!

    Thanks times infinity for your help. (Will post here if I run into any more issues.

    Definitely tell your wife about the site. We're releasing our first episode of the podcast next week. Got a few episodes in the bank already, really excited about it.

    Have a fun/safe/relaxing trip!

  11. magnuskjarans@gmail.com
    Member
    Posted 1 year ago #

    I´ve got problems with my suburbia web as I get two of my posts double
    and three 2-column-posts though I have marked only two as sticky.

    Can you advice how to fix this so that it looks like in the demo, e.g.
    two 2-column-post (sticky posts) above
    and five 1-column-posts with beneath in one or more rows.

    http://www.nbd.is

    Hope somebody can help. Cheers

    Magnus

    magnuskjarans@gmail.com

    (P.S. My former issue was http://nbdisland.wordpress.com/)

  12. Monkeywiz
    Member
    Posted 1 year ago #

    Hi Magnus,

    If you're happy just having the two most recent posts large at the top then un-sticky the ones you've selected and it will revert to how you expect to see it.

    If like me you want only the posts you select to be shown as larger at the top and you have access to the theme files themselves and can edit them, then the code I've pasted above will probably solve your problem.

    Cheers,

    Adam.

  13. magnuskjarans@gmail.com
    Member
    Posted 1 year ago #

    Thank you ever so much. I now try the the first to see the result.

    Cheers,

    Magnus

  14. visco
    Member
    Posted 1 year ago #

    I hope someone can help me with this issue?

    I can't get 5 text boxes in the bottom area (only 4) as shown on the demo. Today the four are defined as widgets in each there bottom area. I can't find a fifth bottom area.

    I also want to change the background colour of the drop down menu. Where do I change this?

    My site is http://www.tagcopenhagen.wordpress.com

    email michael@tagc.com

  15. peeves6
    Member
    Posted 1 year ago #

    There is another way of manipulating the sticky posts within Suburbia theme.

    This is by using the function is_sticky($post->ID)

    As per WordPress Codex, query_posts is not efficient or recommended. The SQL query fetching yours posts has already been performed when home.php is displayed.

    So remove the query_posts call, use the while loop and add the if statement to check if post is sticky or not. Run the while loop twice, once for displayed sticky posts and a second time for displaying non sticky posts.

    <!-- LOOP1 Sticky Posts -->
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    <!-- Check if sticky post -->
    <?php if (is_sticky($post->ID)) : ?>
    //leave the post two display code as is

    <?php else : ?>
    <?php endif; ?>
    <?php endwhile; ?>
    <?php else : ?>
    <?php endif; ?>

    then,
    <!-- LOOP2 Non sticky posts -->
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    <!-- Check if not a sticky post -->
    <?php if (!is_sticky($post->ID)) : ?>

    Remove call to query_posts and also reset query.
    Add to above any extra code to display only x number of sticky or non sticky posts on the page.

    The advantage is that with query_posts you are making two extra DB calls, once to retrieve sticky posts and another time to retrieve non sticky posts. With the above, you dont have that anymore.

    It seems to work for me...

Topic Closed

This topic has been closed to new replies.

About this Topic