How to create easy accordions in drupal - drupal

Is there a way to easily implement accordions in Drupal 8.
Till now, i've done it with field collection (or paragraph) but my client wish to can put an accordion everywhere in a content where he want. with the fields, i need prepare it on the template.
So i think on something like a shortcode known in WordPress:
[accordion]
[accordion-item id="item-1" title="Title of accordion item"]Drop-down content goes here.[/accordion-item]
[accordion-item id="item-2" title="Second accordion item"]Drop-down content goes here.[/accordion-item]
[accordion-item id="item-3" title="A Third accordion"]Drop-down content goes here.[/accordion-item]
[/accordion]
Or is there maybe some kind of a page builder module for Drupal which allows that and gives a bit more flexibility creating the content?
Thanks for any advice.

Ok so here's a very custom solution (not as easy as requested), but still, I guess I'd do it this way. You'll need FieldGroup module and theme preprocesses knowledge.
Add an extra field in your form(s). It will be a Fieldgroup of a titre input and a body textarea. Configure it so the user can add an infinite amount of elements.
Now lets say you add this token in your wysiwyg : [accordion].
In you theme, create a preprocess function for your node (THEMENAME_preprocess_node), and get the wysiwyg content. Search for the token, and if it's there, place the Fieldgroup content there.
Don't forget to hide the Fieldgroup content on the display.
Finally, in your theme, add an accordion library (or jquery-ui accordion from the core) and apply it on your injected html.
It should do the work.
Edit : You can also go with Views Accordion. But I think it would be a less interesting solution for your client UX.

Related

What is the difference between wordpress widgets and block

I have started learning wordpress recently. I have started from version 5 with this new Gutenberg editor which introduced Blocks. I am little confused regarding difference between this new Blocks concept and old Widgets.
Starting with a Blocks: they appear on page creation and can be added to page, there is nice documentation on wordpress webpage: https://developer.wordpress.org/block-editor/tutorials/block-tutorial/ a lot of stuff related to new blocks.
Everything is fine, but Blocks can be added only to page content and not into areas like: sidebar, footer etc.
For changing content of sidebar,footer areas we need to access Appearance->Widgets area where we can add multiple widgets to specific areas. Also for new Gutenberd Page Builder there is section called widgets available but with less number of widgets than under
Apperance->Widgets section.
Im totally confused. Could someone explain what is the difference betweemn Blocks and Widgets?
Why for areas like sidebar/footer we can add only widgets and editing footer is under Widgets menu?
Why only part of widgets are available for Gutenberg Page Editor
What should i do to create reusable code snippet(some html/css/js logic) to be reused on a page? Should i create a widget and somehow include it to widget section for Gutenberg or maybe i should create this new concept of Block? But i will not reuse my block in footer/sidebar section...
Are widgets something which will gonna die soon in wordpress world and will be totally replaced by Blocks? I remember that in previous version we were able to add widgets to page using some kind of shortcodes, so any widget we want? Is it still possible?.
I will appreciate any comments on that.
The Block Editor is so far being used only to generate "content". In the world of WordPress, that normally very generic word has a very specific meaning: whatever is returned by the function the_content(). Usually it's simply all the text and media input on the edit page of a post or page, though that can be modified by filters. This content is entered either in the classic editor's text box or (now) in one or more Gutenberg Blocks.
Widgets, on the other hand, display content outside the main content, in widget areas that your theme has located outside the main content in headers, sidebars, footers, etc.
I suspect you already know much of this. As to your question about code snippets, the simplest way to re-use code is through WordPress shortcodes. Register your shortcodes in functions.php or in a plugin; enable them in your theme; then use them anywhere. There is now a shortcode Block, by the way, for placing recurring content into main content.

Where to start in editing a wordpress plugin?

I am a newbie in wordpress and I was given the opportunity to edit a certain plugin which is MarketPress, but then I had hard times dealing with it since I'm new to this thing and I don't know where exactly to go, I would want to edit an included dynamic_sidebar but I can't the file on where to edit this. Please help me. :(
Thanks.
Not sure of your level of understanding so forgive me if this is over-simplistic.
The sidebar content is driven by widgets, which is controlled from the Widgets admin panel. The only thing about a sidebar that you should be able to edit by messing with its definition are the wrapping markup for the whole widget and for the title, along with the sidebars name and description. The last two only effect text that shows up in the admin Widgets panel.
However what I describe above is not found with the dynamic_sidebar() method, rather with the register_sidebar() or register_sidebars() methods. These 'define' the name and settings for a sidebar. The dynamic_sidebar() method is the used to implement the sidebar by passing it that sidebars name.
The sidebar is then populated with widgets via the admin Widgets panel.
Typically sidebars are registered from within the functions.php file of a theme, but if a plugin contains templates there no reason why it couldn't also have its own sidebars. As for where the register_sidebar() function is being used in your plugin specifically, I couldn't say. Just search through it using whatever IDE you like, or grep if your comfortable with it.
Hope this helps.

Different sidebars for each Wordpress page

I'm making a Wordpress 2.9.2 theme, and I'd like each page to have its own sidebar than can be edited as easily as the page's content. It would be cumbersome to make a different template file for each sidebar. It would also be weird to add a "custom field" containing all the sidebar text, since I wouldn't be able to use the Visual/HTML editor. What I'd like is to have a tag similar to the tag, but instead of delimiting the content to be shown on the front page, it would split the post's content and sidebar. Is this possible? Or is there a better solution?
Make the sidebars widgetized and than use the widget logic plugin, so you can conditionally include widgets on any and all pages.
Doing this lets you utilize the out of the box widgets, which are awesome, and even integrated third party widgets that are just as great.
Also consider this: You widgetize other areas of your site, like your header, which can now use widgets and widget logic. This makes for a more flexible theme.

drupal: adding simple links to a block

im using Views to output a block, containing latest post titles - simple and working. id now like to add some text links that should be different than the "more" link you can add through the Views UI. they are basically just p-tags with a-tags inside, pointing to a url of my choice.
right now i just inserted the markup in Basic Information > Footer > Full HTML.
is this the standard way of achieving what im after?
You can write custom templates for each row in a view if you want. Have a look at views 2 theming
Theming is a good way to do it but then it adds an additional responsibility to move the theme file when you move the view from one site to the other.
The header and footer are provided so that you can add html and php code to it, so it is definitely the right way to do it or else it would not have been provided in the first place by the module developer.
Also if the urls are related to the drupal site then I would suggest you to use php mode and add the link using l function (http://api.drupal.org/api/drupal/includes--common.inc/function/l/6)

Drupal: how to change taxonomy header on page with items?

I have a menu item like
http://localhost/drupal/?q=category/articles/php
It's supposed to output all stories about PHP,
But in resulting page header (with term name (PHP) ) doesn't look very well.
How can I remove header or change its CSS style?
Your best bet for customizing the page is to use the Views Module and activate the taxonomy_term view. Then, you can add to the header field or even create a new template just for that view.
The Drupal Handbook has a lot of great resources for theming and building views:
http://drupal.org/node/352970
Take a look at Drupal's theming guide:
http://drupal.org/theme-guide
You'll need to understand theming to edit css or html.

Resources