Can WP Plugins Alter themes

by 8 replies
10
I'm wondering if it's possible for a WP plugin to alter the main loop, hook into the main loop and override it.

Or would it be more practical to just create a theme with the required functionality?


So for instance the main loop prints out all posts on the blog in standard blog style, newest first in descending order.

Could a plugin change the main theme's files so that instead of doing that it just showed the 3 latest posts? Or is there simply too many theme variations.
#programming #alter #plugins #themes
  • Yes you can make a plugin to change it or make a custom template and define as the index or use a custom query or Function Reference/query posts « WordPress Codex

    In addition here is one plugin that changes main loop if you wanted to look into the code yourself:
    http://wordpress.org/extend/plugins/custom-post-order/

    And one for the post limits:
    http://wordpress.org/extend/plugins/custom-post-limits/

    You will have it easier by looking into their code if you want to make your own.
    • [1] reply
    • Thanks mate, actually not quite what I was looking for. But hopefully those plugins will shed some light.

      I didn't want to change the loop using that function, I wanted to insert some code into the loop via a plugin.
      Just not sure how I can change template files, when i don't know what the template will be at any one time...

      For instance, Bob could be using TwentyEleven, in which case I need to change archives, index, page, search. But Sarah could be using a Professional $120 theme which needs the above and 'portfolio', 'sitemap', 'timeline' and a couple others changed.

      I think my best bet is to create a theme, because I can't see how it could possibly be done using a plugin when there's so many theme variations...
  • No problem been there.
  • That's what I need to figure out, if it's possible or not.
  • You could try to hook see if this is what u need:
    Plugin API/Action Reference/pre get posts « WordPress Codex

    Well you can register it to the database with a plugin so you can handle each separated.
    • [ 1 ] Thanks
  • You'd be getting into theme territory with a plugin like that, and I rather think you'll be opening yourself up to a ton of support requests. What if the user's theme doesn't use the 'standard' WP loop to display content? What about custom post types?
    • [ 1 ] Thanks
  • Thanks CGI I think that's what I need...

    Is there a list of all Action Hooks and the other kind of hook... forgot what it's called.
    Like a phpdoc (javadoc style) for WP?
  • Am only aware of this:
    Plugin API/Hooks « WordPress Codex
    • [ 1 ] Thanks

Next Topics on Trending Feed

  • 10

    I'm wondering if it's possible for a WP plugin to alter the main loop, hook into the main loop and override it. Or would it be more practical to just create a theme with the required functionality?