Solved

PHP - Removing image from code and moving link to text link -- instead of image link

Posted on 2013-11-06
9
496 Views
Last Modified: 2013-11-10
Hello PHP experts!

I am trying to make a minor modification in some php code -- and I am not a php programmer.  

The php includes an image and below it some text with the name of the person in the image.  The image is currently clickable and the link takes the web visitor to a more detailed page about that person.  The name of the person is currently not clickable.

I need to completely remove the image, and make the html name of the person clickable instead.

I have a general idea of what needs to be done, but clearly there is some php formatting / syntax that I am not at all skilled in.

Here is a snippet of the php code that I want to modify.  If you need the complete page of php let me know.  Needless to say I have a complete backup of the page.  
<?php if($this->employee->icon && $this->employee->icon != 'nopic.png') echo '<a href="'.$employee_link.'"><img src="'.$this->employee_folder.$this->employee->icon . '" alt="' . $this->employee->name . '" /></a>'; ?>
        <h3><?php echo $this->employee->name; ?></h3>

Open in new window

Here is a link to the page, on my development site,  that this php is currently used in:  
Link to development page

I have some other html I need to add, but I think I will keep that for a second separate question.  Perhaps what I learn through this question will help me do the additional html myself.  But who knows!

Thanks

Rowby
0
Comment
Question by:Rowby Goren
9 Comments
 
LVL 35

Accepted Solution

by:
Kimputer earned 400 total points
ID: 39628861
this code should work:

<h3><?php echo '<a href="'.$employee_link.'">' . $this->employee->name . '" /></a>'; ?></h3>

Open in new window


Please note, it assumes the link ALWAYS exists. It could be the original code assumed the link always exists IF the image also exists. So you might need to update me on this piece of info.
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 39628911
HI Kimputer,

Thanks for helping!

I put the code in as follows.  Not quite working if you look at the page:
     <?php if($this->employee->icon && $this->employee->icon != 'nopic.png') echo '<a href="'.$employee_link.'"><img src="'.$this->employee_folder.$this->employee->icon . '" alt="' . $this->employee->name . '" /></a>'; ?>
        <h3><?php echo '<a href="'.$employee_link.'">' . $this->employee->name . '" /></a>';

Open in new window


Perhaps I need to remove the code preceding the code you gave me?

Again I can give you the entire page if needed.

ROwby
0
 
LVL 35

Expert Comment

by:Kimputer
ID: 39628930
No, my code was to replace your ENTIRE code, not just replace one line.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 100 total points
ID: 39628940
Hey, Rowby... Try it this way.  This is constructively the same as Kimputer's comment -- an entire replacement for the two lines of original code.

<?php 
echo '<h3>'
. '<a href="' 
. $employee_link 
. '">' 
. $this->employee->name 
. '</a>'
. '</h3>' 
. PHP_EOL;
?>

Open in new window

HTH, ~Ray
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 39628948
Fyi here is the entire current page
<?php
/**
 * @version 3.0 2013-06-11
 * @package Joomla
 * @subpackage Work Force
 * @copyright (C) 2013 the Thinkery
 * @license GNU/GPL see LICENSE.php
 */

defined( '_JEXEC' ) or die( 'Restricted access' );
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers');

$employee_link      = JRoute::_(WorkforceHelperRoute::getEmployeeRoute($this->employee->id, $this->employee->department));
$department_name    = (JRequest::getVar('view') == 'allemployees') ? workforceHTML::getDepartmentName($this->employee->department).' - ' : '';

//check length of bio - decide whether or not to create snippet and read more link
$wflen     = $this->params->get('overview_char',250);
$biolen    = strlen($this->employee->bio);
$readmore  = ($biolen > $wflen) ? true : false;

switch($this->params->get('employee_columns', 2))
{
    case '1':
    default:
        $span = 12;
        break;
    case '2':
        $span = 6;
        break;
    case '3': 
        $span = 4;
        break;
    case '4':
        $span = 3;
        break;
}
?>

<li class="span<?php echo $span; ?>">
    <div class="thumbnail">
        <?php if($this->employee->icon && $this->employee->icon != 'nopic.png') echo '<a href="'.$employee_link.'"><img src="'.$this->employee_folder.$this->employee->icon . '" alt="' . $this->employee->name . '" /></a>'; ?>
        <h3><?php echo $this->employee->name; ?></h3>
        <p class="wf-dep-position-holder"><?php echo $department_name; ?><span class="wf-employee-position"><?php echo $this->employee->position; ?></span></p>
        <div class="wf-icon-holder btn-toolbar">
            <div class="btn-group">
                <?php
                if($this->employee->website):
                    // make sure URL has scheme
                    $website    = JURI::getInstance( $this->employee->website );
                    if (!$website->getScheme()) $website = 'http://' . $this->employee->website;
                    $web_icon   = JHtml::_('image','components/com_workforce/assets/images/web.png', JText::_('COM_WORKFORCE_WEBSITE'));
                    echo '<a class="btn btn-mini hasTip" href="'.$website.'" target="_blank" title="'.JText::_('COM_WORKFORCE_WEBSITE').'::'.JText::_('COM_WORKFORCE_VISIT_WEBSITE').'">'.$web_icon.'</a>';
                endif;
                if($this->employee->availability):
                    $emp_avail      = $this->employee->availability;
                    $adisplay       = str_replace(';','<br />',$emp_avail);
                    $calendar_icon  = JHtml::_('image','components/com_workforce/assets/images/calendar.png', JText::_('COM_WORKFORCE_AVAILABILITY'));
                    echo '<a class="btn btn-mini hasTip" title="'.JText::_('COM_WORKFORCE_AVAILABILITY').'::'.$adisplay.'" href="javascript:void(0)">'.$calendar_icon.'</a>';
                endif;
                if($this->params->get('show_vcard', '')):
                    $vcard_icon = JHtml::_('image','components/com_workforce/assets/images/vcard.png', JText::_('COM_WORKFORCE_VCARD'));
                    echo '<a class="btn btn-mini hasTip" href="'.JRoute::_('index.php?option=com_workforce&task=employee.vcard&employee_id='.(int)$this->employee->id.'&format=raw').'" target="_blank" title="'.JText::_('COM_WORKFORCE_VCARD').'::'.JText::_('COM_WORKFORCE_DOWNLOAD_VCARD').'">'.$vcard_icon.'</a>';
                endif;
                if($this->params->get('show_map') && $this->employee->street && $this->employee->street != ' '):
                    // create map address
                    $mapaddress     = $this->employee->street.' ';
                    $mapaddress    .= $this->employee->city ? $this->employee->city . ', ' : '';
                    $mapaddress    .= $this->employee->locstate ? workforceHTML::getStateName($this->employee->locstate) . ' ' : '';
                    $mapaddress    .= $this->employee->province ? $this->employee->province . ' ' : '';
                    $mapaddress    .= $this->employee->postcode ? $this->employee->postcode : '';
                    $mapaddress    .= $this->employee->country ? ' ' . workforceHTML::getCountryName($this->employee->country) : '';
                    $mapaddress		= urlencode($mapaddress);

                    $map_icon = JHtml::_('image','components/com_workforce/assets/images/map.png', JText::_('COM_WORKFORCE_SHOW_MAP'));
                    echo '<a class="btn btn-mini hasTip" title="'.JText::_('COM_WORKFORCE_SHOW_MAP').'::'.htmlentities('<img src="http://maps.googleapis.com/maps/api/staticmap?markers='.$mapaddress.'&zoom=14&size=200x200&maptype=roadmap&sensor=false" />').'" href="javascript:void(0)">'.$map_icon.'</a>';                    
                endif;
                if(($this->params->get('allow_edit', '') && (!$this->user->guest && ($this->user->get('id') == $this->employee->user_id))) || $this->user->authorise('core.admin', 'com_workforce')):
                    $edit = JHtml::_('icon.edit', $this->employee);
                    echo '<a class="btn btn-mini hasTip" href="'.$edit['link'].'" title="'.JText::_('JGLOBAL_EDIT').'::'.$edit['tooltip'].'">'.$edit['image'].'</a>';
                endif;
                ?>
            </div>
            <div class="btn-group">
                <?php
                if ($this->employee->twitter && $this->params->get('show_twitter', false)):
                    $twitter_icon = JHtml::_('image','components/com_workforce/assets/images/twitter.png',JText::_('COM_WORKFORCE_TWITTER'));
                    echo '<a class="btn btn-mini hasTip" title="'.JText::_('COM_WORKFORCE_TWITTER').'" href="'.workforceHTML::getUrl($this->employee->twitter).'" target="_blank">'.$twitter_icon.'</a>';
                endif;
                if ($this->employee->facebook && $this->params->get('show_facebook', false)):
                    $facebook_icon = JHtml::_('image','components/com_workforce/assets/images/facebook.png',JText::_('COM_WORKFORCE_FACEBOOK'));
                    echo '<a class="btn btn-mini hasTip" title="'.JText::_('COM_WORKFORCE_FACEBOOK').'" href="'.workforceHTML::getUrl($this->employee->facebook).'" target="_blank">'.$facebook_icon.'</a>';
                endif;
                if ($this->employee->youtube && $this->params->get('show_youtube', false)):
                    $youtube_icon = JHtml::_('image','components/com_workforce/assets/images/youtube.png',JText::_('COM_WORKFORCE_YOUTUBE'));
                    echo '<a class="btn btn-mini hasTip" title="'.JText::_('COM_WORKFORCE_YOUTUBE').'" href="'.workforceHTML::getUrl($this->employee->youtube).'" target="_blank">'.$youtube_icon.'</a>';
                endif;
                if ($this->employee->linkedin && $this->params->get('show_linkedin', false)):
                    $linkedin_icon = JHtml::_('image','components/com_workforce/assets/images/linkedin.png',JText::_('COM_WORKFORCE_LINKEDIN'));
                    echo '<a class="btn btn-mini hasTip" title="'.JText::_('COM_WORKFORCE_LINKEDIN').'" href="'.workforceHTML::getUrl($this->employee->linkedin).'" target="_blank">'.$linkedin_icon.'</a>';
                endif;                
                ?>
            </div>
        </div>        
        <?php
        if($this->params->get('show_overview_contact', 1)):
            echo '<div class="wf-employee-contact-holder">';
                if($this->employee->email && $this->params->get('show_employee_email', 1)):                
                    echo '<div class="wf-contact-item"><abbr title="'.JText::_('COM_WORKFORCE_EMAIL').'">E:</abbr> '.JHTML::_('email.cloak', $this->employee->email).'</div>';
                endif;
                if($this->employee->phone1):
                    $ext1 = ($this->employee->ext1) ? ' '.JText::_('COM_WORKFORCE_EXT').':'.$this->employee->ext1 : '';
                    echo '<div class="wf-contact-item"><abbr title="'.JText::_('COM_WORKFORCE_PHONE1').'">P:</abbr> '.$this->employee->phone1.$ext1.'</div>';
                endif;
                if($this->employee->phone2):
                    $ext2 = ($this->employee->ext2) ? ' '.JText::_('COM_WORKFORCE_EXT').':'.$this->employee->ext2 : '';
                    echo '<div class="wf-contact-item"><abbr title="'.JText::_('COM_WORKFORCE_PHONE2').'">P2:</abbr> '.$this->employee->phone2.$ext2.'</div>';
                endif;
                if($this->employee->fax):
                    echo '<div class="wf-contact-item"><abbr title="'.JText::_('COM_WORKFORCE_FAX').'">F:</abbr> '.$this->employee->fax.'</div>';
                endif;
            echo '</div>';
        endif;
        if($this->employee->bio && $this->params->get('overview_char') >= 1):
            echo '<hr />';
            if($this->params->get('full_bio', false) || $readmore == false): //show full bio with no stripped tags
                echo '<p class="wf-employee-overview">'.$this->employee->bio.'</p>';
            else: //show snippet of bio with stripped tags
                echo '<p class="wf-employee-overview">'.workforceHTML::snippet($this->employee->bio, $wflen).'</p>';                
            endif;
            echo '<a class="btn btn-info readon" href="'.$employee_link.'">'.JText::_('COM_WORKFORCE_VIEW_BIO').'</a>';
        endif;
        ?>
        <?php $this->dispatcher->trigger( 'onAfterRenderEmployeeOverview', array( &$this->employee, &$this->params, &$this->user )); ?>
    </div>
</li>

Open in new window

0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 39629095
THanks : KimputerP and Ray,

Works fine now.

I will award the points tomorrow.  I think Ray would not mind giving the points to : KimputerP since his version worked too.  Was my error not doing entire replacement.

I may have a couple other questions. But for now my brain needs a rest.

So will resume tomorrow.  ANd either close the question and open a new one for some other formatting issues on this page.

Thanks

Rowby
0
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 39629099
Replace lines 41 and 42 of the code you've just posted with this:

<?php printf("<h3><a href='%s'>%s</a></h3>", $employee_link, $this->employee->name); ?>

Open in new window


FYI - the code you've posted doesn't seem to resemble the page you've linked to!
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 39630531
Replacement code working fine.

I will be wanting to add some additional fields and possible rearrange the page but that will be in a new question I will post later today or tomorrow.

I am going to give most of the points to Kimputer since I didn't properly copy them into my code, but give a few points to Ray.  

And thanks  ChrisStanyon  too!

I will hold off awarding the points for about an hour when I return to my computer.

Thanks!

Rowby
0
 
LVL 9

Author Closing Comment

by:Rowby Goren
ID: 39637704
THANKS!

It's working, now of course!

Rowby
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question