I got an article that is read from the database. Which is in a wrapper, I needed an image to be full width (so even wider than the wrapper) while still being in the article. So I split it on the image tag like the code below.
However this prevents a user from adding multiple images. When I add another image tag it doesn't show the image.
How can I split the article not just on one image but every image?
All data (text, img tags) is in 'introtext'.
For example:
<p>Part one of the article</p>
//Here the article is split on all img tags that are there.
<img src="#">
<img src="#">
<img src="#">
<img src="#">
<p>Part two of the article</p>
The below code only works when I add one image tag.
<div class="container relative" style="padding: 0px;">
<div class="row">
<div class="col-sm-12">
<div class="blog-item mb-20 mb-xs-40">
<!-- Text -->
<div class="blog-item-body">
<?
$introtext = $contenti[0]['introtext'];
$splitartikel = preg_split('/(<img[^>]+\>)/i', $introtext, -1, PREG_SPLIT_DELIM_CAPTURE);
echo $splitartikel[0];
?>
</div>
</div>
</div>
</div>
</div>
<div class="container-fluid relative" style="padding: 0px;">
<div class="row">
<div class="col-sm-12">
<div class="middleimage">
<?
echo $splitartikel[1];
?>
</div>
</div>
</div>
</div>
<div class="container relative" style="padding: 0px;">
<div class="row">
<div class="col-sm-12">
<div class="blog-item mb-20 mb-xs-40">
<!-- Text -->
<div class="blog-item-body">
<?
echo $splitartikel[2];
?>
</div>
</div>
</div>
</div>
</div>
The query:
// Articles
$content = "SELECT * FROM `lb_content` WHERE alias = '".$conn->real_escape_string($_GET['alias'])."' ";
$contentcon = $conn->query($content);
$contenti = array();
while ($contenti[] = $contentcon->fetch_array());
I also tried looping the middle part, but this also loops the text before and after the image, while I only want to have the option to have multiple images.
Like this:
<?php foreach($splitartikel as $part) : ?>
<div class="container-fluid relative" style="padding: 0px;">
<div class="row">
<div class="col-sm-12">
<div class="middleimage">
<?php echo $part; ?>
</div>
</div>
</div>
</div>
<?php endforeach ?>
Maybe I need to do some sort of foreach loop for every image tag?
Related
It's my first time working with wordpress, ACF and PHP, and well, I've
been in this trouble for days, does anyone know what's going wrong for
the Loop not working?
<div class="swiper">
<div class="swiper-wrapper">
<?php
foreach (get_field('fleet_slides') as $fleet_slide) {
$image = $fleet_slide['image_slide']['url'];
?>
<div class="img-wrapper">
<!-- Slides -->
<div class="swiper-slide">
<img src="<?php echo $image?>" />
</div>
</div>
<?php
}
?>
</div>
<!-- Additional required wrapper -->
<div class="swiper-controls">
<!-- If we need navigation buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<!-- If we need pagination -->
<div class="swiper-pagination"></div>
</div>
</div>
I never liked this syntax:
while( have_rows('fleet_slides', 'option') ) : the_row();
I just treat them as arrays. (I have a repeater called slides with sub fields: image, html). This code works for me.
foreach (get_field('slides') as $slide) {
$image = $slide['image']['url'];
$html = $slide['html'];
?>
<div class="banner-carousel-item" style="position:relative; background-image:url(<?php echo $image; ?>)">
<div style="background:rgba(0,0,0,0.25); position: absolute; top: 0; bottom: 0; left:0; right: 0; ">
</div>
<div class="slider-content">
<div class="container h-100">
<div class="row align-items-center h-100">
<?php echo $html ?>
</div>
</div>
</div>
</div>
<?php
}
?>
I have panel where I'm displaying some basic informations about user. I want to display graph in the center of this panel.
I have problems with one unwanted space which I want to remove but I don't know how to do it.
Please look at image:
Code for this panel:
<div class="row">
<div class="panel panel-default">
<div class="panel-heading">Detail zákazníka </div>
<div class="panel-body">
<div class="form-group">
<label>ID zákazníka:</label>
<p><?php echo !empty($zakaznici['ID_zakaznici'])?$zakaznici['ID_zakaznici']:''; ?></p>
</div>
<div class="form-group">
<label>Meno:</label>
<p><?php echo !empty($zakaznici['meno'])?$zakaznici['meno']:''; ?></p>
</div>
<div class="panel-body" align="center">Graph will be displayed here</div>
<div class="form-group">
<label>Priezvisko:</label>
<p><?php echo !empty($zakaznici['priezvisko'])?$zakaznici['priezvisko']:''; ?></p>
</div>
<div class="form-group">
<label>Email:</label>
<p><?php echo !empty($zakaznici['email'])?$zakaznici['email']:''; ?></p>
</div>
<div class="form-group">
<label>Adresa:</label>
<p><?php echo !empty($zakaznici['adresa'])?$zakaznici['adresa']:''; ?></p>
</div>
<a class="btn btn-primary" href="<?php echo site_url('Zakaznici/viewusersvypozicky/'.$zakaznici['ID_zakaznici']); ?>" role="button">Zobraziť prenájmy</a>
</div>
</div>
</div>
p tags create line breaks. You could replace the p tag with a span tag to remove the unwanted break.
Your div with the class name 'panel-body' is also occupying space. You could add position: absolute; to its defined styles and it would not create that break.
<div class="row">
<div class="panel panel-default">
<div class="panel-heading">Detail zákazníka </div>
<div class="panel-body">
<div class="form-group">
<label>ID zákazníka:</label>
<p><?php echo !empty($zakaznici['ID_zakaznici'])?$zakaznici['ID_zakaznici']:''; ?></p>
</div>
<div class="form-group">
<label>Meno:</label>
<span><?php echo !empty($zakaznici['meno'])?$zakaznici['meno']:''; ?></span>
</div>
<div class="panel-body" align="center">Graph will be displayed here</div>
<div class="form-group">
<label>Priezvisko:</label>
<p><?php echo !empty($zakaznici['priezvisko'])?$zakaznici['priezvisko']:''; ?></p>
</div>
<div class="form-group">
<label>Email:</label>
<p><?php echo !empty($zakaznici['email'])?$zakaznici['email']:''; ?></p>
</div>
<div class="form-group">
<label>Adresa:</label>
<p><?php echo !empty($zakaznici['adresa'])?$zakaznici['adresa']:''; ?></p>
</div>
<a class="btn btn-primary" href="<?php echo site_url('Zakaznici/viewusersvypozicky/'.$zakaznici['ID_zakaznici']); ?>" role="button">Zobraziť prenájmy</a>
</div>
</div>
</div>
Try this
<div class = "row">
<div class = "panel panel-default col-4">
<div class = "panel-body">
//your matter
</div>
</div>
<div class = "panel panel-default col-4">
<div class = "panel-body">
//your graph
</div>
</div>
</div>
As discussed the p's are block level elements and create linebreaks - but Bootstrap also stlyes them with a 10px margin bottom so you may want to overwrite that with
p { margin-bottom: 0;}
I do not recommend this - the ideaa of the margin bottom is to separate text elements.
What will be causing your space issue where you have indicated is that you are using a div with a .panel body class within the panel body.
<div class="panel-body" align="center">Graph will be displayed here</div>
Bootstrap styles the panel body with 15px padding - so either
a) replace that class with a different class (this is what I would do - it makes no sense to have a .panel-body -within a .panel-body)
b) remove the padding from the nested panel body
.panel-body > .panel-body { padding: 0}
But as I said - a panel body within another one is semantically wrong.
I am generating html code using php. I have some information stored in an array called $persons and I'm trying to generate a bootstrap card for each $person:
<div class="container">
<div class="row">
<?php foreach ($persons as $person): ?>
<div class="card col-md-3 m-1">
<img class="card-img-top" src="<?=person['img_src']?>" alt="<?=$person['name']?>">
<div class="card-block">
<h4 class="card-title"><?=$person['name']?></h4>
<p class="card-text"><?=$person['info']?></p>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
Everything works fine when I remove m-1 class, but as soon as I add m-1 class, margin causes the last div to go to next line. I think lack of space causes this problem. How can I fix this problem? How to have margin between divs without the last div going to the next line?
You should have a separate div for the card since it's display:flex. Also, just use my-1 for margin-top and margin-bottom so that x-axis space is not effected...
<div class="container">
<div class="row">
<?php foreach ($persons as $person): ?>
<div class="col-md-3 my-1">
<div class="card">
<img class="card-img-top" src="<?=person['img_src']?>" alt="<?=$person['name']?>">
<div class="card-block">
<h4 class="card-title"><?=$person['name']?></h4>
<p class="card-text"><?=$person['info']?></p>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
https://www.codeply.com/go/78AmkbWrLi
The easiest solution would be to just put another div inside the col, which applies the margin:
<div class="container">
<div class="row">
<?php foreach ($persons as $person): ?>
<div class="card col-md-3">
<div class="m-1"> <!-- NEW -->
<img class="card-img-top" src="<?=person['img_src']?>" alt="<?=$person['name']?>">
<div class="card-block">
<h4 class="card-title"><?=$person['name']?></h4>
<p class="card-text"><?=$person['info']?></p>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
Or if you don't want to add another div, just add the m-1 class to the card-block.
<html>
<div class="product-tile ">
<div class="product-image">
<img src="1.jpg">
<img src="2.jpg">
</div>
<div class="brand">
<a href="example1.html" class="brand-link">
Example1
</a>
</div>
<div class="product-name">
Craquelé-Effect Leather Square-Toe Mules
</div>
</div>
<div class="product-tile ">
<div class="product-image">
<img src="11.jpg">
<img src="12.jpg">
</div>
<div class="brand">
<a href="example2.html" class="brand-link">
Example2
</a>
</div>
<div class="product-name">
Craquelé-Effect
</div>
</div>
</html>
My content is like this in HTML and want to copy it on my website.
My code is like how to get the title, images, brand and there price. I've used file_get_html in it but I'm getting issue in fetching the datalike brand and price.
require('simple_html_dom.php');
$html = file_get_html('new_arrival.html');
//$product = [];
foreach ($html->find('div.wrap-desc') as $pro) {
$proDetails = $pro->find('div.brand');
}
If you are using jQuery you can get the contents of a DOM element using .html():
$('html').html()
Alternatively in vanillaJS:
let x = document.getElementByTagName('html')
console.log(x.innerHTML)
https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML
OK, this is a bit complicated so Ill try my best to explain it:
I have a while loop which has a next link, before I just had it in standard html, so it was farely simple, on click of the class 'arrow' it would just to the next section e.g:
$i = 0;
while ( have_rows('sections') ) : the_row();
$sectionName = $i++;
?>
<section id="<?php echo $sectionName; ?>" class="full-bg-image" style="background-image: url('<?php the_sub_field('section_image'); ?>')">
<div class="image divider" id="partnersImg" style="background-image: url('<?php the_sub_field('section_image'); ?>')">
<div class="wrapper">
<div class="overlay" style="color: <?php the_field('section_text_colour','options'); ?>">
<?php the_sub_field('divider_text'); ?>
</div>
</div>
</div>
<div class="sectionContent">
<div class="wrapper">
<div class="centerContent">
<div class="contentWrapper">
<div class="text animation-element" data-sr="enter center wait 0.5s, no reset" style="background-color: <?php the_field('text_block_bg_colour','options'); ?>; color: <?php the_field('text_block_text_colour','options'); ?>">
<?php the_sub_field('section_text'); ?>
<div class="arrowContainer"></div>
</div>
<div class="clr"></div>
</div>
</div>
</div>
</div>
</section>
<?php endwhile;
The sectionName variable is set for each item name that is added in the wordpress admin however the issue comes when my above code shows and the anchor is linking too itself and not the next section, I would like to know how to link it to the next section and if its the last section then to have a anchor which links to the first.
<section id="0">
<div class="arrowContainer"></div>
</section>
<section id="1">
<div class="arrowContainer"></div>
</section>
<section id="2">
<div class="arrowContainer"></div>
</section>
<section id="3">
<div class="arrowContainer"></div>
</section>
In this case I am using Advanced Custom Fields repeater and not posts.