how to disable fancybox on certain div's - php

I have a fancybox that opens on div click. The divs are made automatically and the id's are not the same.
I have 8 divs on which the fancybox should open on 4 of them and it does.
But on the others, it opens also with a content can't be found message, and that should not pop up.
I have tried the jquery removeclass function already but doesn't seem to be working.
This is the code :
$outputEdities = '<div id="data_' . $currID . '" class="fancybox-content" style="display: none; max-width: 600px;"> ';
while($rowEditie = mysql_fetch_assoc($resultEdities)){ //Creates a loop to loop through results
$currIDEditie = $rowEditie['id'];
$currStream = $rowEditie['streamurl'];
$currStation = $rowEditie['stationid'];
$currName = $rowEditie['editienaam'];
$outputEdities .= '<h2>Editie</h2>';
$outputEdities .= '<h1>'. $currName .' </h1>';
}
$outputEdities .= '</div>';
}
$output .= '<div class="content-b' . $count . '" style="text-align:center;">';
//$output .= $outputEdities;
$output .= '<img src="' . $currPicture . '" alt="' . $currName . ' Luisteren" />';
$output .= $outputEdities;
$output .= '</div>';
if( $count == 1 )
$count = 2;
else if( $count == 2 )
$count = 3;
else if( $count == 3 )
{
$count = 1;
$output .= '<div class="clear"></div>';
This code generates the divs and shows content.
I dont know if I have posted my question correctly but we will see.

Related

Adding background color to element within php if-statement

I have the following code in which I want to add an element to my if statement, but I am unsure how to approach this. What I am looking to do is add a background-color to the else part of it. Within this:
else {
$status_img = '<img src="../icons/collection/checkmark.png" alt="Goal Complete">';
}
So if $status is not 0, I want to set background color for the class goal-box-right.
Is there anyway I can manipulate the CSS through php like this?
foreach ($rows as $row) {
$status = $row['status'];
if ($status == 0) {
$status_img = '<img src="../icons/collection/x-sign.png" alt="Goal Not Complete">';
}
else {
$status_img = '<img src="../icons/collection/checkmark.png" alt="Goal Complete">';
}
$goal_date = $row['date'];
$fixed_goal_date = fixDate($goal_date);
$html = "";
$html .= '<div class="goal-box" id="comment-'.$row['id'].'">';
$html .= '<div class="goal-box-left">'; //added
$html .= '<div class="goal-post-status">'.$status_img. '</div>';
$html .= '</div>'; //added
$html .= '<div class="goal-box-right">'; //added
$html .= '<div class="goal-post-title">'.$row['title']. '</div>';
$html .= '<div class="goal-post-date">'.$fixed_goal_date. '</div>';
$html .= '<div class="goal-post-description">'.$row['description']. '</div>';
$html .= '</div>'; //added
$html .= '</div>';
Separate the logic - add a CSS class based on the status then set the colours in the stylesheet.
$class = $status != 0 ? 'status-nonzero' : '';
$html .= '<div class="goal-box-right ' . $class . '">';
CSS:
.goal-box-right.status-nonzero { background-color: #foo }
Advantage is keeping the style logic in the CSS where it belongs and away from the code that's generating the HTML.
So what's the problem:
$style = '';
if ($status == 0) {
$style = ' style="your-style:here"';
$status_img = '<img src="../icons/collection/x-sign.png" alt="Goal Not Complete">';
}
else {
$status_img = '<img src="../icons/collection/checkmark.png" alt="Goal Complete">';
}
// ...
$html .= '<div class="goal-box-right"' . $style . '>'; //added

My For loop in PHP used to iterate an array works on the first loop, but not the second

if (isset($_GET['q'])){
$q = $_GET['q'];
//variables
$sql = "SELECT * FROM products WHERE product LIKE '%$q%' OR search LIKE '%$q%'";
$result = $conn->query($sql);
//check database
if($result->num_rows > 0){
while ($row = $result->fetch_array()){
$product = $row['product'];
$productImage = $row['product_image'];
$price = $row['price'];
$seller = $row['seller_name'];
$sellerImage = $row['seller_image'];
$desc = $row['description'];
$search = $row['search'];
$console = $row['console'];
$array = array($product, $price, $productImage);
$arrayDesc = array($desc, $sellerImage);
if (preg_match('/Game/', $seller)){
for ($num = 0; $num < 3; $num++) {
echo '<div class="tile col-md-4 col-sm-3">';
if($num == 0){
echo '<div class="tileTitleBox"><h4>' . $array[$num] . '</h4></div>';
}
if($num = 1){
echo '<p class="price">' . $array[$num] . '</p>';
}
if($num = 2){
echo '<img class="tilePic" src="' . $array[$num] . '"/>';
}
// if($num = 3){
// echo '<div class = "desc"><p>' . $array[$num] . '</p></div>';
// }
echo '</div>';
}//For Iteration Loop - TILE
for($count = 0; $count < 2; $count++){
echo '<div class="tile-description col-md-4 col-sm-3 hidden">';
if($count == 0){
echo '<div class="desc"><p>' . $arrayDesc[$count] . '</p></div>';
}
if($count == 1){
echo '<img class="sellerImg" src="' . $arrayDesc[$count] . '"/>';
}
echo '</div>';
}//end for loop - TILE-DESCRIPTION
So as you see above, I have one for loop which creates the "tile" and the second which is supposed to create the "tile-description". The first one works well to create a single div with the class of "tile" in which my remaining contents is loaded into the div. But in the second for loop the "desc" dev and the "sellerImg" div are separated. The loop needs to go through the array various times.
Shown Bellow:
You can see that the "Tile" div contains "tileTitleBox", "price", and "tilePic". But the "tile-description" which is hidden, is separated into two divs. As opposed to holding both elements inside the same div.
#sam-dufel rightly pointed out you're overwriting the iterator
if($num = 1){
But in fact you shouldn't use any loops here:
echo '<div class="tile col-md-4 col-sm-3">';
echo '<div class="tileTitleBox"><h4>' . $array[0] . '</h4></div>';
echo '<p class="price">' . $array[1] . '</p>';
echo '<img class="tilePic" src="' . $array[2] . '"/>';
echo '</div>';
echo '<div class="tile-description col-md-4 col-sm-3 hidden">';
echo '<div class="desc"><p>' . $arrayDesc[0] . '</p></div>';
echo '<img class="sellerImg" src="' . $arrayDesc[1] . '"/>';
echo '</div>';

How can I echo two items per one time by using PHP Foreach?

I'm using PHP to echo my products from the database. If we just use foreach, we will get the result one item per a loop, but actually I want it echo two items per one times as ub the below function.
This is my PHP function using foreach to fetch data from database.
I've used row item selector to wrap product selector, so I want to echo a block of product two times, and then it should echo the row item.
Example: row item = 1 then product = 2
public function last_upated_products() {
$data = $this->newest_products_from_db('products');
$out = '';
if ($data) {
foreach ($data as $k => $row) {
$out .= '<div class="row item">';
$out .= '<div class="product">';
$out .= '<div class="image">';
$out .= '<img src="' . base_url('asset/img/main/9.jpg') . '" alt="img" class="img-responsive">';
$out .= '<div class="promotion"><span class="discount">' . $row['prod_id'] . '% OFF</span> </div>';
$out .= '</div>';
$out .= '<div class="description"><div class="price"><span>$' . $row['prod_price'] . '</span></div><h4>' . $row['prod_name'] . '</h4>';
$out .= '<p>' . $row['prod_descrip'] . '</p>';
$out .= '</div>';
$out .= '</div>';
$out .= '</div>';
}
}
return $out;
}
This function will echo one item for a loop.
You can not print two times in one iteration of a loop. You can use conditional HTML output to do this job.
Consider this:
function last_upated_products() {
$data = $this->newest_products_from_db('products');
$out = '';
$counter = 1;
$length = count($data);
if ($data) {
foreach ($data as $k => $row) {
if ($counter % 2 != 0) {
$out .= '<div class="row item">';
}
$out .= '<div class="product">';
$out .= '<div class="image">';
$out .= '<img src="' . base_url('asset/img/main/9.jpg') . '" alt="img" class="img-responsive">';
$out .= '<div class="promotion"><span class="discount">' . $row['prod_id'] . '% OFF</span> </div>';
$out .= '</div>';
$out .= '<div class="description"><div class="price"><span>$' . $row['prod_price'] . '</span></div><h4>' . $row['prod_name'] . '</h4>';
$out .= '<p>' . $row['prod_descrip'] . '</p>';
$out .= '</div>';
$out .= '</div>';
if ($counter % 2 == 0 || $length == $counter) {
$out .= '</div>';
}
$counter++;
}
}
return $out;
}
You can use the modulus operator to make the check. If your iterator is a multiple of two it will output the appropriate elements (it does this by checking that the remainder is zero):
public function last_upated_products() {
$data = $this->newest_products_from_db('products');
$out = '';
if ($data) {
$i = 0;
foreach ($data as $k => $row) {
if( ($i % 2) === 0) {
$out .= '<div class="row item">';
}
$out .= '<div class="product">';
$out .= '<div class="image">';
$out .= '<img src="' . base_url('asset/img/main/9.jpg') . '" alt="img" class="img-responsive">';
$out .= '<div class="promotion"><span class="discount">' . $row['prod_id'] . '% OFF</span> </div>';
$out .= '</div>';
$out .= '<div class="description"><div class="price"><span>$' . $row['prod_price'] . '</span></div><h4>' . $row['prod_name'] . '</h4>';
$out .= '<p>' . $row['prod_descrip'] . '</p>';
$out .= '</div>';
$out .= '</div>';
if( ($i + 1) % 2 === 0 || ($i + 1) === count($data) ) {
$out .= '</div>';
}
$i++;
}
}
return $out;
}
Note that the last bit ($i + 1) === count($data) is important in the event that your set holds an uneven number.

I need to wrap span tags around breadcrumb text, this is what I have

Drupal 7:
function THEMENAME_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
if (!empty($breadcrumb)) {
// Provide a navigational heading to give context for breadcrumb links to
// screen-reader users. Make the heading invisible with .element-invisible.
$output = '<h2 class="element-invisible">' . t('You are here:') . '</h2>';
$crumbs = '<ul class="breadcrumbs clearfix">';
$array_size = count($breadcrumb);
$i = 0;
while ( $i < $array_size) {
$crumbs .= '<li class="breadcrumb-' . $i;
if ($i == 0) {
$crumbs .= ' first';
}
if($i != 0 && $i+1 != $array_size ) {
$crumbs .= ' middle';
}
if ($i+1 == $array_size) {
$crumbs .= ' last';
}
$crumbs .= '">' . $breadcrumb[$i] . '</li>';
$i++;
}
$crumbs .= '</ul>';
return $crumbs;
}
}
This outputs the breadcrumbs in the format I need other than I need to add span tags around the text inside the link.
The link is being written in the seventh line from the bottom:
$crumbs .= '">' . $breadcrumb[$i] . '</li>';
Any ideas?
Since I can't see the content inside of $breadcrumb[$i] I can't be completely sure that this will work, but the following code should work for you as it wraps anything inside an anchor tag with a span tag:
preg_match("#<a ([^>]+)>(.+)</a>#i", $breadcrumb[$i], $matches);
$crumbs .= '"><a ' . $matches[1] . '><span>' . $matches[2] . '</span></a></li>';
Just replace the seventh line in your function with these 2 lines and see if it works! Otherwise, use var_dump on $breadcrumb[$i] and add the result to your question.

Writing out the category of a product from Duka Press Plugin

I'm trying to modify a wordpress plugin called Duka Press, and I'm a complete noobie to PHP. It uses shortcodes which produces the template for the product grid, and I basically just need to write out all the categories the product has to create jQuery filter function.
To better understand what I need read the HTML comment in the code underneath
CODE:
<ul>
I need this for each category inside the active category set i the shortcode:
<li>[CategoryNameHere]</li>
</ul>
$products = get_posts($order_string . 'numberposts=' . $per_page . '&post_type=' . $type . '&meta_key=price&category=' . $category . $offset);
if (is_array($products) && count($products) > 0) {
$content .= '<div class="dpsc_grid_display">';
$count = 1;
$all_count = 0;
foreach ($products as $product) {
$output = dpsc_get_product_details($product->ID, $p_b_n, $direct_checkout);
if ($output) {
$attachment_images = &get_children('post_type=attachment&post_status=inherit&post_mime_type=image&post_parent=' . $product->ID);
$main_image = '';
foreach ($attachment_images as $image) {
$main_image = $image->guid;
break;
}
$prod_permalink = get_permalink($product->ID);
$content .= '<div class="dpsc_grid_product">';
$content .= '<div class="dpsc_grid_product_image">';
if ($main_image != '') {
$content .= '<img src="' . DP_PLUGIN_URL . '/lib/timthumb.php?src=' . $main_image . '&w=' . $dp_shopping_cart_settings['g_w'] . '&h=' . $dp_shopping_cart_settings['g_h'] . '&zc=1" >';
}
$content .= '</div>';
<!-- In the following line i need to write out all the categories for the current product -->
$content .= '<div class="dpsc_grid_product_detail [Categories here]">';
$content .= '<p class="title">' . __($product->post_title) . '</p>';
$content .= '<p class="detail">' . $product->post_excerpt . '</p>';
$content .= '<p class="price">' . $output['price'] . '</p>';
$content .= $output['start'];
$content .= $output['add_to_cart'];
$content .= $output['end'];
$content .= '</div>';
$content .= '</div>';
if ($count === intval($column)) {
$content .= '<div class="clear"></div>';
$count = 0;
}
$count++;
$all_count++;
}
}
$content .= '<div class="clear"></div>' . $page_links . '<div class="clear"></div>';
$content .= '</div>';
$content .= '<div class="clear"></div>';
}
return $content;
Shortcode that uses the template above:
[dpsc_grid_display category="22" total="100" column="3" per_page="100" type="duka"]

Categories