• Hi there!

    After running around in loops, I was finally redirected to this plugin to try to add some special functionality on a site’s theme, which seems to be hard to do otherwise.

    Here is the idea: having some special HTML for certain categories/archives (almost all, in fact). The HTML changes for each case — it’s a list of buttons, links, images — but from the perspective of the backoffice, they just need to change a regular post and flag it as sticky for that category/archive. Simple so far.

    Then, on the theme’s loop, all I need to do is to figure out if a certain article is sticky or not. If it is, then it pulls in a template part (yes, a whole template part) for that article. This template part will have shortcodes and the such, so it really needs to go through all the regular WP filtering system.

    Doing it on the Homepage is a piece of cake: just check for is_sticky() inside the loop, and, if it’s true, add the appropriate template part. If not, then it’s a regular article, and it uses the normal templating for that. Simple!

    Doing it on other category/taxonomy/archive pages is a problem, since is_sticky() will not work, of course. So I need the equivalent of that. CSS classes are certainly useful, but just to a degree: the HTML hasn’t been rendered yet when I need it to change the template. Remember, this is not merely styling and adding/removing CSS blocks — which would be possible with a bit of JS. It’s fully going through the whole WP engine, using shortcodes, and so forth, and displaying an article with a completely different set of rules.

    My first idea was to add a secondary loop on the theme on a separate block, checking what category WP is currently in, and pulling the appropriate code if there is a sticky post in that category, just on that block (mirroring the way other CMS work). But this would be rather unflexible, i.e. working with a hard-coded table of post IDs and categories. Messy! Users will certainly delete articles by mistake and so forth! So, using a plugin that lets articles be sticky sounds like a far better approach. Now I just need a function to test if they’re sticky or not ??

    How could this be done with Q2W3 Post Order?

    https://www.ads-software.com/extend/plugins/q2w3-post-order/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Max Bond

    (@max-bond)

    Hi!

    I don’t recommend to use sticky posts feature and Q2W3 Post order at the same time. In this case there are many problems…

    CSS classes are certainly useful, but just to a degree: the HTML hasn’t been rendered yet when I need it to change the template.

    But you can get all post classes right in the loop by using function get_post_class()! You’ll get an array of default classes. Among them will be classes setted by Q2W3 Post Order, so you can test is the post in sorted group, or even the position of the post.

    Thread Starter Gwyneth Llewelyn

    (@gwynethllewelyn)

    Great, thanks! I was probably unclear on my request: I didn’t want to use the default WP sticky posts with Q2W3 Post Order at the same time, but emulate the is_sticky() functionality while using Q2W3 Post Order.

    Using get_post_class() is a very welcome suggestion. I’ll try it out and see what functions I can use for what I want…

    Thanks again for your suggestion!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Theme support — using a is_sticky() variant?’ is closed to new replies.