Insert widgetized area into loop, independent of theme
-
Hi guys,
I thought this would be simple somehow but I guess it isn’t. Let me start by saying that I am no coder but willing to learn a bit if necessary. I was looking for a way to inject one (or more) widgetized area(s) into the wordpress loop, for instance before the 1st or 3rd etc post.
Now I have found a few instructions for that but mostly it consists of registering a dynamic sidebar in functions.php and then hack index.php or category.php etc by looking for “endwhile” and inserting the dynamic sidebar before that.
However, this is very theme dependent. Whenever I switch themes I need to adapt and reinsert that code to fit with the new theme, some of them don’t even seem to have that “endwhile” in index.php.
So I was thinking of implementing this as a plugin, independently of the theme used. I have found a way to register the dynamic sidebar by creating a plugin consisting of a site_functions.php and adding this:
register_sidebar(array('name'=> 'WidgetArea1', 'id' => 'Widget1', 'description' => esc_html__('Widgets appear before 1st post', ''), 'before_widget' => '<section id="%1$s" class="WidgetArea1">', 'after_widget' => '</section>', 'before_title' => '', 'after_title' => '' ));
So now I know I am supposed to add something like this to the loop:
<?php if ($count==1) { dynamic_sidebar(‘WidgetArea1’); } $count = $count + 1; ?>
How and where can I do this (or something else ?) with my plugin so that the widget area appears in every theme, no matter how it displays the blog posts and which layout it uses (standard, masonry, isotope, etc) and without hacking theme files every time I switch themes.
Ideally that would also be extendable to archive or category pages etc
I am actually amazed that there doesn’t seem to be a plugin on the market that can do things like that already. There are thousands of plugins available for wordpress but obviously not for something apparently simple like that. I hope it is possible ?!?
Thanks a lot for your help guys!
AlexPS: If this is really complicated and any of you talented developers out there would prefer to create a plugin that does things like that I would even pay a little. Probably others as well … ??
- The topic ‘Insert widgetized area into loop, independent of theme’ is closed to new replies.