Show images with php and bootstrap carousel - php

I need to create an list of images with twitter bootstrap so I write:
<?php osc_run_hook('item_detail', osc_item() ) ; ?>
<?php if( osc_images_enabled_at_items() && (osc_count_item_resources() > 0) ) { ?>
<div class="row hidden-xs" id="mediaCarouselThumbs" style="padding: 15px;">
<?php $itemCount = osc_count_item_resources(); ?>
<?php for($i = 0; $i < $itemCount; $i++) { ?>
<div class="pull-left" style="width: 11.11%;">
</div><?php } ?>
<!---->
</div>
<?php } ?>
All is fine but echo osc_resource_url(); dont give me the right url and dont change it in the loop, also with $i is everything fine and work well... So after raun this code I get:
<div class="row hidden-xs" id="mediaCarouselThumbs" style="padding: 15px;">
<div class="pull-left" style="width: 11.11%;">
</div> <div class="pull-left" style="width: 11.11%;">
</div> <div class="pull-left" style="width: 11.11%;">
</div> <!---->
</div>
What I need to do to change image URL on every loop. Thanks and sorry for my english.

The value returned by osc_resource_url() (in your current code) is "static" and is not affected by the current loop. This is the reason why all images are the same. One solution is to pass an argument to this function.
Because I have no idea what is the main job that this function do (are there any arguments that can be passed, what value will be returned, etc.), I'll suggest simple solution using array for images and urls:
<?php
$itemCount = osc_count_item_resources();
$images = array(
array('url' => '#', 'image' => 'http://dive.agroagro.com/0.jpg'),
array('url' => '#', 'image' => 'http://dive.agroagro.com/1.jpg'),
array('url' => '#', 'image' => 'http://dive.agroagro.com/2.jpg'),
array('url' => '#', 'image' => 'http://dive.agroagro.com/3.jpg')
);
?>
<?php for($i = 0; $i < $itemCount; $i++) { ?>
<div class="pull-left" style="width: 11.11%;">
</div>
<?php } ?>

Related

php two arrays into string

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.

i want to display ads in a foreach loop in codeigniter

i have some items i want displayed in the view, my per page is set to 15, so each page displays 15 items, but i want to display ads in the middle of the loop, after maybe 4 items displayed, I've tried to put an if statement in the foreach loop to control the display, it displays the first 3 values, but when i put the div for the ad, it loops too, can someone please tell me what to do, or point me in the right direction?? thanks, here is my code so far:
<?php
$counter1 = 0;
//the foreach loop that retrieves the values from the controller
foreach($records as $record){
//an if statement to display the first 4 items..
if ($counter1 <= 3){
?>
<div class='box-scene'>
<div class='dbox'>
<div class='front face'>
<img src="images/newtag.png">
</div>
<a style="font-size:15px;" href="<?php echo base_url();?>music/<?php echo $record->url; ?>">
<div class="side face">
<span>
<?php echo $record->name; ?>
</span>
</div>
</a>
</div>
</div>
<?php
$counter1++;
}
?>
<div style="width:200px; height:200px; float:left; display:inline-block; margin: 0 12.5px 20px 12.5px;">
<div id="ad_200_200">
</div>
</div>
<!-- this div displays more than once, i dont know where to place it
for it to display after the first 3 items -->
<?php
}
?>
i want to know where to place the div, and how to continue displaying the items...thanks
Hi please use else condition.please check replace with below code
<?php
$counter1 = 0;
//the foreach loop that retrieves the values from the controller
foreach ($records as $record) {
//an if statement to display the first 4 items..
?>
<?php if($counter1 % 4 == 0) { ?>
<div style="width:200px; height:200px; float:left; display:inline-block; margin: 0 12.5px 20px 12.5px;">
<div id="ad_200_200">
</div>
</div>
<?php } ?>
<div class='box-scene'>
<div class='dbox'>
<div class='front face'>
<img src="images/newtag.png">
</div>
<a style="font-size:15px;" href="<?php echo base_url(); ?>music/<?php echo $record->url; ?>">
<div class="side face">
<span>
<?php echo $record->name; ?>
</span>
</div>
</a>
</div>
</div>
<!-- this div displays more than once, i dont know where to place it
for it to display after the first 3 items -->
<?php
$counter1++;
}
?>
use also an else statement like below:
<?php
$counter1 = 0;
foreach($records as $record){
if ($counter1 <= 3){ ?>
<div class='box-scene'>
<div class='dbox'>
<div class='front face'>
<img src="images/newtag.png">
</div>
<a style="font-size:15px;" href="<?php echo base_url();?>music/<?php echo $record->url; ?>">
<div class="side face">
<span>
<?php echo $record->name; ?>
</span>
</div>
</a>
</div>
<div>
<?php
$counter1++;
} else{ ?>
<div style="width:200px;height:200px;float:left;display:inline-block; margin: 0 12.5px 20px 12.5px;">
<div id="ad_200_200"></div>
</div>
<?php
$counter1 = 0;
} ?>
<?php
}
?>

Every/other CSS techniques

I am creating a page with 4 different sections. In each section there is a responsive image and on the image there is text and some buttons. Right now they are aligned a bit off center and to the right. I am trying to achieve so that the 1st div the text and buttons float right and the 2nd div the text and buttons float left and so on. I am using the even odd nth property but it is only responding on the even css nth property. Here is the CSS and html. Keep in mind I am just using the background color now as an example and will put in the floats and padding if I get it working.
.popup-open:nth-child(odd) {
background: #ff0000;
}
.popup-open:nth-child(even) {
background: #000000;
}
<div class="popup-open">
<div class="icons-large">
<?php
$fields = CFS()->get('icons_large');
if($fields) :
foreach ($fields as $field) : ?>
<div class="row">
<div class="image">
<img src="<?php echo $field['icons_big'];?>" alt="">
</div>
</div>
<?php endforeach; endif; ?>
</div>
<div class="icons-large">
<?php
$fields = CFS()->get('tour_titles');
if($fields) :
foreach ($fields as $field) : ?>
<?php echo $field['tour_name'];?>
<?php endforeach; endif; ?>
</div>
<div class="title"><?php the_title(); ?></div>
</div>
I think you should add a class to the divs and target them that way, you will have more control over it too.
if($fields) :
$i = 1;
foreach ($fields as $field) :
if($i === 2){
$class = "even";
$i = 1;
}else if($i === 1){
$class = "odd";
$i = 2;
}
<div class="row <?=$class;?>">
<div class="image">
<img src="<?php echo $field['icons_big'];?>" alt="">
</div>
</div>
<?php endforeach; endif; ?>

How can I display a two column array in PHP/HTML?

I have an array of icons. Right now, we only display them in buckets of 4. So if you have 7 icons, the 4th icon on the first slide will repeat as the 8th on the second slide. That's because the 3rd index of the array is stored in that same spot. To fix this, I want to loop through the array instead of explicitly iterating icon by icon.
<?php if (!empty($icons)) { // if we have icons attributes
// NOTE: we've changed it to show as many sets as we can
// (sets of 4)
$number_of_sets = ceil(count($icons) / 4);
$k=0; // for inner iteration
for ($j=0;$j < $number_of_sets; $j++) {
$slide_total ++;
?>
<div class="cf slide icon-slide">
<?php
// up to 4 icons
if (is_array($icons) && !empty($icons[$k])) {
$icon1 = $icons[$k];
$k++;
}
?>
<div class="col left">
<div class="cf icon">
<div class="col thumb">
<img src="<?=$icon1['thumb']?>" alt="<?=htmlentities($icon1['post_title'])?>" />
</div>
<div class="colR details">
<h4><?=$icon1['post_title']?></h4>
<p><?=$icon1['post_content']?></p>
</div>
</div>
<?php
// up to 4 icons
if (is_array($icons) && !empty($icons[$k])) {
$icon2 = $icons[$k];
$k++;
}
?>
<div class="cf icon">
<div class="col thumb">
<img src="<?=$icon2['thumb']?>" alt="<?=htmlentities($icon2['post_title'])?>" />
</div>
<div class="colR details">
<h4><?=$icon2['post_title']?></h4>
<p><?=$icon2['post_content']?></p>
</div>
</div>
</div>
<?php
// up to 4 icons
if (is_array($icons) && !empty($icons[$k])) {
$icon3 = $icons[$k];
$k++;
}
?>
<div class="colR right">
<div class="cf icon">
<div class="col thumb">
<img src="<?=$icon3['thumb']?>" alt="<?=htmlentities($icon3['post_title'])?>" />
</div>
<div class="colR details">
<h4><?=$icon3['post_title']?></h4>
<p><?=$icon3['post_content']?></p>
</div>
</div>
<?php
// up to 4 icons
if (is_array($icons) && !empty($icons[$k])) {
$icon4 = $icons[$k];
$k++;
}
?>
<div class="cf icon">
<div class="col thumb">
<img src="<?=$icon4['thumb']?>" alt="<?=htmlentities($icon4['post_title'])?>" />
</div>
<div class="colR details">
<h4><?=$icon4['post_title']?></h4>
<p><?=$icon4['post_content']?></p>
</div>
</div>
</div>
</div> <!-- // end icon slide -->
<?php
} // end for $j (number of sets of 4 icons
?>
My proposed solution:
<?php if (!empty($icons)) {
$num_cols = 2;
$i = 0;
$slide_items = 4;
?>
<div class="cf slide icon-slide">
<?php foreach ( $icons as $icon ) {
echo $i++%$num_cols==0 ? '</div><div class="col" style="width: 250px;">' : '';
?>
<div class="cf icon">
<div class="col thumb">
<img src="<?=$icon['thumb']?>" alt="<?=htmlentities($icon['post_title'])?>" />
</div>
<div class="colR details">
<h4><?=$icon['post_title']?></h4>
<p><?=$icon['post_content']?></p>
</div>
</div>
<?php } } // end if we have icons attributes ?>
I'm having trouble figuring out how to make another slide after I hit 4 icons. Adding the following line before the end of the foreach loop hasn't worked.
echo $i++%$slide_items==0 ? '</div><div class="cf slide icon-slide">' : '';
Here's some logic for the loop:
$i = count( $icons );
if ( $i % 4 != 0 )
$i = $i + ( $i % 4 );
for( $n = 0; $n < $i; $n++ )
{
if ( $n % 4 == 0 )
{
// code to open a row here
}
// code to open a column here
// echo your icon here, use isset() or !empty().
// code to close a column here
if ( $n > 0 && $n % 3 == 0 )
{
// code to close a row here
}
}
The IFs at the top is for keeping the column number consistent. Otherwise there'll be some weirdness at the end of the loop.

Automatically Update Bootstrap Layout With PHP

I'm trying to generate a layout with php and jQuery which lists certain profiles and organizes them in a certain way.
Specifically, I have an array of program titles and I'd like to list all of the program titles on the page as headers with two program titles per row. Then, I have an array of names which each contain an array of program names. I'd like to list all of the users that have a certain program in their array underneath the relevant program title. Additionally, the names start off hidden and each program title has a button underneath it which hides and shows tutors. I've created this layout using Bootstrap here:
<?php
include ('objects.php');
function tutorCreator($tutorName, $boxNum, $spanClass){
include ('objects.php');
echo "<div class='" . $spanClass . " tutorBox" . $boxNum . "'>";
}
?>
<div class="row-fluid">
<span class="programHeader span5">DreamWeaver</span>
<span class="programHeader offset1 span5">GIMP</span>
</div>
<div class="row-fluid">
<span class="span2 showTutors">Show tutors</span>
<span class="span2 offset4 showTutors">Show tutors</span>
</div>
<div class="row-fluid">
<?php
tutorCreator('Kevin Marks', '1', "span4");
tutorCreator('Kevin Marks','2', "span4 offset2");
?>
</div>
<div class="row-fluid">
<?php
tutorCreator('Helen Larson', "1", "span4");
tutorCreator('Helen Larson','2', "span4 offset2");
?>
</div>
<div class="row-fluid">
<span class="programHeader span5">Google Analytics</span>
<span class="programHeader offset1 span5">HootSuite</span>
</div>
<div class="row-fluid">
<span class="span2 showTutors">Show tutors</span>
<span class="span2 offset4 showTutors">Show tutors</span>
</div>
<div class="row-fluid">
<?php
tutorCreator('Ken Gato', '3', "span4");
tutorCreator('Julien Mans', '4', "span4 offset2");
?>
</div>
<div class="row-fluid">
<?php
tutorCreator('Ommed Kosh', '3', "span4");
?>
</div>
The classes added to the tutor names are for the purpose of being shown when the appropriate "show tutors" button is listed and to help with the layout.
The objects.php file contains the arrays with the list of tutors and the list of programs. This layout works fine. However, I'm trying to change the php code so that this layout is automatically updated each time I add a program or a tutor to the arrays in objects.php. I've been trying to figure it out for a few days and I just can't get an automatically updated layout which works well. I realize this is probably too broad a question but I've hit a road block so any help would really be appreciated. You can see a fuller version of the current layout here: http://www.tutorgrams.com/tutors. Thanks for any help.
Here is the objects.php file (with some tutors and programs removed for brevity):
<?php
$programs = array();
$programs['DreamWeaver'] = array(
'name' => 'DreamWeaver');
$programs['GIMP'] = array(
'name' => 'GIMP');
$programs['Google Analytics'] = array(
'name' => 'Google Analytics');
$programs['HootSuite'] = array(
'name' => 'HootSuite');
$tutors['Helen Larson'] = array(
'name' => 'Helen Larson',
'programs' => array('DreamWeaver', 'GIMP')
);
$tutors['Kevin Marks'] = array(
'name' => 'Kevin Marks',
'programs' => array('DreamWeaver', 'GIMP')
);
$tutors['Ommed Kosh'] = array(
'name' => 'Ommed Kosh',
'programs' => array('Google Analytics')
);
$tutors['Julien Mans'] = array(
'name' => 'Julien Mans',
'programs' => array('HootSuite')
);
$tutors['Ken Gato'] = array(
'name' => 'Ken Gato',
'programs' => array('Google Analytics')
);
?>
How does this look?
<?php
$numProgs = count($programs);
$progs = array_keys($programs);
$i = 0; ?>
<?php while($i < $numProgs): ?>
<div class="row-fluid">
<span class="programHeader span5"><?php echo $progs[$i]; ?></span>
<span class="programHeader offset1 span5"><?php echo $progs[$i + 1]; ?></span>
</div>
<div class="row-fluid">
<span class="span2 showTutors">Show tutors</span>
<span class="span2 offset4 showTutors">Show tutors</span>
</div>
<div class="row-fluid">
<?php foreach($tutors as $name => $data) {
$tutProgs = $data['programs'];
if(in_array($progs[$i], $tutProgs)) {
tutorCreator($name, $i, "span4");
}
} ?>
</div>
<div class="row-fluid">
<?php
foreach($tutors as $name => $data) {
$tutProgs = $data['programs'];
if(in_array($progs[$i + 1], $tutProgs)) {
tutorCreator($name, $i + 1, "span4 offset2");
}
}
?>
</div>
<?php $i += 2; ?>
<?php endwhile; ?>
It could probably be optimised a little but it seems to do the trick for me. The only thing is I don't have your themes so It might not look right yet.

Categories