open link with target="_blank" can´t fix it - php

i would like to change a link to target="_blank" (opening in a new window, or tab) but can#t fix it. i´m a fool in php and my try&error-method did´t work. can anybody help me?
Thank you so much!
original code from the parallax one theme (wordpress)
<?php
if(!empty($parallax_one_contact_info_item_decoded)){
foreach($parallax_one_contact_info_item_decoded as $parallax_one_contact_item){
if(!empty($parallax_one_contact_item->link)){
echo '<div class="col-sm-4 contact-link-box col-xs-12">';
if(!empty($parallax_one_contact_item->icon_value)){
echo '<div class="icon-container"><span class="'.esc_attr($parallax_one_contact_item->icon_value).' colored-text"></span></div>';
}
if(!empty($parallax_one_contact_item->text)){
echo ''.$parallax_one_contact_item->text.' ';
}
echo '</div>';
} else {
echo '<div class="col-sm-4 contact-link-box col-xs-12">';
if(!empty($parallax_one_contact_item->icon_value)){
echo '<div class="icon-container"><span class="'.esc_attr($parallax_one_contact_item->icon_value).' colored-text"></span></div>';
}
if(!empty($parallax_one_contact_item->text)){
if(function_exists('icl_translate')){
echo ''.icl_translate('Contact',$parallax_one_contact_item->id.'_contact',esc_attr($parallax_one_contact_item->text)).'';
} else {
echo ''.esc_attr($parallax_one_contact_item->text).'';
}
}
echo '</div>';
}
}
}
?>

Simply add target="_blank" in your anchor tag. For example :
echo '<a target="_blank" href="'.$parallax_one_contact_item->link.'" class="strong">'.$parallax_one_contact_item->text.' </a>';

Try this:
<?php
if(!empty($parallax_one_contact_info_item_decoded)){
foreach($parallax_one_contact_info_item_decoded as $parallax_one_contact_item){
if(!empty($parallax_one_contact_item->link)){
echo '<div class="col-sm-4 contact-link-box col-xs-12">';
if(!empty($parallax_one_contact_item->icon_value)){
echo '<div class="icon-container"><span class="'.esc_attr($parallax_one_contact_item->icon_value).' colored-text"></span></div>';
}
if(!empty($parallax_one_contact_item->text)){
echo '<a target="_blank" href="'.$parallax_one_contact_item->link.'" class="strong">'.$parallax_one_contact_item->text.' </a>';
}
echo '</div>';
} else {
echo '<div class="col-sm-4 contact-link-box col-xs-12">';
if(!empty($parallax_one_contact_item->icon_value)){
echo '<div class="icon-container"><span class="'.esc_attr($parallax_one_contact_item->icon_value).' colored-text"></span></div>';
}
if(!empty($parallax_one_contact_item->text)){
if(function_exists('icl_translate')){
echo '<a target="_blank" href="" class="strong">'.icl_translate('Contact',$parallax_one_contact_item->id.'_contact',esc_attr($parallax_one_contact_item->text)).'</a>';
} else {
echo '<a target="_blank" href="" class="strong">'.esc_attr($parallax_one_contact_item->text).'</a>';
}
}
echo '</div>';
}
}
}
?>
Note: Added target="_blank" in each hyperlink.

Related

Web Server Says The Page Isn't Working And Won't Load Page

This is the entirety of the code that I have on this page. I've linked to the server connection, which works. Can't figure out what's wrong. Some input would be appreciated.
<?php
session_start();
require_once("account-management/db_connect.php");
if (isset($_SESSION['user_lister_id']) && ($_SESSION['email'])) {
echo '<section class="topnavbar">';
echo '<div id="top-login">';
echo 'Listing Profile / Account Settings / Case Requests';
echo '</div>';
echo '</section>';
} else {
echo '<section class="topnavbar">';
echo '<div id="top-register">';
echo 'Client Register / Lister Register';
echo '</div>';
echo '<div id="top-login">';
echo 'Client Login / Lister Login';
echo '</div>';
echo '</section>';
}
?>
<section class="header-grid">
<img src="../images/Logo.png" width="120" />
<div id="ad-field">This content coming soon!</div>
</section>

Check box is toggled when I click on any text

I am dynamically creating the checkbox input fields with text lables, and trying to create a treeview when I click any item in the tree the first check box is always toggling.What can be the possible reason.
if($category->visible==1){
echo '<div class="categorylist level'.$depth.' cat">';
$count=$DB->count_records('course',['category'=>$category->id]);
if($count>0){
echo '<div class="parent">';
if($depth>0){
$indent=10;
for($i=0;$i<=$depth;$i++){
$indent=$indent+$depth;
echo '<div style="margin-left:'.$indent.'px">';
}
}
echo '<input type="checkbox" id="category" name="cat[]" value='.$category->id.'/>';
echo '<label for="category"'.$category->id.'"><span class="">'.$category->name.' ('.$count.')</span></label><br>';
if($depth>0){
for($i=0;$i<=$depth;$i++){
echo '</div>';
}
}
echo '</div>';
}
else{
echo '<div class="parent">';
if($depth>0){
$indent=10;
for($i=0;$i<=$depth;$i++){
$indent=$indent+$depth;
echo '<div style="margin-left:'.$indent.'px">';
}
}
echo '<label for="category"><span class="">'.$category->name.' ('.$count.')</span></label><br>';
if($depth>0){
for($i=0;$i<=$depth;$i++){
echo '</div>';
}
}
echo '</div>';
}
echo '</div>';
}
Just checked this <label for="category"'.$category->id.'"> could be your issue, label with duplicate for attribute can cause this issue, make sure that you have no label with same $category->id

Problem after converting my HTML site to PHP ( echo ''; echo ''; everywhere)

I tried to convert my static html site pages with an online HTML to PHP converter. I changed all my extensions to .php and also the links. You can see the result of the conversion below. I run it with wamp but some stuff (images, css, text) of the page is shown in the browser, but most of the stuff is not, and instead I see
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '';
echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo
''; echo '
everywhere.
What am I doing wrong?
<? php
echo '<!DOCTYPE html>';
echo '<html lang="en">';
echo '<head>';
echo '<meta charset="utf-8">';
echo '<meta http-equiv="X-UA-Compatible" content="IE=edge">';
echo '<meta name="viewport" content="width=device-width, initial-scale=1">';
echo '<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->';
echo '<title>Title</title>';
echo '<!-- Bootstrap -->';
echo '<link href="css/bootstrap.min.css" rel="stylesheet">';
echo '<link rel="stylesheet" type="text/css" href="css/style.css">';
echo '<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->';
echo '<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->';
echo '<!--[if lt IE 9]>';
echo '<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>';
echo '<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>';
echo '<![endif]-->';
echo '</head>';
echo '<body>';
echo '<nav class="navbar navbar-default">';
echo '<div class="container">';
echo '<!-- Brand and toggle get grouped for better mobile display -->';
echo '<div class="navbar-header">';
echo '<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">';
echo '<span class="sr-only">Toggle navigation</span>';
echo '<span class="icon-bar"></span>';
echo '<span class="icon-bar"></span>';
echo '<span class="icon-bar"></span>';
echo '</button>';
echo '<a class="navbar-brand" href="index.php"><img src="images/logo.png" class="img-responsive" width="150px"></a>';
echo '</div>';
echo '<!-- Collect the nav links, forms, and other content for toggling -->';
echo '<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">';
echo '<ul class="nav navbar-nav navbar-right">';
echo '<li class="active">HOME <span class="sr-only">(current)</span></li>';
echo '<li class="dropdown">';
echo 'text <span class="caret"></span>';
echo '<ul class="dropdown-menu">';
echo '<li>some link</li>';
echo '<li role="separator" class="divider"></li>';
echo '<li>something</li>';
echo '<li role="separator" class="divider"></li>';
echo '<li>something else</li>';
echo '</ul>';
echo '</li>';
echo '<li class="dropdown">';
echo 'something<span class="caret"></span>';
echo '<ul class="dropdown-menu">';
echo '<li>something</li>';
echo '<li role="separator" class="divider"></li>';
echo '<li>some link</li>';
echo '<li role="separator" class="divider"></li>';
echo '<li></> something</li>';
echo '<li role="separator" class="divider"></li>';
echo '<li></>something</li>';
echo '</ul>';
echo '</li>';
echo '<li class="dropdown">something<span class="caret"></span>';
echo '<ul class="dropdown-menu">';
echo '<li>something</li>';
echo '<li role="separator" class="divider"></li>';
echo '<li>something</li>';
echo '<li role="separator" class="divider"></li>';
echo '<li></>something</li>';
echo '<li role="separator" class="divider"></li>';
echo '<li></>something</li>';
echo '</ul>';
echo '</li>';
echo '</ul>';
echo '</div><!-- /.navbar-collapse -->';
echo '</div><!-- /.container-->';
echo '</nav>';
echo '<!-- Carousal -->';
echo '<section class="jk-slider">';
echo '<div id="carousel-example" class="carousel slide" data-ride="carousel">';
echo '<ol class="carousel-indicators">';
echo '<li data-target="#carousel-example" data-slide-to="0" class="active"></li>';
echo '<li data-target="#carousel-example" data-slide-to="1"></li>';
echo '<li data-target="#carousel-example" data-slide-to="2"></li>';
echo '</ol>';
echo '<div class="carousel-inner">';
echo '<div class="item active">';
echo '<div class="hero">';
echo '<hgroup>';
echo '<p>something</p>';
echo '</hgroup>';
echo '</div>';
echo '<div class="overlay"></div>';
echo '<img src="images/1.jpg" class="img-responsive" width="100%">';
echo '</div>';
echo '<div class="item">';
echo '<div class="hero">';
echo '<hgroup>';
echo '<p>something</p>';
echo '</hgroup>';
echo '</div>';
echo '<div class="overlay"></div>';
echo '<img src="images/2.jpg" class="img-responsive" width="100%">';
echo '</div>';
echo '<div class="item">';
echo '<div class="hero">';
echo '<hgroup>';
echo '<p>something</p>';
echo '</hgroup>';
echo '</div>';
echo '<div class="overlay"></div>';
echo '<img src="images/3.jpg" />';
echo '</div>';
echo '</div>';
echo '<a class="left carousel-control" href="#carousel-example" data-slide="prev">';
echo '<span class="glyphicon glyphicon-chevron-left"></span>';
echo '</a>';
echo '<a class="right carousel-control" href="#carousel-example" data-slide="next">';
echo '<span class="glyphicon glyphicon-chevron-right"></span>';
echo '</a>';
echo '</div>';
echo '</section>';
echo '<!-- End Of carousal -->';
echo '<section>';
echo '<div class="container">';
echo '<div class="row">';
echo '<div class="col-md-12">';
echo ' ';
echo '</div>';
echo '</div>';
echo '</div>';
echo '</section>';
echo '<script src="../../ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>';
echo '<!-- Include all compiled plugins (below), or include individual files as needed -->';
echo '<script src="js/bootstrap.min.js"></script>';
echo '<script type="text/javascript">';
echo '<script type="text/javascript">';
echo '$('.count').each(function () {';
echo '$(this).prop('Counter',0).animate({';
echo 'Counter: $(this).text()';
echo '}, {';
echo 'duration: 5000,';
echo 'easing: 'swing',';
echo 'step: function (now) {';
echo '$(this).text(Math.ceil(now));';
echo '}';
echo '});';
echo '});';
echo '</script>';
echo '</script>';
echo '</body>';
echo '</html>';
?>
Do you really need to make everything in echo? You can just simply put in normal html tag. And put <?php ?> wherever you need PHP code.
Regarding your JS, you are calling <script type='text/javascript'></script> twice.

Wordpress Ordering (boolean?)

Hi I would like to order custom fields in wordpress. I've got it displaying the single project. But can't figure out how I can get it to display in order. I've created a field called project_order which works correctly on another page.
But i'm not used to this sort of php with order by. This is a project designed by someone else so i'm trying to pick up and learn how it was built.
<?php
//associate sector to product projects page
$sector['construction'] = 131;
$sector['timber-frame'] = 235;
$sector['industrial'] = 253;
$sector['agriculture'] = 263;
//link to view all projects for product
echo '<p>View all projects</p>';
?>
</div>
<div class="span5">
<div id="latestproject">
<h2>Latest Project</h2>
<?php
//get latest projects
$rows = get_field('projects', $sector [$post->post_name] , '&order=ASC');
//display latest project
if ($rows) {
echo '<div class="row">';
if ($rows[0]['project_pageturner']) {
echo '<a href="'.$rows[0]['project_pageturner'].'" target="_blank">';
} else if ($rows[0]['project_pdf']) {
echo '<a href="'.wp_get_attachment_url($rows[0]['project_pdf']).'" target="_blank">';
} else {
echo "<a href=\"javascript:alert('No PDF uploaded for this item.')\">";
}
echo '<div class="span2">';
if ($rows[0]['project_thumbnail']) {
echo wp_get_attachment_image($rows[0]['project_thumbnail'], 'full');
} else {
echo '<img src="'.get_bloginfo('template_directory').'/images/defaultproject.jpg" alt="">';
}
echo '</div>';
echo '<div class="span3">';
echo '<p><strong>'.$rows[0]['project_title'].'</strong></p>';
echo '<p>View project »</p>';
echo '</div>';
echo '</a>';
echo '</div><!--row-->';
} else {
echo '<p>No projects to display currently.</p>';
}
?>
I'm guessing it will have something to do with.
$rows = get_field('projects', $sector [$post->post_name]);
Try below code, may be this resolve your problem.
<?php
wp_reset_query();
//associate sector to product projects page
$sector['construction'] = 131;
$sector['timber-frame'] = 235;
$sector['industrial'] = 253;
$sector['agriculture'] = 263;
//link to view all projects for product
echo '<p>View all projects</p>';
?>
</div>
<div class="span5">
<div id="latestproject">
<h2>Latest Project</h2>
<?php
//get latest projects
$rows = get_field('projects', $sector [$post->post_name] , '&order=ASC');
//display latest project
if ($rows) {
echo '<div class="row">';
if ($rows[0]['project_pageturner']) {
echo '<a href="'.$rows[0]['project_pageturner'].'" target="_blank">';
} else if ($rows[0]['project_pdf']) {
echo '<a href="'.wp_get_attachment_url($rows[0]['project_pdf']).'" target="_blank">';
} else {
echo "<a href=\"javascript:alert('No PDF uploaded for this item.')\">";
}
echo '<div class="span2">';
if ($rows[0]['project_thumbnail']) {
echo wp_get_attachment_image($rows[0]['project_thumbnail'], 'full');
} else {
echo '<img src="'.get_bloginfo('template_directory').'/images/defaultproject.jpg" alt="">';
}
echo '</div>';
echo '<div class="span3">';
echo '<p><strong>'.$rows[0]['project_title'].'</strong></p>';
echo '<p>View project »</p>';
echo '</div>';
echo '</a>';
echo '</div><!--row-->';
} else {
echo '<p>No projects to display currently.</p>';
}
wp_reset_query();
?>
Thanks.

Multiple divs with a repeater field of image

i´m trying to display multiple divs with the images of a repeater field (ACF plugins).
For example Div 1 with image 1 - Div 2 with image 2 - etc...
with this markup:
<div id="project" class="item">
<a href="#">
<img src="img/project1.jpg" alt="project1" width="240" height="173">
</a>
<div class="art_title">
<p>SWEET LIFE #1</p>
</div>
<div class="mask"></div>
</div>
So, repeating it thru the html I displayed all the images, but now i´m integratin it in the wordpress and I have the following problem:
I´m using the repeater field to get all the images, so with this code:
<?php $slides = get_field('project_thumbnails');
// Grabs the array
// Check if there is any data in the array before looping
if($slides) {
//we need to close this div
echo '<div id="project_slider" class="item">';
foreach($slides as $s) {
echo '<div class="aimagediv" >'; //adding the start tag of the div
echo '<a href="#">';
echo '<img src="'.$s['project_thumb'].'" alt="" />';
echo '</a>';
echo '</div>'; //CLOSING THE DIV JUST ADDED
}
echo '<div class="art_title">';
echo '<p>SWEET LIFE2</p>';
echo '</div>';
echo '<div class="mask">';
echo '</div>';
echo '</div>'; //closing the first div,not sure if you want this, its optional
}
?> <?php endwhile; // end of the loop. ?>
I get the images of the repeater but it displays all into the same div, it doesn´t create a new div id=¨project". So it shows like this:
And the markup created on the page it´s like all the images are into the same div.
<div id="project" class="item">
<a href="#">
<img src="img/project1.jpg" alt="project1" width="240" height="173">
<img src="img/project1.jpg" alt="project1" width="240" height="173">
</a>
<div class="art_title">
<p>SWEET LIFE #1</p>
</div>
<div class="mask"></div>
</div>
What i´m doing wrong?
<?php $slides = get_field('project_thumbnails');
// Grabs the array
// Check if there is any data in the array before looping
if($slides) {
//we need to close this div
foreach($slides as $s) {
echo '<div id="project_slider" class="item">';
echo '<div class="aimagediv" >'; //adding the start tag of the div
echo '<a href="#">';
echo '<img src="'.$s['project_thumb'].'" alt="" />';
echo '</a>';
echo '</div>'; //CLOSING THE DIV JUST ADDED
echo '<div class="art_title">';
echo '<p>SWEET LIFE2</p>';
echo '</div>';
echo '<div class="mask">';
echo '</div>';
echo '</div>'; //closing the first div,not sure if you want this, its optional
}
}
?> <?php endwhile; // end of the loop. ?>

Categories