I returning my data to build a list group. All is fine but when the data contains <pre> tag it messes my display.
My list group as follows.
if (isset($BS_array)){
//Create a list group to show results
echo '<div class="list-group">';
foreach($BS_array as $result){
?>
<!-- Build list group -->
<div class="list-group-item list-group-item-action" aria-current="true">
<div class="d-flex w-100 justify-content-between">
<!-- Incident number goes here -->
<h5 style="cursor: pointer;" id="<?php echo $result['number']; ?>" onclick="getINCDetails(this.id)" class="mb-1"><?php echo $result['number']; ?></h5>
</div>
<!-- Description goes here -->
<p class="mb-1"><?php echo $result['description']; ?></p>
<small>
<?php
//List BS in INC card
echo $result['state'];
?>
</small>
</div>
<?php
}
echo '</div>';
}
?>
The way when all goes ok should be like this.
But at times, $result['description'], contains the word <pre>, which messes things up.
It will look like this.
How do I fix/circumvent this problem?
If you dont require html tags to actually work on the description just use htmlentities():
<?php echo htmlentities($result['description']); ?>
That will actually show instead of the browser considering it html tag.
Related
I understand foreach but this is new for me because within the foreach in PHP I have some script for each item that shows up and wondering why it only works for the item in the first item
In the code, I am getting an image from an MYSQL database. instead of using onclick in js I am learning more into jquery and only when I click the first image it will generate the
$("#main").load("includes/product.php");
path and change I want to change but in the product name and the cart button do not change the visuals.
<section id="new-products" class="clearfix">
<div class="title-block">
<h4>New Products</h4>
</div>
<?PHP
foreach ($item as $items){
?>
<div class="left-col-block">
<article class="product-box clearfix">
<a href="#store/category/<?PHP echo $items['category'];?>/<?PHP echo $items['brand'];?>/<?PHP echo $items['name'];?>" id="product-link">
<img src="<?PHP echo $items['image']; ?>" alt="Card Games" title="Card Games" height="80" width="80">
</a>
<?PHP echo $items['name']; ?><br>
<span class="price">$<?php echo $items['price'];?></span>
</article>
`<script>
$( "#product-link" ).click(function() {
$("#main").load("includes/product.php");
});
</script>
</div>
<div class="left-col-block">
</div>
<?PHP
}
?>
</section>
Expected:
I am wanting each link with the id of product-link to give the event trigger with jquery on each product and each id
Actual Results:
$("#main").load("includes/product.php");
only works on the first id that is equal to product-link
because of you have 3 like for each item and you want to set on click for every 3 link, you must use class attribute and set it unique for each item.
I changed your code to this:
<section id="new-products" class="clearfix">
<div class="title-block">
<h4>New Products</h4>
</div>
<?PHP
foreach ($item as $key=>$items){
?>
<div class="left-col-block">
<article class="product-box clearfix">
<a href="#store/category/<?PHP echo $items['category'];?>/<?PHP echo $items['brand'];?>/<?PHP echo $items['name'];?>" class="product-link-<?=$key?>">
<img src="<?PHP echo $items['image']; ?>" alt="Card Games" title="Card Games" height="80" width="80">
</a>
<?PHP echo $items['name']; ?><br>
<span class="price">$<?php echo $items['price'];?></span>
</article>
`<script>
$( ".product-link-<?=$key?>" ).click(function() {
$("#main").load("includes/product.php");
});
</script>
</div>
<div class="left-col-block">
</div>
<?PHP
}
?>
</section>
Found the answer was
<script>$( ".product-box a" ).click(function() {
$("#main").load("includes/product.php");
});</script>
since product-bot was a class and I didn't realize the # makes it check for id and the. makes it search for a class and class is able to be called multiple times whereas an id has to be unique
I am using post navigation for my blog. For this portion i wrote some css. It's working fine. But the problem is for the very latest post , it's showing blank space for next post link. Same thing is happened with oldest post, it's showing again bank space for previous post link.
I add code snippet for this portion. Can i anyone suggest how can i modify my css for this portion. Following code is embedded in php file.
<div class="row justify-content-center">
<div class="sewl-more-posts">
<div class="previous-post">
<?php If(previous_post_link()){?>
<span class="post-control-link">Previous Article</span>
<span class="post-name"><?php previous_post_link(); ?></span>
<?php } ?>
</div>
<div class="next-post">
<?php If(next_post_link()){?>
<span class="post-control-link">Next Article</span>
<span class="post-name"><?php next_post_link(); ?></span>
<?php } ?>
</div>
</div>
</div>
First, output the divs only if they'll have content:
<div class="sewl-more-posts">
<?php if (previous_post_link()){?>
<div class="previous-post">
<span class="post-control-link">Previous Article</span>
<span class="post-name"><?php previous_post_link(); ?></span>
</div>
<?php } ?>
<?php if (next_post_link()){?>
<div class="next-post">
<span class="post-control-link">Next Article</span>
<span class="post-name"><?php next_post_link(); ?></span>
</div>
<?php } ?>
</div>
This way, if the previous-post or next-post div is missing, you'll be able to target the remaining one with the :only-child pseudo class:
.sewl-more-posts > div:only-child {
text-align: center;
}
You cannot do this with php once the page is generated client-side, therefore you have to use javascript (for example):
onclick = documet.getElementById('the id you have').style.property = "blue";
This is my code in the php file. excontent is an array, $rebuild is a string.
<div class="about-hero">
<h2><span class="accel"><?php echo $excontent[0] . " "; ?></span><?php echo $rebuild; ?> </h2>
</div>
This is what I get when I inspect the element:
<div class="about-hero">
<h2>
<span class="accel">
<p>
"Accelerate is a marketing agency located in NYC. A great blah blah blah."
</p>
</span>
</h2>
</div>
Any ideas why its putting in a p tag??? Its something with the PHP and I'm new to PHP. I tried it with just strings and it works fine. I'm changing the color of the first word in a sentence (following the design) the rebuild is the rest of the sentence. They both echo fine on their own and show the correct content.
I'm assuming the <p> tag is on the $excontent[0] variable. In this case, you could try removing all HTML tags from it:
<div class="about-hero">
<h2><span class="accel"><?php echo strip_tags($excontent[0]) . " "; ?></span><?php echo $rebuild; ?> </h2>
</div>
Or removing just the trailing and leading <p> and </p>:
<div class="about-hero">
<h2><span class="accel"><?php echo substr(trim(substr(trim($excontent[0]), 3, strlen($excontent[0]))), 0, -4) . " "; ?></span><?php echo $rebuild; ?> </h2>
</div>
Your Browser will not "put" something into your HTML without any reason.
The first result of the Array is the place you should look at. You didn't provided your PHP Code, but im sure that result is where you find the <p> Tag ...
Just try this in JavaScript:
alert(<?PHP echo $excontent[0]; ?>);
I have successfully added a tab to my view.phtml page located at app/design/frontend/enterprise/aps/template/catalog/product.
I tried an if statement to hide it if the Specifications field is empty, i.e. no content. The issue is, it doesn't work. It still shows the tab even if there is no content.
My code is below at the end of post.
2 Questions:
Am I taking the correct approach? Basically, I am making a tab to have an Expert Review tab. I originally was going to use a cms block, but figured purposing the Specifications field was easier, for one, but also I could ignore the tab if no content
Can you please help ? :)
Thanks so much and here is my code and I attached a screenshot of the empty tabs.
<div class="wa-product-details-tab product-description">
<div class="wa-product-details-tab-heading product-desc-tab">
<div rel=".wa-product-tab-details-item-1" class="wa-product-heading-item wa-product-heading-item-1 wa-product-heading-item-active">
<span>Description</span>
</div>
<div rel=".wa-product-tab-details-item-2" class="wa-product-heading-item wa-product-heading-item-2">
<span>Specs</span>
</div>
<div rel=".wa-product-tab-details-item-3" id="review-form" class="wa-product-heading-item wa-product-heading-item-3">
<?php
$summaryData = Mage::getModel('review/review_summary')
->setStoreId(Mage::app()->getStore()->getId())
->load($_product->getId());
?>
<span >Reviews (<?php echo $summaryData->getReviewsCount();?>)</span>
</div>
<div rel=".wa-product-tab-details-item-4" class="wa-product-heading-item wa-product-heading-item-4">
<span>APS Advisor Review</span>
</div>
</div>
<div class="wa-product-tab-details product-desc">
<div style="display: block;" class="wa-product-tab-details-item wa-product-tab-details-item-1">
<?php echo $_product->getDescription(); ?>
</div>
<div style="display: none;" class="wa-product-tab-details-item wa-product-tab-details-item-2">
<p> <?php echo $this->getChildHtml('additional')?></p>
</div>
<div style="display: none;" class="wa-product-tab-details-item wa-product-tab-details-item-3">
<p>
<?php echo $this->getChildHtml('review_form') ?>
<?php echo $this->getChildHtml('product_additional_data_review') ?>
</p>
</div>
<div style="display: none;" class="wa-product-tab-details-item wa-product-tab-details-item-4">
<?php if ($_product->getSpecifications()); ?>
</div>
</div>
I am not sure if I understood your issue correctly. I am assuming that you want to hide the "APS Advisor Review" tab if there is no content in it.
For this you can use an if condition to check if $_product->getSpecifications() has any content, and show the tab title only if there is any content like this
<?php if( !empty($_product->getSpecifications()) ){ ?> <!-- displays the tab title only if the product has any specifications -->
<div rel=".wa-product-tab-details-item-4" class="wa-product-heading-item wa-product-heading-item-4">
<span>APS Advisor Review</span>
</div>
<php } ?>
Im created a custom block, with the below code, but im having some trouble turning the Group Title into an link, that will take the user back to the group at anytime.
Below is the code ive used, I thought active turns it into a link, but perhaps im being stupid.
<div class="active"><h2><?php print $group_title; ?></h2></div>
Below is the full code:
<?php $group_title = og_get_group_context()->title; ?>
<?php $group_nid = og_get_group_context()->nid; ?>
<?php $forum_link = og_forum_get_forum_container($group_nid); ?>
<div class="active"><h2><?php print $group_title; ?></h2></div>
<div class="content"
<div class="item-list">
<ul>
<li class="user-input-link"><a title="Add a new Forum topic"href="/node/add/forum?gids[]=<?php print $group_nid; ?>">Add a new forum topic</a>
</ul>
</div>
</div>
You need to create URL for it to work.
Here is the link to API with more info: http://api.drupal.org/api/drupal/includes--common.inc/function/l/6
<div class="active"><h2><?php print l($group_title, "node/{$group_nid}"); ?></h2></div>
You need to do an anchor tag, like:
<div><h2><?php print $group_title; ?></h2></div>
I don't know how to get the url in Drupal though..