Trying to display the custom posts on my archive page within a bootstrap row containing 3 columns then starting a new row, got the code but new to PHP and dont know where to put the content.
<?php
//Columns must be a factor of 12 (1,2,3,4,6,12)
$numOfCols = 3;
$rowCount = 0;
$bootstrapColWidth = 12 / $numOfCols;
?>
<div class="row">
<?php
foreach ($rows as $row){
?>
<div class="col-md-4"<?php echo $bootstrapColWidth; ?>">
<div class="thumbnail">
<img src="user_file/<?php echo $row->foto; ?>">
</div>
</div>
<?php
$rowCount++;
if($rowCount % $numOfCols == 0) echo '</div><div class="row">';
}
?>
</div>
<div class="embed-container">
<?php the_field('podcast_embed_link'); ?>
</div>
<h3><?php the_title(); ?></h3>
<p><b><?php echo $date->format( $format_out );?></b></p>
<p><?php the_field('description'); ?></p>
<?php if( get_field('thumbnail') ): ?>
<img src="<?php the_field('thumbnail'); ?>" />
<?php endif; ?>
<?php endwhile; // end of the loop. ?>
</div>
</div>
</div><!-- #content -->
Here is the code for the page archive.podcasts.php, where would i add the custom fields within the row loop?
First of all, you don't need to close and open row tag each 3 items. If you leave the code like this:
<div class="row">
<?php
foreach ($rows as $row){
?>
<div class="col-md-<?php echo $bootstrapColWidth; ?>">
<div class="thumbnail">
<img src="user_file/<?php echo $row->foto; ?>">
</div>
</div>
<?php
}
?>
</div>
you will get the same effect, but without the separation that a row tag involves. Notice that the line involving "col-md-4" has already changes in order to not create wrong col size usage.
In this part of code:
<div class="col-md-4"<?php echo $bootstrapColWidth; ?>">
You must get wrong bootstrap class like col-md-41, col-md-412.
Correct you code by this way:
<div class="col-md-<?php echo $bootstrapColWidth; ?>">
Related
I'm really new to php and now I got stucked on what I thought was something really easy. Byt I can't see wheres my problem is.
I'm trying to create a webshop page that displays all my products.
To the problem!
Here is my code so far. It displays all products as expected but it closes the main and product-container before all product-cards except from the first one. How to wrap all product-cards in the same div?
$pdo = connect();
$limit = 20;
$offset = 0;
$stmt = get_all_products($pdo, $limit, $offset);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<main>
<section class="product-container">
<?php
foreach($rows as $row) {
?>
<div class="product-card">
<img class="product-image" src="<?php echo $row['Img'];?>" >
<h2 class="title"><?php echo $row['ProductName']; ?></h2>
<span class="price"><?php echo $row['Price'];?></span><span>:-</span>
</div>
</section>
</main>
<?php
}?>
You should move the closing main and section tag after the foreach loop is closed.
<main>
<section class="product-container">
<?php
foreach($rows as $row) {
?>
<div class="product-card">
<img class="product-image" src="<?php echo $row['Img'];?>" >
<h2 class="title"><?php echo $row['ProductName']; ?></h2>
<span class="price"><?php echo $row['Price'];?></span><span>:-</span>
</div>
<?php }?> <!-- Close the foreach loop here -->
</section>
</main>
This is some Bootstrap HTML where I need to create multiple blocks like a table but it just grabs the first item in the DB and prints 50 of them. I'm having trouble figuring out how to mingle the php code and html code so it works correctly.
<section id="latest-news" class="latest-news-section">
<div class="container">
<?php
include_once ('mysql.inc.php');
$ix = $_POST['i'];
$sql = "SELECT * from deposits WHERE d_userid = '$ix' ORDER BY _productionid ASC";
$query = #mysql_query($sql);
$outcome = #mysql_fetch_array($query);
foreach ($outcome as $result1){
?>
This part comes out nicely formatted, but the only data is the first item in the DB, and there are 50 copies made
<div class="col-md-4 col-sm-4">
<div class="latest-post">
<img src="assets/images/<?php echo $outcome['d_picture'] ?>" class="img-responsive" alt="">
<h4>Your ST1 <?php echo $outcome['d_firstname'] ?></h4>
<p>Prod ID <?php echo $outcome['d_productionid'] ?></p>
<p>Color: <?php echo $outcome['d_color'] ?><br />
Equip: <?php echo $outcome['d_equip'] ?><br />
Custom: <?php echo $outcome['d_custom'] ?></p>
<a class="btn btn-primary">View More</a>
</div>
</div>
<?
}
#mysql_close;
?>
</div>
</section>
You should use $result1 and not $outcome
ex: $result1['d_picture']
I've got this PHP code:
<div class="connect_wrap <?php echo $this->class; ?> block" <?php echo $this->cssID; ?>>
<?php if(!$this->empty): ?>
<?php foreach($this->entries as $entry): ?>
<div class="entry block <?php echo $entry->class; ?>">
<div class="tab">
<ul class="tabs">
<li class="tab-link current" data-tab="Kunden">Kunden</li>
<li class="tab-link" data-tab="Loesungen">Lösungen</li>
</ul>
<?php
$this->import('Database');
$pName = $entry->field('name')->value();
$result = \Database::getInstance()->prepare("SELECT * FROM kunden WHERE partner=?")->execute($pName);
?>
<?php if($result->numRows):?>
<div id="Kunden" class="tab-content current">
<?php while($result->next()) { ?>
<div class="items">
<a href="{{env::url}}/kunden-detail/<?php echo $result->alias; ?>">
<div class="logo">
<img src="<?php $objFile = \FilesModel::findByUuid($result->logo); echo $objFile->path;?>"width="180" height="135">
</div>
</a>
</div>
<?php } ?>
</div>
<?php endif;?>
<?php
$this->import('Database');
$pName = $entry->field('name')->value();
$result = \Database::getInstance()->prepare("SELECT * FROM solutions WHERE solution_provider=?")->execute($pName);
?>
<?php if($result->numRows):?>
<div id="Loesungen" class="tab-content">
<?php while($result->next()) { ?>
<div class="items">
<a href="{{env::url}}/synaptic-commerce-solution/<?php echo $result->alias; ?>">
<div class="logo">
<img src="<?php $objFile = \FilesModel::findByUuid($result->logo); echo $objFile->path;?>"width="180" height="135">
</div>
</a>
</div>
<?php } ?>
</div>
<?php endif;?>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<?php endif;?>
In that code, I've got two DB queries. My problem is, if there is no data for both queries, the div with the class "connect_wrap" should not be displayed.
How can I do that?
Thanks in advance.
do you want to check if the query has data in it and its not empty ? if so try num_rows it will return the number of rows that the query found/affected for example to check if th query returned one or more rows
if($result->num_rows >= 1) {
//do stuf
} else {
// no result found
}
Move the query execution up or preferably: not within the html but in a different file/class. Then add a check before the content_wrap div: if($kundenResult->num_rows >= 1 || $solutionsResult->num_rows >= 1). If you just keep the individual checks like you already have, it will only show the content_wrap div if either or both of the queries return rows of data.
I create two design to display news .
first DIV Display BIGGER images and Separate css class and display only two rows.
Second DIV Display Smaller images and Separate css class and display five rows..
I select rows in asc order from query.
my query is = select * from news order by priority asc.
My Only Need is TO Display two rows in First div and then display another rows in Second DIV.
IS This is possible using if else or any other condition...how to do this.........
but keep all div tag as it is bcoz of page design purpose......
<!-- FIRST DIV -->
<div class="post">
<div class="buffer">
<?php foreach($top2 as $top){ ?>
<div class="content"> <img src="bhaskarcms/uploads/<?php echo $top['photo']; ?>" style="width:285px; height:100px;" />
<h2><?php echo htmlspecialchars_decode($top['headline']); ?></h2>
</div>
<?php } ?>
<!--<p class="details2">8 Comments / Read More</p>-->
</div>
</div>
<!-- end post -->
<!-- SECOND DIV -->
<!-- begin post -->
<div class="post">
<div class="buffer">
<?php foreach($top2 as $top){ ?>
<div class="content1"><img src="bhaskarcms/uploads/<?php echo $top['photo']; ?>" />
<h2><?php echo htmlspecialchars_decode($top['headline']); ?></h2>
</div>
<?php } ?>
</div>
</div>
<!-- end post -->
Yes, it's possible. Assuming your $top2 array has standard numerical/sequential keys, then:
$split = 2;
for($i = 0; $i < $split; $i++) {
... print $top2[0] and $top2[1]
}
for ($i = $split; $i < count($top2); $i++) {
... print the rest of the rows
}
Can use array_slice()
<!-- FIRST DIV -->
<div class="post">
<div class="buffer">
<?php $arr = array_slice($top2, 0, 2) ?>
<?php foreach($arr as $top){ ?>
<div class="content"> <img src="bhaskarcms/uploads/<?php echo $top['photo']; ?>" style="width:285px; height:100px;" />
<h2><?php echo htmlspecialchars_decode($top['headline']); ?></h2>
</div>
<?php } ?>
<!--<p class="details2">8 Comments / Read More </p>-->
</div>
</div>
<!-- end post -->
<!-- SECOND DIV -->
<!-- begin post -->
<div class="post">
<div class="buffer">
<?php $arr = array_slice($top2, 2) ?>
<?php foreach($arr as $top){ ?>
<div class="content1"><img src="bhaskarcms/uploads/<?php echo $top['photo']; ?>" />
<h2><?php echo htmlspecialchars_decode($top['headline']); ?></h2>
</div>
<?php } ?>
</div>
Add a count that you increment in the foreach loop, then break when its over two:
<!-- FIRST DIV -->
<div class="post">
<div class="buffer">
<?php
$rowCount = 0;
foreach($top2 as $top){ ?>
<div class="content"> <img src="bhaskarcms/uploads/<?php echo $top['photo']; ?>" style="width:285px; height:100px;" />
<h2><?php echo htmlspecialchars_decode($top['headline']); ?></h2>
</div>
<?php
$rowCount++;
if($rowCount > 2){
break;
}
} ?>
<!--<p class="details2">8 Comments / Read More</p>-->
</div>
</div>
<!-- end post -->
so I am trying to add a new row after every 4th gallery and continue on until I am out of galleries to add. So if there is 17 galleries there will be 4 rows of 4 galleries and 1 row of the remaining gallery. here is an example of how it looks: http://www.csulb.edu/centers/latinohealth/media/galleries/
here is my code:
<?php $this->start_element('nextgen_gallery.gallery_container', 'container', $displayed_gallery); ?>
<div class="row-fluid secondone">
<div class="ngg-albumoverview span12">
<div class="row-fluid">
<?php $count = 0;?>
<?php foreach ($galleries as $gallery) {
$count++;
?>
<div class="ngg-album span3">
<div class="ngg-albumtitle">
<?php echo_safe_html($gallery->title); ?>
</div>
<div class="ngg-albumcontent">
<div class="ngg-thumbnail">
<a class="gallery_link" href="<?php echo nextgen_esc_url($gallery->pagelink); ?>"><img class="Thumb" alt="<?php echo esc_attr($gallery->title); ?>" src="<?php echo nextgen_esc_url($gallery->previewurl); ?>"/></a>
</div>
<div class="ngg-description">
<p><?php echo_safe_html($gallery->galdesc); ?></p>
<?php if (isset($gallery->counter) && $gallery->counter > 0) { ?>
<p><strong><?php echo $gallery->counter; ?></strong> <?php _e('Photos', 'nggallery'); ?></p>
<?php } ?>
</div>
</div>
</div>
<?php if ($count % 4 == 0 ) ?>
</div>
<div class="row-fluid">
<?php } ?>
</div>
</div>
</div>
<?php $this->end_element(); ?>
Found the problem:
the row:
<?php if ($count % 4 == 0 ) ?>
should be:
<?php if ($count % 4 == 0 ) { ?>
You need to do what you want with css styles, not with the php.
Create a container block with fixed width that can contain exacly 4 galleries and use the float property on the boxes of the galleries.