I have a customer's list where is possible to tag each one like "Emprendedor", "Creativo" and/or "Detallista". I want to insert the following icon for no-taged customers:
http://imagizer.imageshack.us/v2/800x600q90/824/6h1d.png
The problem is the icon's position. I want it next to label. The code is:
<?php
foreach($customers as $customerKey => $customer){ ?>
<? $selectedCount = "0"; ?>
<div class="row customer customer-<?=$customer?>">
<div class="col-xs-6 col-md-4 customer-name customer-<?=$customer?>"><?=utf8_encode($customerNames[$customer])?></div>
<div class="col-xs-6 col-md-4"><?
foreach($tags as $tagKey => $tag){
$selected=false;
foreach($customerTags as $customerTagKey => $cTags)
if($customerTagKey == $customer)
foreach($cTags as $cKey => $cTag)
if($cTag == $tag){
$selected=true;
$selectedCount = $selectedCount + 1;
}
?><span class="label label-<?=$tag?><?=$selected?" selected":" hidden-print"?> customer-<?=$customer?>" onclick="connect('customer-<?=$customer?>', '<?=$customer?>', '<?=$tag?>');"><?=$tag?></span> <?
}?></div>
</div> <!-- customer-<?=$customer?> row -->
<?
echo "<div class=\"";
if($selectedCount == 0){
echo "glyphicon glyphicon-exclamation-sign glyphicon-red";
}
if($selectedCount > 1){
echo "glyphicon glyphicon-retweet glyphicon-blue";
}
echo " \"></div>";
}
?>
Related
With php print_r I got final result as :
Array ( [0] => 31 [1] => 21 ) Array ( [0] => 33 [1] => 27 )
And I want result to be like 31,21,33,27.
I am stuck up. Please guide me through.
Thanks,
Vikram
**Please bare with lengthy stuff. **
I have 2 main categories and need to display 3 fourth level children on home page. Categories are like :
Category > Clothing.
Category > Clothing > Mens.
Category >> Clothing > Mens > Top.
Category > Clothing > Mens > Top > Jeans.
CODES
<div class="container products" data-aos="fade-down">
<div class="page-titles" data-aos="fade-up">
Products
<hr />
</div>
<!--page-titles-->
<?php
$homepage_products=get_post_meta($post->ID, 'homepage_products', TRUE);
$homepage_parent=explode(',', $homepage_products);
global $parent_one;
global $x;
$x=1;
foreach($homepage_parent as $parent_one)
{
$parent_one_title = get_the_title( $parent_one );
$content_post = get_post($parent_one);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
?>
<div class="row clothing">
<div id="<?php echo $x++; ?>" class="col-xs-12 col-sm-12 col-md-4 col-lg-4
<?php if($x % 2)
{
echo 'col-md-push-8 col-lg-push-8';
}
?>
">
<?php echo get_the_post_thumbnail($parent_one, 'medium_large', array('class' => 'img-'.$x)); ?>
</div>
<!--col-4 img-->
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8
<?php if($x % 2)
{
echo 'col-md-pull-4 col-lg-pull-4';
}
?>
">
<h2><?php echo $parent_one_title; ?></h2>
<?php echo $content; ?>
<!-- child pages of <?php echo strtolower($parent_title); ?> starts-->
<div class="row">
<?php
$parent_two=get_pages( array('parent'=>$parent_one,'child_of'=>$parent_one) );
foreach($parent_two as $parent_two_ids)
{
$parent_two_id=$parent_two_ids->ID;
$parent_two_id.=",";
$parent_three=get_pages( array('parent'=>$parent_two_id) );
$str_id = array();
foreach($parent_three as $parent_three_ids)
{
$parent_three_id=$parent_three_ids->ID;
$parent_three_id.=',';
$parent_four=get_pages( array('parent'=>$parent_three_id) );
$four_ids=array();
foreach($parent_four as $parent_four_ids)
{
$four_id=$parent_four_ids->ID;
$four_ids[]=$four_id;
}//parent_four_ids
// HERE IS MY ISSUE //
echo implode(',', array_merge($four_ids) );
// HERE IS MY ISSUE //
//$ids=implode(',',$four_ids);
//$idx=$ids;
//$idv=preg_replace('#\s+#',',',trim($idx));
//echo $idv;
//$str_id[]=$idx;
//$str_idx=implode(',',$str_id);
//echo $str_idx;
$content=apply_filters('the_content', $parent_four_ids->post_content);
$c_length = 80;
if (strlen($content) > $c_length)
{
$content = wordwrap($content, 80);
$i = strpos($content, "\n");
if ($i) {
$content = substr($content, 0, $i);
}
}
?>
<!-- <div class="col-xs-12 col-sm-12 col-md-3 col-lg-3 product">
< ?php echo get_the_post_thumbnail($parent_four_ids, 'medium_large'); ?>
<a href="< ?php echo get_permalink($parent_four_ids);?>">
<h4>< ?php echo $parent_four_ids->post_title; ?></h4>
</a>
< ?php echo $content; ?>
</div><!--col 3 #< ?php echo $parent_four_ids->ID; ?>-->
<?php
}//parent_three_ids
} // parent_two_ids
?>
</div>
<!-- row category - slider- child pages of <?php echo strtolower($parent_one_title); ?> ends-->
</div>
<!-- col-6 content - child pages-->
</div>
<!--row <?php echo strtolower($parent_title); ?>-->
<? } //home_parent ?>
</div>
<!--container products-->
Just as iainn said above:
php > echo implode(',', array_merge([31, 21], [33, 27]));
31,21,33,27
If you wanted a single array and not a string, remove the implode() call.
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="row text-center">
<?php
if($_GET[id] == 0)
{
$querysb = mysql_query("SELECT * FROM services WHERE parentid !=0 order by parentid, cid ");
}
else
{
$querysb = mysql_query("SELECT * FROM services WHERE parentid='".$_GET[id]."'");
}
while($rowsb = mysql_fetch_assoc($querysb))
{
if($val == '6' || $val =='10'){
$classname = 'whitebg';
} else {
$classname = 'bg-blue co-white';
}
?>
<div class="col-md-4 mrgnBtm15">
<div class="<?php echo $classname;?> padding30" style="min-height: 250px">
<h3 class="service-heading">
<?php echo $rowsb['cname'];?>
</h3>
<h4>
RS <?php echo $rowsb['price'];?><br>
</h4>
<div class="mrgnTop15 clearfix"></div>
<a class="btn bg-orange co-white" href="<?php echo MYWEBSITE;?>servicedetail/<?php echo to_prety_url($rowsb['cname']).'-'.$rowsb['cid'];?>.html">
<font style="size:14px; color:#000; font-weight:bolder;font-family: "Open Sans";">Register</font></a>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
I am working on a dynamic website. here is the code of a particular page. In this page there is a div section with class="col md-4". If the number of content panel in that division appears to 5 or 7 in that case I want only the last panel (i.e 5th and 7th) to be in full column (col-12). What should I do?
Since you are using col-md-4, 3 divs will be shown each row. So I think what you are looking for is a way to make the last div full width if its going to be alone in its row. In that case, you will need to make it col-md-12 on 4th (not 5th) and 7th and 10th records and so on. This is exactly what the following code does,
I think what you want to do is show the
<?php
if($_GET[id] == 0)
{
$querysb=mysql_query("SELECT * FROM services WHERE parentid !=0 order by parentid, cid ");
}
else
{
$querysb=mysql_query("SELECT * FROM services WHERE parentid='".$_GET[id]."'");
}
$number_of_records = mysql_num_rows($querysb);
$counter = 1;
while($rowsb=mysql_fetch_assoc($querysb))
{
if($val == '6' || $val =='10'){
$classname= 'whitebg';
}else{
$classname= 'bg-blue co-white';
}
//if($number_of_records %3 ==1 && $counter == $number_of_records)
if(($number_of_records == 5 || $number_of_records == 7) && $counter == $number_of_records)
$col_class = "col-md-12";
else
$col_class = "col-md-4";
?>
<div class="<?php echo $col_class;?> mrgnBtm15">
<div class="<?php echo $classname;?> padding30" style="min-height: 250px">
<h3 class="service-heading">
<?php echo $rowsb['cname'];?>
</h3>
<h4>
RS <?php echo $rowsb['price'];?><br>
</h4>
<div class="mrgnTop15 clearfix"></div>
<a class="btn bg-orange co-white" href="<?php echo MYWEBSITE;?>servicedetail/<?php echo to_prety_url($rowsb['cname']).'-'.$rowsb['cid'];?>.html">
<font style="size:14px; color:#000; font-weight:bolder;font-family: "Open Sans";">Register</font></a>
</div>
</div>
<?php
$counter++;
} ?>
</div>
</div>
</div>
I am trying to create a new row or breaking my row of results to drop down to a new row in my results set because at the moment they just go on and on and break out of the container and do not create a new row as it hits the end of the container.
My code is fairly simple - I am using the bulma css framework and specifically the is-3 class to display each result so its gives me 4 columns in the container. So after every four a new row should be created.
My code is is fairly simple:
<div class="container">
<div class="columns projectList">
<?php while($stmt->fetch()) { ?>
<div class="column is-3">
<div class="card">
<div class="card-content">
<div class="content">
<p class="projectStatus">
<?php
if($phase == 0){
echo 'Phase: Pending';
}
elseif($phase == 1){
echo 'Phase: Planning';
}
elseif($phase == 2){
echo 'Phase: Design';
}
elseif($phase == 4){
echo 'Phase: Development';
}
else{
echo 'No Phase Added';
}
?>
</p>
<p class="projectTitle"><span>!</span><?php echo $projectName; ?></p>
<div class="projectTimes">
<div class="inner">
<span class="days">12</span>
<span class="for">Days Left In Design</span>
</div>
<div class="inner">
<span class="days">42</span>
<span class="for">Days to finish</span>
</div>
</div>
</div>
</div>
<footer class="card-footer">
<a class="card-footer-item"><i class="material-icons"></i>32</a>
<a class="card-footer-item"><i class="material-icons"></i>10</a>
</footer>
</div>
</div>
<!-- END ROW HERE AND CREATE NEW ONE -->
<?php } $stmt->close(); } ?>
</div>
</div>
My question: How do I line break after every fourth result?
<div class="container">
<?php
$i = 0;
while($stmt->fetch()) {
if($i%4==0){
echo '<div class="columns projectList">';
}
$i++;
?>
<div class="column is-3">
<div class="card">
<div class="card-content">
<div class="content">
<p class="projectStatus">
<?php
if($phase == 0){
echo 'Phase: Pending';
}
elseif($phase == 1){
echo 'Phase: Planning';
}
elseif($phase == 2){
echo 'Phase: Design';
}
elseif($phase == 4){
echo 'Phase: Development';
}
else{
echo 'No Phase Added';
}
?>
</p>
<p class="projectTitle"><span>!</span><?php echo $projectName; ?></p>
<div class="projectTimes">
<div class="inner">
<span class="days">12</span>
<span class="for">Days Left In Design</span>
</div>
<div class="inner">
<span class="days">42</span>
<span class="for">Days to finish</span>
</div>
</div>
</div>
</div>
<footer class="card-footer">
<a class="card-footer-item"><i class="material-icons"></i>32</a>
<a class="card-footer-item"><i class="material-icons"></i>10</a>
</footer>
</div>
</div>
<?php
if($i%4==0){
echo '</div>'
$i = 0;
}
?>
<!-- END ROW HERE AND CREATE NEW ONE -->
<?php } $stmt->close(); } ?>
</div>
</div>
There is something called the modulus.
for ($c = 1; $c < count($results); $c++) {
if ($c % 4 == 0) {
// This is the fourth iteration
}
}
is this what you are looking for ?
<div class="container">
<?php
$x = 1;
while($stmt->fetch()) {
?>
<?php if($x == 1) { ?> <div class="columns projectList"> <?php }
$x++;
?>
<div class="column is-3">
<div class="card">
<div class="card-content">
<div class="content">
<p class="projectStatus">
<?php
if($phase == 0){
echo 'Phase: Pending';
}
elseif($phase == 1){
echo 'Phase: Planning';
}
elseif($phase == 2){
echo 'Phase: Design';
}
elseif($phase == 4){
echo 'Phase: Development';
}
else{
echo 'No Phase Added';
}
?>
</p>
<p class="projectTitle"><span>!</span><?php echo $projectName; ?></p>
<div class="projectTimes">
<div class="inner">
<span class="days">12</span>
<span class="for">Days Left In Design</span>
</div>
<div class="inner">
<span class="days">42</span>
<span class="for">Days to finish</span>
</div>
</div>
</div>
</div>
<footer class="card-footer">
<a class="card-footer-item"><i class="material-icons"></i>32</a>
<a class="card-footer-item"><i class="material-icons"></i>10</a>
</footer>
</div>
</div>
<!-- END ROW HERE AND CREATE NEW ONE -->
<?php
if($x % 4 == 0)
{
echo '<div/>';
$x = 1;
}
} $stmt->close(); } ?>
</div>
Using this logic you can break your ROW at fourth iteration
$i = 0;
while(while($stmt->fetch())){
if($i%4==0){
//div to create new ROW
}
<div class="column is-3">
//all your logic go here
</div>
if($i%4==0){
// close the div for create new ROW
}
$i++;
}
This is a fairly simple one. I take from your question that you essentially want to split your results from the query into groups of 3? With each group being displayed as a row?
What i would recommened is fetching all of your results at once and storing as a variable. Assuming this variable is an array you can use array_chunk() to split the array of rows into the cunks you need. This will result in an array of arrays with each of the inner arrays containing the specified number of items. See: http://php.net/manual/en/function.array-chunk.php
Ive mocked up a quick example for you here:
<?php
//Fetch all data, this will become the $items array
$items = array(
'item 1',
'item 2',
'item 3',
'item 4',
'item 5',
'item 6',
'item 7',
'item 8',
'item 9',
'item 10',
'item 11',
'item 12',
'item 13',
'item 14',
);
//Split the items into 'rows' (chunks)
//The second parameter here basically indiciates how many items you want in each row
$rows = array_chunk($items, 3);
//Loop over each row group, remembering each row is an array of items (columns)
//Do your row building HTML within this foreach loop
//Do your columnd building HTML within the inner foreach loop
foreach($rows as $columns){
echo "---------------<br />";
//Build column html for each item within the row
foreach($columns as $column){
echo $column.' | ';
}
echo "<br />";
echo "---------------";
echo "<br /><br />";
}
?>
Run the abover here: http://phpfiddle.org/
You can see how it splits up the rows etc.
Hope this helps!
I need to wrap every 2 divs with another div for a project (a row) so it will look like:
<div class="row">
<div> Item </div>
<div> Item </div>
</div>
<div class="row">
<div> Item </div>
<div> Item </div>
</div>
I have tried a few solutions but they dont work since the items coming in are odd (9 items). Here is what I had:
<?php
$count = 0;
foreach ($contents as $content)
{
//var_dump($content);
$books = $content["tags"];
$book_image = $content['content_image'];
$book_desc = $content['content_social_description'];
++$count;
if($count == 1)
{
echo "<div class='et_pb_row'>";
}
foreach ($books as $book)
{
$book_name = $book['tag_name'];
$book_name_trim = str_replace(' ', '-', $book_name);
?>
<!-- Inside the Book Loop -->
<div class='et_pb_column et_pb_column_1_2 books' style="background: url('https://s3-us-west-2.amazonaws.com/crowdhubproverbs31/<?php echo $book_image ;?>');">
<h2><?php echo $book_name; ?></h2>
<p><?php echo $book_desc; ?></p>
<?php echo $count; ?>
</div>
<?php
}
if ($count == 2)
{
echo "</div>";
$count = 0;
}
}
?>
This works except the second to last row has 3 items even though it dispays the "count" as 2 when I echo it out so it should reset but doesnt. So its:
<div class="row">
<div> Item </div> "Count 1"
<div> Item </div> "Count 2"
</div>
<div class="row">
<div> Item </div> "Count 1"
<div> Item </div> "Count 2"
</div>
<div class="row">
<div> Item </div> "Count 1"
<div> Item </div> "Count 2"
<div> Item </div> "Count 2"
</div>
<div class="row">
<div> Item </div> "Count 1"
<div> Item </div> "Count 2"
</div>
You should open and close your <rows/> in the books loop, and add a late check for odd books:
<?php
$count = 0;
foreach ($contents as $content)
{
//var_dump($content);
$books = $content["tags"];
$book_image = $content['content_image'];
$book_desc = $content['content_social_description'];
foreach ($books as $book)
{
++$count;
if($count == 1)
{
echo "<div class='et_pb_row'>";
}
$book_name = $book['tag_name'];
$book_name_trim = str_replace(' ', '-', $book_name);
?>
<!-- Inside the Book Loop -->
<div class='et_pb_column et_pb_column_1_2 books' style="background: url('https://s3-us-west-2.amazonaws.com/crowdhubproverbs31/<?php echo $book_image ;?>');">
<h2><?php echo $book_name; ?></h2>
<p><?php echo $book_desc; ?></p>
<?php echo $count; ?>
</div>
<?php
if ($count == 2)
{
echo "</div>";
$count = 0;
}
}
}
if ($count > 0)
{
echo "</div>";
}
?>
Doing so, your $count variable will be incremented only when foreach($books AS $book) loop is run (thus you have at least one book to print)
You can take advantage of array_chunk :
//First make a generator to get all books
function allBooks($contents) {
foreach($contents as $content) {
foreach($content['tags'] as $book) {
yield $book; //Here you can yield whatever you want !
}
}
}
//Then create rows
$itemPerRow = 2;
$rows = array_chunk(iterator_to_array(allBooks($contents)), $itemPerRow, true);
//Display all
foreach($rows as $row) {
echo '<row>';
foreach($row as $book) {
//Display the book !
}
echo '</row>';
}
<div class="puffar">
<?php
//Set up the objects needed
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));
//Get children
$children = ($post->post_parent) ? get_page_children($post->post_parent, $all_wp_pages) : get_page_children($post->ID, $all_wp_pages);
$i = 0;
//Build custom items
echo "<div class='row'>";
foreach ($children as $child) {
?>
<div class="col-sm-6">
<div class="puff">
<div class="puff-image-holder">
<?php echo get_the_post_thumbnail($child->ID, 'full'); ?>
</div>
<fieldset class="linedHeadline hlmedium">
<legend><?php echo get_the_title($child->ID); ?></legend>
</fieldset>
<?php echo get_field("puff_introtext", $child->ID); ?>
<?php
$values = get_field('puff_lanktext', $child->ID);
if (get_field("popup_eller_lank", $child->ID) == "popup") {
?>
<fieldset class="linedHeadline hlmedium">
<legend><a class="linktopage open-popup"
href="<?php echo get_page_link($child->ID); ?>"><?php echo get_field("puff_lanktext", $child->ID); ?> </a>
</legend>
</fieldset>
<?php
} elseif (get_field("popup_eller_lank", $child->ID) == "extern") {
?>
<fieldset class="linedHeadline hlmedium">
<legend><a class="linktopage"
href="<?php echo get_field("puff_lank", $child->ID); ?>"><?php echo get_field("puff_lanktext", $child->ID); ?> </a>
</legend>
<?php
$i++;
if ($i % 2 == 0) {
echo "</div><div class='row'>";
}
} else {
}
?>
</div>
</div>
<?php } ?>
</div>
</div>
I want every 2 items that's rendered out to be wrapped in a <div class="row">, however I can't figure it out. Can anyone help me?
So basically the row should wrap every 2 elements that is getting looped. I have been stuck on this forever... Hopefully anyone got better expertise than me hehe.
The div="row" should wrap the col-sm-6 and class="puff".
$i = 0;
foreach ($children as $child) {
$i++;
// your code goes here
if($i % 2 == 0) {
echo "</div><div class='row'>";
// reset the counter to 0
$i = 0 ;
}
}
use proper logic
if ($i % 2 == 0) {
echo "</div><div class='row'>";
}
$i++;
First check if its mod by 2 or not (Gives 0 value after MOD), then close div , open new.
Now increase counter . Because for the first time , i will be 0 , then you increment it and then you use logic. So in short counter shoul be incremented at the end only not in between before you do any operation/logic.
Updated
Use code as it is **: issue was you have i++ and your condition in 3rd else if which never executed. So took it outside All and just before foreach.
<div class="puffar">
<?php
//Set up the objects needed
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));
//Get children
$children = ($post->post_parent) ? get_page_children($post->post_parent, $all_wp_pages) : get_page_children($post->ID, $all_wp_pages);
$i = 0;
//Build custom items
echo "<div class='row'>";
foreach ($children as $child) {
?>
<div class="col-sm-6">
<div class="puff">
<div class="puff-image-holder">
<?php echo get_the_post_thumbnail($child->ID, 'full'); ?>
</div>
<fieldset class="linedHeadline hlmedium">
<legend><?php echo get_the_title($child->ID); ?></legend>
</fieldset>
<?php echo get_field("puff_introtext", $child->ID); ?>
<?php
$values = get_field('puff_lanktext', $child->ID);
if (get_field("popup_eller_lank", $child->ID) == "popup") {
?>
<fieldset class="linedHeadline hlmedium">
<legend><a class="linktopage open-popup"
href="<?php echo get_page_link($child->ID); ?>"><?php echo get_field("puff_lanktext", $child->ID); ?> </a>
</legend>
</fieldset>
<?php
} elseif (get_field("popup_eller_lank", $child->ID) == "extern") {
?>
<fieldset class="linedHeadline hlmedium">
<legend><a class="linktopage"
href="<?php echo get_field("puff_lank", $child->ID); ?>"><?php echo get_field("puff_lanktext", $child->ID); ?> </a>
</legend>
<?php
} else {
}
?>
</div>
</div>
<?php
if ($i % 2 == 0) {
echo "</div><div class='row'>";
}
$i++;
} ?>
</div>
</div>
First set $i=0;
if ($i % 2 == 0) {
echo "</div><div class='row'>";
}
$i++;