How to use only one child theme but have custom text for each site - wordpress-theming

I am using wordpress multisite for 5 websites. I created a child theme off of the parent so all sites have the same theme, but we have a need for slightly different introduction text at the top of the home pages.
The theme I am using has 3 columns but only has widget-able functionality in column 2 and 3, but the main content area does not have a widget area. Otherwise i would have dropped in a text widget for what i want here.
My question is what is the best way to add this text?
1.) Would I do this in functions.txt? Something like if(site1) echo, elsif(site2) echo, or is there an easier way than this?
2.) Is there a way to do this by editing the theme files and using some short of shortcode? But then where would i define what text to place in there based on the site thats loading?
Please provide a simple example in code if possible. Thanks in advance!

step 1, add to your function.php
<?php
/**
* Register our sidebars and widgetized areas.
*
*/
function arphabet_widgets_init() {
register_sidebar( array(
'name' => 'Column 1',
'id' => 'column_1',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'arphabet_widgets_init' );
step 2, now you will find the widget area in your dashboard Appearance/Widgets, add your content to it.
step 3 add <?php dynamic_sidebar( 'column_1' ); ?> in your template where you want to have column 1

Beside coding the theme there are also other way maybe easier ...
Use this plugin to create widget zone inside a page:
Widgets on Pages
Versione 0.0.12 | by Todd Halfpenny
Use this plugin so you can display or not the widget deending on what page you are:
Dynamic Widgets
Versione 1.5.6 | by Qurl

Related

Gutenberg Templates: Core Block Attributes

The Gutenberg Handbook currently has a short entry for creating whole templates of blocks used e.g. for Custom Post Types or the like.
https://wordpress.org/gutenberg/handbook/templates/
It seems to be missing a comprehensive overview of the core/-Blocks though. Especially the available attributes are interesting here. Is there a reference-entry I am just missing?
To elaborate:
By playing around, I found out a few things. E.g. preformatted blocks do take the formatting of a php file like line breaks, indends and tabs, which makes them a bit sensitive..
array( 'core/preformatted', array(
'content' => 'Grundlegende Fakten:
Operator: Max Mustermann
Wo: City, Country
Wer: 99999 Kinder
Wieviel: 99999 Angestellte',
) ),
This does translate into:
(note that every tab or indent before later lines would have been taken over as well)
So - what other possibilities do i have to modify the 'content' and 'placeholder' attributes? Can I make use of the fact that they are arrays and insert selectors or other html like .. This does NOT work:
array( 'core/preformatted', array(
'content' => array('selector' => 'h1', 'content' => 'Does this do anything?'),
) ),
..But this DOES:
array( 'core/preformatted', array(
'content' => array('Does', 'this', 'do', 'anything?'),
) ),
And where can I find a comprehensive list of first order attributes, since e.g it's not always clear whether a core/block will take a 'text'-string or a 'content'-array and so on..
To partly answer my own question:
As mentioned in this git issue you can use
console.log(wp.blocks.getBlockTypes());
in the browser console after all the Gutenberg magic loaded (e.g. in the editor window of a post) to show all currently registered blocks, inluding their attributes.
Definitely a helpful tool!
Another Info-Source:
The Git-Project of Gutenberg holds all core blocks and their properties can be accessed by
Name-of-Block/index.js
Then find: const blockAttributes =

Kartik Gridview conflict with my templates menu

I have a template that i was using for my project.
Look at the picture below:
This is when i am not using the kartikGrid. the dropdown menu running as well as the template want.
look at the image below:
this is when i use kartik, the dropdown menu not running anymore.
can some body tell me why it happen.
The template using different bootsrap version with kartik.
thaks.
Hope some body help me.
Imaginaroom, that did the trick for me thank you.
My top menu wasn't responding (direct link, or drop down menu) after kartik was used. I added an id to my menu widget and it did the trick.
echo Nav::widget([
'id' => 'topMenuID',
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
Manually assign different ids to all widgets, so there won't be any conflicts.
If you don't assign ids to widgets, yii gives them one automatically, but the problem occures when loading data with ajax or pjax, then Yii cannot know which ids are already used in the page.
Every widget in Yii2 has a property 'id' that you can assign in configuration array when calling a widget.
Add this code in layout or page that has problem:
$this->registerJs( "$(document).ready(function() { $('.dropdown-toggle').dropdown(); });", View::POS_END, 'ecommerceProductJs' );

How to render custom menu with childs for nth depth in drupal 7

I found similar answer for my question:
How to print a custom menu in Drupal 7?
but, it is not rendering child with nth depth.
Also, I want to give bootstrap css class to menu item.
Effort
I have created custom menu from
structure > menu
with the name menu-top-course-menu machine name. Now I have this menu rendered in my page template file:
print theme(
'links',
array(
'links' => menu_navigation_links('menu-top-course-menu'),
'attributes' => array(
'class'=> array(
'links',
'menu-top-course-menu'
)
)
)
);
How can I achieve this? Please help me.
Did you try menu block module:
https://www.drupal.org/project/menu_block
https://www.drupal.org/node/1934824
I'm personally using my custom code to generate menu html.
I get menu tree structure with menu_tree_all_data():
$tree = menu_tree_all_data($params['menu']);
https://api.drupal.org/api/drupal/includes!menu.inc/function/menu_tree_all_data/7
Then I'm calling:
menu_tree_add_active_path($tree);
So, it will mark active item well. I think that function is part of that menu block module so you must add dependency for that block to your module.
And then I'm crawling that tree on my own and have full freedom to generate HTML I want.
It's not that easy, but at end I have the code I want, so if everything else fails...

How do I change the HTML that is created with links in Wordpress?

I am trying to create a Wordpress template from static HTML that I made a while back. In the HTML there is a <span> tag within each link in the main navigation menu. It looks like this:
https://www.dropbox.com/s/52zgm8kpj8cfb51/Screenshot%202014-08-25%2018.35.47.png?dl=0
The span accounts for the small tab-like extension to the left of the links. This is to give the page a three-dimensional effect. Unfortunately, when I converted the HTML to a Wordpress theme, I was not able to find how to do this whilst making use of Wordpress' dynamic menu function. This creates the links automatically and generates the HTML. I was wondering if anyone knew a way in which I could edit the generated hyperlinks to include the <span> tag.
Assuming you're using the wp_nav_menu() function to generate the menu links, I believe the code you're looking for is:
<?php
$defaults = array(
'link_before' => '<span>',
'link_after' => '</span>'
);
wp_nav_menu( $defaults );
?>
http://codex.wordpress.org/Function_Reference/wp_nav_menu

Can't seem to widgetize a sidebar for a custom Wordpress theme

I was brought in to make a quick Wordpress theme for a client's existing site. Using the existing site's CSS and JS, and skeleton HTML, I was able to get the theme working in virtually every way except some. For starters, I can't seem to 'widgetize' the sidebar.
The HTML for the sidebar, before attempting to register for widgets, was as follows:
<div class="wms-column wms-column-nav">
<div class="wms-column-nav-body">
<h2>Blog</h2>
</div>
</div>
Bear in mind that I can add html inside of the inner div, but I cannot change the two outer divs. They must remain.
After reading http://codex.wordpress.org/Widgetizing_Themes and trying several examples, I get nothing but errors. Naturally, the widget area therefore refuses to show in Dashboard > Appearances.
How do I convert the above code to function as a widget-accepting sidebar? Is having id="sidebar" necessary? And are titles needed? The Codex page seems to imply the way you format the titles depends on the overall approach (example: divs vs. lists). The impression I am getting is that you're making a template that the widgets use over and over to kick out content. I figured you just were telling WP where to put widgets (and all of their content / format / intricacies were handling in the widget's code).
Widgetizing a theme a basically two steps.
Register your sidebar
Add the registered sidebar to the theme
In functions.php
From the Codex page for register_sidebar;
register_sidebar(array(
'name' => __( 'Right Hand Sidebar' ),
'id' => 'right-sidebar',
'description' => __( 'Widgets in this area will be shown on the right-hand side.' ),
'before_title' => '<h1>',
'after_title' => '</h1>'
));
In your theme template(s)
Add a call to dynamic_sidebar. This would probably be in sidebar.php
<div class="wms-column wms-column-nav">
<div class="wms-column-nav-body"><?php
dynamic_sidebar( 'right-sidebar' ); // your widgets will go here ?>
</div>
</div>
Notice that the parameter used in dynamic_sidebar matches the id used when registering the sidebar. That should be it. Of course, implementations can be more complicated-- including for example a hard-coded fallback sidebar or multiple sidebars-- but that is the basic started pack.