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.
Related
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; ?>">
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.
Ive got the follow PHP:
<div class="slide-background">
<div class="slide">
<?php foreach (array_chunk($items->submenu, $linkCount) as $items): ?>
<?php if (12 / $cols == 1):?>
<div class="col-md-12">
<?php else: ?>
<div class="col-md-<?php echo 12 / $cols; ?>">
<?php endif; ?>
<ul>
<?php foreach($items as $submenu): ?>
<?php echo $submenu; ?>
<?php endforeach; ?>
</ul>
</div>
<?php endforeach; ?>
</div>
<ul class="pager">
<li>prev</li>
<li>next</li>
</ul>
</div>
</div>
basically it calculates how many links to display and how many columns, but i now need to place the links in <div class="slide"></div>, but based on the columns.. so basically i need to say if $cols = 2 place two div's in a div and close.. so its basically how many every $cols it should place so many div's in that div..
Its Confusing for me to even explain.. I think Ive explained it rather well above.. If not place say so and ill try again..
Any Help Greatly Appreciated..
UPDATE:
thanks to Hans ive now have the following:
<?php $linksPerColumn = ceil($linkCount / $cols); $linkCounter = 0;?>
<div class="slide-background">
<div class="slide">
<div class="col-md-<?php echo 12 / $cols ?>">
<ul>
<?php foreach ($items->submenu as $link): ?>
<?php $linkCounter++;?>
<?php if($linkCounter % $linksPerColumn == 0):?>
</ul>
</div>
<div class="col-md-<?php echo 12 / $cols ?>">
<ul>
<?php endif; ?>
<?php echo $link; ?>
<?php endforeach; ?>
</ul>
</div>
</div>
<ul class="pager">
<li>prev</li>
<li>next</li>
</ul>
</div>
</div>
only problem is when there's only one column and i need 2 links and then for it to close the div and the ul and start new ones.. right now it does that except for everyone and not for every two links...
You could use modulus for this one. You should calculate how many items you need per column. And then create a close and open div for example:
<?
$linksPerColumn = 4;
if ($linkCount > 4){
$linksPerColumn = ceil ($linkCount / $amountOfColums);
}
$linkCounter = 0;
?>
<div class="slide-background">
<div class="slide">
<?
foreach ($links as $link)
{
$linkCounter++;
?>
// Do your HTML Here.
<?
if($linkCounter % $linksPerColumn = 0)
{
?>
</div>
<div class="slide">
<?
}
?>
</div>
</div>
// Rest of the HTML here.
I think this should do the trick for you.
My page http://www.allyourpods.no/ has some odd "holes" that I cant for the life of me figure out.
I would love some help to figure out how to make it automagickly fill the site in a proper fashion.
My template-file for the start-screen looks like this:
<?php
/*
Template Name: Home Template
*/
get_header(); ?>
<?php query_posts('cat='.recPodcastCategory.'&showposts=30');?>
<?php $categories = get_categories('child_of='.recPodcastCategory); ?>
<?php if($categories): $count=0;?>
<div class="recommended">
<div class="wrapper">
<div class="main_recommended_main_block">
<?php foreach($categories as $category) { if($count<30) { $count++;
if($count!=30) $class='recommend_block'; else $class='recommend_block_1'; ?>
<?php if (function_exists('get_terms_meta'))
{
$cat_image = get_terms_meta($category->term_id, 'image',true);
$add_play_podcast = get_terms_meta($category->term_id, 'play_download',true);
}?>
<div class="<?php echo $class;?>">
<div class="main">
<?php $play_podcast = get_post_meta($post->ID,'play_podcast',true);?>
<div class="view view-fifth"><?php if($cat_image):?><img src="<?php echo $cat_image;?>" alt="category image" /><?php endif;?>
<?php if($add_play_podcast):?>
<div class="mask">Play</div>
<?php endif; ?>
</div>
</div>
<?php echo substr( category_description( $category->term_id ),0,100 ) . "..."; ?>
</div>
<?php } } ?>
</div>
</div>
</div>
<?php endif; ?>
<?php if(!isset($_GET['pod_category']))$class_all = ' class="active"'; ?>
<div class="clr"></div>
<?php get_footer(); ?>
If any more information is needed please let me know.
You should add this css:
.recommend_block:nth-child(4) {
clear: left;
}
The problem is one of the first two is a little lower than the others, so it is blocking the float.
Edit: that should be
.recommend_block:nth-child(4n)
I am creating some jQuery functionality on my website whereas an array of Facebook posts and Tweets is looped through to show on the front page.
I have 5 boxes on my front page which I need 5 to show random elements from this array at the same time, then I using some jQuery cycle functionality to cycle through this array. The only issue is, as I am looping over this array 5 times (with each box) and there are only 20 items in this array it can show repeated data.
To help explain this more here is my code:
<?php
$social_feeds = array_merge($tweets_feed, $facebook_feeds);
$social_feeds_arranged = $tweets_feed_instance->sortArrayItemsByDate($social_feeds);
?>
<div id="social_box_item1" class="social_box_item">
<?php foreach($social_feeds_arranged as $item) { ?>
<a class="item">
<?php echo $item['text'] ?>
</a>
<?php } ?>
</div>
<div id="social_box_item2" class="social_box_item">
<?php foreach($social_feeds_arranged as $item) { ?>
<a class="item">
<?php echo $item['text'] ?>
</a>
<?php } ?>
</div>
<div id="social_box_item3" class="social_box_item">
<?php foreach($social_feeds_arranged as $item) { ?>
<a class="item">
<?php echo $item['text'] ?>
</a>
<?php } ?>
</div>
<div id="social_box_item4" class="social_box_item">
<?php foreach($social_feeds_arranged as $item) { ?>
<a class="item">
<?php echo $item['text'] ?>
</a>
<?php } ?>
</div>
<div id="social_box_item5" class="social_box_item">
<?php foreach($social_feeds_arranged as $item) { ?>
<a class="item">
<?php echo $item['text'] ?>
</a>
<?php } ?>
</div>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#social_box_item1').cycle({
});
jQuery('#social_box_item2').cycle({
});
jQuery('#social_box_item3').cycle({
});
jQuery('#social_box_item4').cycle({
});
jQuery('#social_box_item5').cycle({
});
});
</script>
What I need to happen I think is for the first loop to push the item it is displaying ot the back of the array, so when the second loop accesses the first item it will not show the same array item, the same with the 3rd, 4th and 5th loops. I have attempted to do this using array_push and array_shift but can't seem to get it working.
Does anybody have any ideas or can help point out where I am going wrong?
Those loops are not needed then. You can access those array items one by one, if you meant that. Try this:
$social_feeds = array_merge($tweets_feed, $facebook_feeds);
$social_feeds_arranged = $tweets_feed_instance->sortArrayItemsByDate($social_feeds);
?>
<div id="social_box_item1" class="social_box_item">
<a class="item">
<?php echo $social_feeds_arranged[0]['text']; ?>
</a>
</div>
<div id="social_box_item2" class="social_box_item">
<a class="item">
<?php echo $social_feeds_arranged[1]['text']; ?>
</a>
</div>
<div id="social_box_item3" class="social_box_item">
<a class="item">
<?php echo $social_feeds_arranged[2]['text']; ?>
</a>
</div>
<div id="social_box_item4" class="social_box_item">
<a class="item">
<?php echo $social_feeds_arranged[3]['text']; ?>
</a>
</div>
<div id="social_box_item5" class="social_box_item">
<a class="item">
<?php echo $social_feeds_arranged[4]['text']; ?>
</a>
</div>