ACF InnerBlocks breaks css grid, How can we add classes to allowedblocks (Wordpress Gutenberg) - advanced-custom-fields

When I create an ACF Innerblock with allowedblocks, childs blocks are wrapped inside a wp-block div that breaks my grid system.
For example a simple grid system like that :
<div class="grid-wrapper innerblock">
<div class="grid-item allowedblock col3 "></div>
<div class="grid-item allowedblock col3 "></div>
<div class="grid-item allowedblock col3 "></div>
<div class="grid-item allowedblock col3 "></div>
</div>
Will output this breaking code in the admin :
<div class="grid-wrapper block-editor-block-list__layout" data-is-drop-zone="true">
<div class="wp-block"> <!-- no class "col3" !! -->
<div class="grid-item allowedblock col3 "></div>
</div>
<div class="wp-block"> <!-- no class "col3" !! -->
<div class="grid-item allowedblock col3 "></div>
</div>
<div class="wp-block"> <!-- no class "col3" !! -->
<div class="grid-item allowedblock col3 "></div>
</div>
<div class="wp-block"> <!-- no class "col3" !! -->
<div class="grid-item allowedblock col3 "></div>
</div>
</div>
What's the solution to pass the class "col3" to the dynamics wp-blocks ?
I tried this, but it didn't work...
<div class="block-wrapper">
<?php
$template = array(
array( "acf/card", array( "className" => "col1-6 col2-8 col3-4" ) )
);
?>
<InnerBlocks
class=" grid-wrapper"
allowedBlocks="<?php echo esc_attr( wp_json_encode( array( 'acf/card') ) ); ?> "
template="<?php echo esc_attr( wp_json_encode( $template ) ); ?>"
/>
</div>

In InnerBlocks, I suspect class=" grid-wrapper" is breaking the layout as "class" is a reserved word in JavaScript. Unfortunately, InnerBlocks doesn't support "className" by default; even if you added className="grid-wrapper it would not be appended to class of <div>...</div>. Although, there is another way to create the wrapper <div> with the correct class using hooks with InnerBlocks.
General InnerBlocks with className example:
JavaScript
const blockProps = useBlockProps({
className: "grid-wrapper"
});
const { children, ...innerBlocksProps } = useInnerBlocksProps(blockProps,
{
template: [['acf/card', {className: 'col1-6 col2-8 col3-4'}]]
allowedBlocks: ['acf/card']
});
// Outter div will have: class="grid-wrapper"
<div {...innerBlocksProps}>
{children} // Inner divs(blocks) will have: class="col1-6 col2-8 col3-4"
</div>

Related

Create a Bootstrap card layout to display blog posts on Wordpress

I have some HTML/CSS that I've previously used to display blog post intros on a static website. I'm now building a theme for Wordpress and I would like to use the same layout to display all of my posts within the theme. Based on this accepted answer I think the best option is to create a page template (option 2 from the top answer in the link). The static layout looks like this: Bootstrap layout.
The HTML from the above screenshot is (just the first row of cards):
<div class="row mb-2">
<div class="col-md-6">
<div class="card flex-md-row mb-4 shadow-sm h-md-250 card-left">
<div class="card-body d-flex flex-column align-items-start">
<strong class="d-inline-block mb-2 text-danger">Film</strong>
<h3 class="mb-0">
<a class="text-dark" href="#">The Last Jedi</a>
</h3>
<div class="mb-1 text-muted">Sep 19</div>
<p class="card-text mb-auto">Star Wars Episode VIII proved to be divisive within the fandom. How will it be remembered once the sequel trilogy has concluded?</p>
Continue reading
</div>
<img class="card-img-right flex-auto d-none d-lg-block" data-src="holder.js/200x250?theme=thumb" alt="The Last Jedi" style="width: 200px; height: 250px;" src="Images/Thumbnails/The-Last-Jedi-Thumbnail.jpg" data-holder-rendered="true">
</div>
</div>
<div class="col-md-6">
<div class="card flex-md-row mb-4 shadow-sm h-md-250 card-right">
<div class="card-body d-flex flex-column align-items-start">
<strong class="d-inline-block mb-2 text-danger">Film</strong>
<h3 class="mb-0">
<a class="text-dark" href="#">Episode IX</a>
</h3>
<div class="mb-1 text-muted">Aug 19</div>
<p class="card-text mb-auto">The final chapter of the Skywalker sage is key to the future of the franchise, away from the original protagonists.</p>
Continue reading
</div>
<img class="card-img-right flex-auto d-none d-lg-block" data-src="holder.js/200x250?theme=thumb" alt="The Rise of Skywalker" style="width: 200px; height: 250px;" src="Images/Thumbnails/The-Rise-of-Skywalker-Thumbnail.jpg" data-holder-rendered="true">
</div>
</div>
</div>
With a small amount of CSS:
.card-left {
margin-left: 15%;
margin-right: 2%;
margin-top: 1.5%;
margin-bottom: 1.5%;
}
.card-right {
margin-left: 2%;
margin-right: 15%;
margin-top: 1.5%;
margin-bottom: 1.5%;
}
The information on the cards will need to map to WP. So from the above screenshot the coloured category (e.g. film) would be the WP category, the title the post title, the date the post date, the description a character-capped excerpt and the continue reading a link to the full post. I'd like the image to be a cropped version of the post header image, but for now am happy to exclude this part for the sake of simplicity.
I have a very simple index.php from the Underscores starter theme that I'd like to use to create this blog template:
<?php
/**
* Template Name: Blog Card Layout
*
* The template file for displaying blog posts using a Bootstrap card layout.
*/
get_header();
?>
<main id="primary" class="site-main">
<?php
if ( have_posts() ) :
if ( is_home() && ! is_front_page() ) :
?>
<header>
<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
</header>
<?php
endif;
/* Start the Loop */
while ( have_posts() ) :
the_post();
/*
* Include the Post-Type-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Type name) and that will be used instead.
*/
get_template_part( 'template-parts/content', get_post_type() );
?>
<?php
endwhile;
the_posts_navigation();
else :
get_template_part( 'template-parts/content', 'none' );
endif;
?>
</main><!-- #main -->
<?php
get_sidebar();
get_footer();
For reference, the template-parts/content looks like this:
<?php
/**
* Template part for displaying posts
*
* #link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* #package Suscito
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php
if ( is_singular() ) :
the_title( '<h1 class="entry-title">', '</h1>' );
else :
the_title( '<h2 class="entry-title">', '</h2>' );
endif;
if ( 'post' === get_post_type() ) :
?>
<div class="entry-meta">
<?php
suscito_posted_on();
suscito_posted_by();
?>
</div><!-- .entry-meta -->
<?php endif; ?>
</header><!-- .entry-header -->
<?php suscito_post_thumbnail(); ?>
<div class="entry-content">
<?php
the_content(
sprintf(
wp_kses(
/* translators: %s: Name of current post. Only visible to screen readers */
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'suscito' ),
array(
'span' => array(
'class' => array(),
),
)
),
wp_kses_post( get_the_title() )
)
);
wp_link_pages(
array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'suscito' ),
'after' => '</div>',
)
);
?>
</div><!-- .entry-content -->
<footer class="entry-footer">
<?php suscito_entry_footer(); ?>
</footer><!-- .entry-footer -->
<hr>
</article><!-- #post-<?php the_ID(); ?> -->
So my question is two-fold:
Is it possible to re-create this layout, or something close to it?
If so, where in the new page template would the Bootstrap HTML code go and how would I amend it so that it gets the relevant information from Wordpress? I'm particularly interested in how I could control the post excerpt and 'continue reading' element.
Sorry for such a long post! I've been scratching my head over this one for a while. For reference my site is https://www.davidhazeel.com.

Mysql data not arranged in perfect row

Thanks for previous helps. Am here with another one.
Ok, so i am retrieving data from database.. its working fine, but where i have issues is that after the data spans the first row it doesn't start from the first column of the next row.. I don't know how to explain this better ... but I'I'll add the code and image here....
<div class="row">
<?php
$selectCat = "SELECT * FROM categories ORDER BY cat_id DESC";
$selectCatKwary = mysqli_query($link, $selectCat);
$catCount = mysqli_num_rows($selectCatKwary);
if ($catCount > 0) {
?>
<?php
while ( $catRow = mysqli_fetch_array($selectCatKwary)) { ?>
<a href="">
<div class="col-lg-3 col-sm-6">
<div class="card">
<div class="content">
<div class="row">
<div class="col-xs-5">
<div class="icon-big icon-warning text-center">
<i class="ti-user"></i>
</div>
</div>
<div class="col-xs-7">
<div class="numbers">
<p class="text-uppercase text-bold"><?php echo $catRow['catTitle']; ?></p>
105GB
</div>
</div>
</div>
</div>
</div>
</div>
</a>
<?php } } ?>
</div>
and here is the image
The first four data resolved well... the next one which MOBILE CARS did not start from the beginning column, and also affected others

Logo Image float on a Image Slider Wordpress Theme CSS

DISCLAIMER : I did not code the theme. This was made by another developer who left the project and I am making adjustments based on the new requirements. I don't have experience in Wordpress Theming but I can understand codes.
I am making a design in a website and I want to make my logo to be like floating above the Slider layer. I am working on a wordpress theme:
As you can see the Logo 'Red Dela Cruz' is on the top occupying a separate space or div. I want it inside the slider and floating on it like a layer, whenever the slide changes image, logo should still be there. Here is my code:
<div class="slider">
<img src="<?php echo $template_path; ?>images/redlogo_website.png" alt="" class="web-logo"/>
<div id="one-by-one-slider" class="one-by-one-slider">
<ul class="one-by-one-slider-large">
<?php
$args = array(
'post_type' => 'rdc_home',
);
query_posts( $args );
// The Loop
if ( have_posts() ) :
while (have_posts()) :
//the post for declaration
the_post();
?>
<li>
<img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'thumbnail') ); ?>" alt="<?php the_title(); ?>"/>
<div class="slider-content text-center">
<div class="slider-heading shp-12 slides" data-animation="bounceInDown" data-duration=4 data-delay=1>
<div class="container">
<div class="row">
<div class="col-md-12">
<h1><?php the_title(); ?></h1>
</div>
</div>
</div>
</div>
<div class="slider-heading shp-13 slides" data-animation="bounceInDown" data-duration=6 data-delay=2>
<div class=" container">
<div class="row">
<div class="col-md-12">
<h3><?php the_content(); ?></h3>
</div>
</div>
</div>
</div>
<!-- <div class="slider-heading shp-14 slides" data-animation="bounceInUp" data-duration=8 data-delay=4>
<div class=" container">
<div class="row">
<div class="col-md-12">
For Bookings
</div>
</div>
</div>
</div> -->
</div>
</li>
<?php
endwhile;
endif;
wp_reset_query();
?>
</ul>
<div class="one-by-one-slider-nav">
<ul class="one-by-one-slider-thumbs">
<li class="one-by-one-slider-element"></li>
<?php
$args = array(
'post_type' => 'rdc_home',
);
query_posts( $args );
// The Loop
if ( have_posts() ) :
while (have_posts()) :
//the post for declaration
the_post();
?>
<li></li>
<?php
endwhile;
endif;
wp_reset_query();
?>
</ul>
</div><!-- one-by-one-slider-nav -->
</div><!-- one-by-one-slider -->
</div><!-- slider -->
The logo is on the 2nd line and I haven't done any css on class
web-logo
This should work:
.web-logo {
position:absolute;
}
If the logo goes "behind" the slider, you should add a z-index, and make it higher, untill the image is showing:
.web-logo {
position:absolute;
z-index:2;
}
you can try this one:
.web-logo {
position: absolute;
right: 10px;
top: 10px;
z-index:2;
}

Bootstrap 2 - correct way to centre a div

I am using Bootstrap with the Yii framework - and am trying to centre my login box in the middle of the page, but not having any joy.
My code looks like as follows:
How should I amend this to have the div display bang on in the centre?
A jsfiddle -:
http://jsfiddle.net/7946rak9/1/
<div class="row">
<?php $form = $this->beginWidget('CActiveForm', array(
'id' => get_class($model),
'enableAjaxValidation' => true,
'clientOptions' => array(
'validateOnSubmit' => true,
'validateOnChange' => false,
),
'htmlOptions' => array('class'=>'form-vertical'),
'action' => array('/frontend/user/login')
)); ?>
<div class="span2">
<?php echo $form->labelEx($model,'username'); ?>
</div>
<div class="span10">
<?php echo $form->textField($model,'username', array('class' => '')); ?>
<?php echo $form->error($model, 'username', array('class'=>'errorMessage')); ?>
</div>
</div>
<div class="row">
<div class="span2">
<?php echo $form->labelEx($model,'password'); ?>
</div>
<div class="span10">
<?php echo $form->passwordField($model,'password', array('class' => '')); ?>
<?php echo $form->error($model, 'password', array('class'=>'errorMessage')); ?>
</div>
</div>
<div class="row">
<div class="offset2 span10">
<?php echo $form->checkBox($model,'rememberMe', array('class' => 'pull-left')); ?>
<?php echo $form->labelEx($model,'rememberMe', array('style' => 'padding-left: 20px;')); ?>
<?php echo $form->error($model, 'rememberMe', array('class'=>'errorMessage')); ?>
</div>
</div>
<div class="row">
<div class="offset2 span3">
<?php echo Html::submitButton('Login', array('class' => 'btn')); ?>
</div>
</div>
<?php $this->endWidget();?>
have you tried adding another class "text-center" to the row div?
EDITED:
If you want to use Bootstrap 2's included markup, use the following to offset your div to the middle of the row.
<div class="row-fluid">
<div class="span4">...</div>
<div class="span4 offset3">...</div>
</div>
http://getbootstrap.com/2.3.2/scaffolding.html#fluidGridSystem
Alternative
Or you could wrap all your divs with another div and then use the following markup.
<div class="wrapper">
....all you content divs here
</div>
.wrapper {
margin: 0 auto;
width: 50%;
}
http://jsfiddle.net/7946rak9/2/
Simply use:
margin: 0 auto;
On the div you would like to center
You can simply use text-align: center; on the div you want to centre
<div id="mydiv"></div>
#mydiv {
text-align: center;
}
Should do the trick. Simple Demo
Try defining classes span2 and span 10 with text-align: center; in your CSS if you're using a pre 2.3.0 version of Bootstrap - the .text-center method, suggested by #Wu4D wasn't added until v2.3.

Bootstrap row fluid spans jump a line

I'm running a query that outputs a span4 element in a row-fluid. I added code in my css to remove the margin-left on the third span4 in a row-fluid. This has also worked so far, but suddenly the one of the span4 jumps a line. Any suggestions why this suddenly stopped working?
You can see the page here:
http://dtm-auto.ch/home/
My css:
.row-fluid [class*="span"]:nth-child(3n+1) {
margin-left: 0!important;
}
My code:
<div id="content" class="clearfix row-fluid">
<div id="main" class="span12 clearfix" role="main">
<h2 class="text-left">Neue Fahrzeuge</h2>
<div class="clearfix row-fluid">
<?php
global $wp_query;
query_posts( array(
'post_type' => 'acme_product',
'posts_per_page' => 6
));
while ( $wp_query->have_posts() ) :
$wp_query->the_post();
?><?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );?>
<div id="front-new-video" class="span4">
<h3 id="car-title"><?php the_title(); ?></h3>
<div class="thumbnail wrapper">
<div class="ribbon-wrapper-green"><div class="ribbon-green">Neu</div></div>
<?php the_post_thumbnail('medium');?>
<p>Preis: <span style="color:#FEF158"><?php the_field('preis'); ?> CHF</span></p>
<p>Jahr: <span style="color:#FEF158"><?php the_field('jahr'); ?></span></p>
<p>Farbe: <span style="color:#FEF158"><?php the_field('farbe'); ?></span></p>
<p>KM: <span style="color:#FEF158"><?php the_field('km'); ?> KM</span></p>
<h4> <i class="icon-chevron-sign-right"></i> Zum Fahrzeug </h4>
</div>
</div>
<?php
endwhile;
?>
</div>
</div> <!-- end #main -->
</div> <!-- end #content -->
It's because you're using height: 100% on #front-new-video which doesn't really do anything because the parents height(row-fluid) needs to be defiend for height: 100% to work.
Use a fixed height or min-height instead and your problem will be solved. e.g height: 419px;