WordPress.org

Ready to get started?Download WordPress

Forums

How to make a Category header or 'sticky'? (17 posts)

  1. mookie
    Member
    Posted 10 years ago #

    What would be the best way to add category header text (paragraph or intro related to that category)? It could be at the top of either the content section or sidebar
    Would I need an approach using a php include statement based on the category name or am I missing something simpler? Can I make a post a 'sticky' that stays in the #1 spot?
    Thx, Mookie

  2. Cena
    Member
    Posted 10 years ago #

    Did you try searching first?

  3. mookie
    Member
    Posted 10 years ago #

    yes I had found this
    http://dinki.mine.nu/word/b2-img/stickyinstructions.txt
    but it seems to make the post a sticky on the main page as well as the category page, not quite what i was looking for. My php is rusty but i'll take closer look. Thx.

  4. TechGnome
    Moderator
    Posted 10 years ago #

    I think what mookie is looking for is to make posts sticky within categories, and not the first page. An interesting idea, not sure how to go about doing it though.....
    TG

  5. Laughinglizard
    Member
    Posted 10 years ago #

    Should be relatively simple. You could add a check within wp-blog-header.php which would check to see if a category is set or not, if it is set, check to see if each sticky is within that category and add to the series of posts.

  6. davidchait
    Member
    Posted 10 years ago #

    Right.
    I'm not on the latest code (still 1.0alpha), but in wp-blog-header, originally had something like:

    if (empty($orderby)) {
    $orderby='date '.$order;

    Which needs to be something more like the following (for sticky support and only-on-cat-page support)

    if (empty($orderby)) {
    $orderby='date '.$order;
    if (!empty($whichcat))
    $orderby .= 'post_status ASC';

    And of course, the sticky hack already requires that the line:

    $where .= ' AND (post_status = "publish"';

    is changed to something like:

    $where .= ' AND (post_status = "publish"' OR post_status = "sticky";

    but you really want it in your case to be:

    $where .= ' AND (post_status = "publish"';
    if (!empty($whichcat))
    $where .= ' OR post_status = "sticky"';

    I assume that's what you are looking for (only show sticky posts in category views AND put them at the top...).
    Gee, I really need to start my own hacks collection, don't I? ;)
    -d
    http://www.chait.net

  7. mookie
    Member
    Posted 10 years ago #

    Wow, thanks David.
    I tried it but had sql errors so I'll have to go back & see what i did wrong. I did the original hack then your modifications. I won't be able to try again until momday but wanted to thank you & others for the quick& helpful response.

  8. phpNeophyte
    Member
    Posted 10 years ago #

    Did anyone get this sorted out? NOW my wife wants the same thing at http://organicgardensite.com (WP1.02 default rewrite rules)
    She wants to be able to create a "preface post" for each category that would be sticky in the category (A little blurb about the category)
    ALSO she doesn't want those posts on the front page.
    So I am thinking I need to make it so only one post goes on the front page, after the one sticky that is the general description of the site in general.
    I have her create her category stickies and after she has done them all we post an article (then no category header "sticky" posts on the front page since only showing one latest post on the front page.)
    Now every time she posts a new article, no matter what category it will be on the front page under the front page sticky AND be the first article on that category page after the sticky at the top of the category (preface for the category)
    Make sense? Possible? Not Possible? Feedback and ideas urgently needed to maintain marital bliss! LOL! Thanks.
    Kevin

  9. davidchait
    Member
    Posted 10 years ago #

    Ummm. I read that post like five times. I think my resulting parsing of your description is 'works as designed'. I could be wrong...
    d

  10. davidchait
    Member
    Posted 10 years ago #

    Okay, I think what you are looking for is to change my above solution:
    if (!empty($whichcat))
    $where .= ' OR post_status = "sticky"';
    to be something like:
    if (!empty($whichcat))
    $where .= ' OR post_status = "sticky"';
    else
    $where .= ' OR (post_status = "sticky" AND $whichcat==7)';
    So that sticky posts in cat #7 show up on the front page and the cat 7 listings view as well.
    -d
    http://www.chait.net

  11. davidchait
    Member
    Posted 10 years ago #

    Jaykul -
    While that makes some sense, the power and flexibility of a full-bore 'post' is simpler to integrate than addition custom processing of the category description. Though I do agree that for simple descriptions, that is certainly a viable approach.
    But the whole post interface makes for simpler management of complex data in the post, and it gets processed the same as all other post content (good if you have hacks/plugins/etc you want processing that content).
    I think both approaches have their uses. Mine was simply an easy extension off the already-greatly-functional StickyPost stuff. ;)
    But good to note that there are usually multiple ways to skin a cat in WP. :) :)
    -d
    http://www.chait.net

  12. phpNeophyte
    Member
    Posted 10 years ago #

    And just to sum up and clarify, I sent David an email clarifying that my wife wants a "sticky" post at the top of each category, an intro explanation of what is in each category. But she also need s an "Intro" sticky on the front page which in my case is "About This Site" ( cat=7 ) so that cat sticky needs to be sticky in 2 places. So that is what he was specifically addressing.
    Maybe my type of questions represent a segment of potential WP users that are not Uber Geek, nor programmers, but are nonetheless interested in WP as an easy to implement, easy to adapt CMS solution. The rule of thumb being K.I.S.S "Keep It Simple Solution". Like the anecdote about (some) women and cars, they could give a hoot about automobile technical specs, they just want to know where to put the gas and the key.
    I'm trying to find the means to make her a site that works within the default behavior of WP as much as possible. She has no clue about 'blogging' and probably never will, and I have no php skills. Nonetheless, I see WP as an easy CMS and so am trying to wrap my head around it from her "static-pages-type-site" perception to make it easy for her to continually add content and not feel like she has a heavy learning curve (which would result in her not doing it if she had to learn about static page integration, my-hacks file, etc. LOL)
    So please be patient with folks like myself, and thank you David for taking the time to be specific, that is the type of explanation I (and many others I'm sure) am seeking. Now where do I put that? In the wp-blog-header? (I have already implemented the original "sticky post hack" successfully.) Thanks.
    Kevin

  13. davidchait
    Member
    Posted 10 years ago #

    It's right where the other sticky code is, within wp-blog-header.php. I'm not on the latest code, and you've modified yours, so you'll have to just find the matching line (or reasonably matching!) and replace them.
    If you can't figure it out, I can always have you make a copy of your wp-blog-header.php accessible as a .phps-extension file, and I can try to quickly find and tell you the changes (or just send you a changed file). But I generally recommend if you're going to be using this stuff and modifying it, it's definitely worth knowing enough to make these kinds of minor (few lines) changes yourself. ;)
    -d

  14. phpNeophyte
    Member
    Posted 10 years ago #

    David,
    I implemented the changes for 1.0 & 1.01+ from LaughingLizard's Sticky post hack at
    http://weblogtoolscollection.com/b2-img/stickyinstructions.txt
    My wp-blog-header is at http://organicgardensite.com/wp-blog-header.phps I figured it would be safer if you saw where I made the changes to get the sticky post hack working before I go about mucking it up in case your proposed approach might need to be implemented/integrated in some of the same various corresponding places LauhingLizard's changes were implemented. I sure wouldn't know. "Find and tell" works for me, LaughingLizard's clear step-by-step was easy to follow.
    Thanks for taking the time to look at this idea. I appreciate it.
    Kevin

  15. Anonymous
    Unregistered
    Posted 10 years ago #

    @phyNeophyte. Have you considered divorce ? :-)

  16. davidchait
    Member
    Posted 10 years ago #

    Hey phpNeo -
    Yes, looking at your code, I believe my original changes, plus my additional revised statement, should apply just fine to your file and should 'work as designed'. The above instructions from my two posts should be pretty self explanatory -- just find the matching code.
    Let me know if you run into any issues. And a reminder to all to always backup before you make significant changes, or test them in an offline environment.
    -d
    http://www.chait.net

  17. phpNeophyte
    Member
    Posted 10 years ago #

    O.K Here's what I Did;
    if (empty($orderby)) {
    $orderby='date '.$order;
    Which needs to be something more like the following;
    if (empty($orderby)) {
    $orderby='date '.$order;
    if (!empty($whichcat))
    $where .= ' OR post_status = "sticky"';
    else
    $where .= ' OR (post_status = "sticky" AND $whichcat==7)';
    And of course, the sticky hack already requires that the line:
    $where .= ' AND (post_status = "publish"';
    is changed to something like:
    $where .= ' AND (post_status = "publish"' OR post_status = "sticky";
    but you really want it in your case to be:
    $where .= ' AND (post_status = "publish"';
    if (!empty($whichcat))
    $where .= ' OR post_status = "sticky"';
    else
    $where .= ' OR (post_status = "sticky" AND $whichcat==7)';
    This is the error I get:
    SQL/DB Error:
    [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '==7) AND post_date <= '2004-04-25 11:26:19' AND (post_status = ]
    SELECT DISTINCT * FROM wp_posts WHERE 1=1 OR (post_status = "sticky" AND $whichcat==7) AND post_date <= '2004-04-25 11:26:19' AND (post_status = "publish" OR post_status = "sticky") ORDER BY post_status DESC, post_date DESC LIMIT 2
    Kevin

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.