Solved

php one line if else

Posted on 2013-06-22
15
539 Views
Last Modified: 2013-06-22
	<a href="<?php if(the_title() == 'Hormone Therapy') ? echo 'hormones' : echo '#'; ?>" title="<?php the_title(); ?>">

Open in new window


What does this line get an error?
0
Comment
Question by:poweraddict
  • 5
  • 3
  • 3
  • +2
15 Comments
 
LVL 3

Expert Comment

by:SamGarner
ID: 39268774
Check out your '?'
0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 39268779
The thing to the left of the ? *is* the if--you don't need the keyword "if" at that point.

<a href="<?php (the_title() == 'Hormone Therapy') ? echo 'hormones' : echo '#'; ?>" title="<?php the_title(); ?>">

Open in new window

0
 
LVL 15

Assisted Solution

by:Jagadishwor Dulal
Jagadishwor Dulal earned 166 total points
ID: 39268780
Try this one
<a href="<?php $title=(the_title() == 'Hormone Therapy') ?  'hormones' : '#'; ?>" title="<?php echo $title; ?>">

Open in new window

0
 
LVL 6

Author Comment

by:poweraddict
ID: 39268794
those don't work...
0
 
LVL 3

Expert Comment

by:SamGarner
ID: 39268797
whats the previous line?
0
 
LVL 3

Expert Comment

by:SamGarner
ID: 39268799
just realised thats a stupid question, forget i said that im half asleep :/
0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 39268806
Try moving the echo call out:

<a href="<?php echo (the_title() == 'Hormone Therapy') ? 'hormones' : '#'; ?>" title="<?php echo the_title(); ?>">

Open in new window

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 6

Author Comment

by:poweraddict
ID: 39268807
still not working, here is the results of that:

<a class="nivo-imageLink" title="Nutrition Counseling" href="Nutrition Counseling#" style="display: block;">
<a class="nivo-imageLink" title="Hormone Therapy" href="Hormone Therapy#" style="display: none;">
<a class="nivo-imageLink" title="Botox" href="Botox#" style="display: none;">
0
 
LVL 6

Author Comment

by:poweraddict
ID: 39268808
it should be:

<a class="nivo-imageLink" title="Nutrition Counseling" href="#" style="display: block;">
<a class="nivo-imageLink" title="Hormone Therapy" href="hormones" style="display: none;">
<a class="nivo-imageLink" title="Botox" href="#" style="display: none;">

Open in new window

0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 39268821
Are you sure this code is the one running? The current result you mention isn't showing the anchor's attributes in the order you have defined them. In other words, your code is showing that the href should come before the title, but your example output shows the reverse.
0
 
LVL 15

Assisted Solution

by:Jagadishwor Dulal
Jagadishwor Dulal earned 166 total points
ID: 39268829
What did your function return? it must work I have tested using a test function:
<?php
function the_title(){
	$title='';// Change value of Function To Hormone Therapy next time and hover on link you will see the title changed
	return $title;
}
?>

Open in new window

<a class="nivo-imageLink" href="<?php $title=(the_title() == 'Hormone Therapy') ?  'hormones' : '#'; ?>" title="<?php echo $title; ?>" style="display: block;">Nutrition Counseling</a>
<a class="nivo-imageLink" href="<?php $title=(the_title() == 'Hormone Therapy') ?  'hormones' : '#'; ?>" title="<?php echo $title; ?>" style="display: block;">Hormone Therapy</a>
<a class="nivo-imageLink" href="<?php $title=(the_title() == 'Hormone Therapy') ?  'hormones' : '#'; ?>" title="<?php echo $title; ?>" style="display: block;">Botox</a>

Open in new window


I have changed your display:none to block
0
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 39268837
Check it Your self..
0
 
LVL 6

Author Comment

by:poweraddict
ID: 39268843
Yeah I'm trying to modify a wordpress plugin.

Look on line 433 and you'll see my code.

I'm not a php developer...but I understand it alright.

<?php

/*

Plugin Name: WP Nivo Slider

Plugin URI: http://www.nerdhead.com.br/en/wp-nivo-slider-en/

Description: Creates a slider using js created by Gilbert Pellegrom. WordPress plugin develop by Rafael Cirolini

Version: 2.0

Author: Rafael Cirolini

Author URI: http://www.nerdhead.com.br/

License: GPL2

*/



/*  Copyright 2010  WP Nivo Slider - Rafael Cirolini  (email : rafael@nerdhead.com.br)

 

    This program is free software; you can redistribute it and/or modify

    it under the terms of the GNU General Public License, version 2, as

    published by the Free Software Foundation.

 

    This program is distributed in the hope that it will be useful,

    but WITHOUT ANY WARRANTY; without even the implied warranty of

    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

    GNU General Public License for more details.

 

    You should have received a copy of the GNU General Public License

    along with this program; if not, write to the Free Software

    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/



add_action('admin_menu', 'wpns_add_menu');

add_action('admin_init', 'wpns_reg_function' );



register_activation_hook( __FILE__, 'wpns_activate' );



add_theme_support('post-thumbnails');



function wpns_add_menu() {

    $page = add_options_page('WP Nivo Slider', 'WP Nivo Slider', 'administrator', 'wpns_menu', 'wpns_menu_function');

}



function wpns_reg_function() {

	register_setting( 'wpns-settings-group', 'wpns_category' );

	register_setting( 'wpns-settings-group', 'wpns_effect' );

	register_setting( 'wpns-settings-group', 'wpns_slices' );

	register_setting( 'wpns-settings-group', 'wpns_width' );

	register_setting( 'wpns-settings-group', 'wpns_height' );

}



function wpns_activate() {

	add_option('wpns_category','1');

	add_option('wpns_effect','random');

	add_option('wpns_slices','5');	

}



wp_enqueue_script('nivo_slider', WP_PLUGIN_URL . '/wp-nivo-slider/js/jquery.nivo.slider.pack.js', array('jquery'), '2.3' );



function show_nivo_slider() {

?>



<style type="text/css">

#slider {

/*	-moz-box-shadow:0 0 10px #333333; */

	background:url("<?php echo WP_PLUGIN_URL . "/wp-nivo-slider/"; ?>images/loading.gif") no-repeat scroll 50% 50% transparent;

	width:<?php echo get_option('wpns_width'); ?>px; /* Change this to your images width */

    height:<?php echo get_option('wpns_height'); ?>px; /* Change this to your images height */
	
	margin-bottom: 50px;

}

#slider img {

	position:absolute;

	top:0px;

	left:0px;

	display:none;

}

#slider a {

	border:0 none;

	display:block;

}

/* The Nivo Slider styles */

.nivoSlider {

	position:relative;

}

.nivoSlider img {

	position:absolute;

	top:0px;

	left:0px;

}

/* If an image is wrapped in a link */

.nivoSlider a.nivo-imageLink {

	position:absolute;

	top:0px;

	left:0px;

	width:100%;

	height:100%;

	border:0;

	padding:0;

	margin:0;

	z-index:60;

	display:none;

}

/* The slices in the Slider */

.nivo-slice {

	display:block;

	position:absolute;

	z-index:50;

	height:100%;

}

/* Caption styles */

.nivo-caption {

	position:absolute;

	left:0px;

	bottom:0px;

	background:#000;

	color:#fff;

	opacity:0.1; /* Overridden by captionOpacity setting */

	width:100%;

	z-index:89;

}

.nivo-caption p {

	padding:5px;

	margin:0;

}

.nivo-caption a {

	display:inline !important;

}

.nivo-html-caption {

    display:none;

}

/* Direction nav styles (e.g. Next & Prev) */

.nivo-directionNav a {

	position:absolute;

	top:45%;

	z-index:99;

	cursor:pointer;

}

.nivo-prevNav {

	left:0px;

}

.nivo-nextNav {

	right:0px;

}

.nivo-controlNav {

	bottom:-30px;	

	left:47%;

	position:absolute;

}

.nivo-controlNav a {

	background:url("<?php echo WP_PLUGIN_URL . "/wp-nivo-slider/"; ?>images/bullets.png") no-repeat scroll 0 0 transparent;

	border:0 none;

	display:block;

	float:left;

	height:10px;

	margin-right:3px;

	text-indent:-9999px;

	width:10px;

}

.nivo-controlNav a.active {

	background-position:-10px 0;

}

.nivo-controlNav a {

	cursor:pointer;

	position:relative;

	z-index:99;

}

.nivo-controlNav a.active {

	font-weight:bold;

}

.nivo-directionNav a {

	background:url("<?php echo WP_PLUGIN_URL . "/wp-nivo-slider/"; ?>images/arrows.png") no-repeat scroll 0 0 transparent;

	border:0 none;

	display:block;

	height:34px;

	text-indent:-9999px;

	width:32px;

}

a.nivo-nextNav {

	background-position:-32px 0;

	right:10px;

}

a.nivo-prevNav {

	left:10px;

}

</style>



<script type="text/javascript">

jQuery(window).load(function() {

	jQuery('#slider').nivoSlider({

		effect:'<?php echo get_option('wpns_effect'); ?>',

		slices:<?php echo get_option('wpns_slices'); ?>,

		animSpeed:500, //Slide transition speed

        pauseTime:9000,

        startSlide:0, //Set starting Slide (0 index)

        directionNav:true, //Next & Prev

        directionNavHide:true, //Only show on hover

        controlNav:true, //1,2,3...

        controlNavThumbs:false, //Use thumbnails for Control Nav

        controlNavThumbsFromRel:false, //Use image rel for thumbs

        controlNavThumbsSearch: '.jpg', //Replace this with...

        controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src

        keyboardNav:true, //Use left & right arrows

        pauseOnHover:true, //Stop animation while hovering

        manualAdvance:false, //Force manual transitions

        captionOpacity:0, //Universal caption opacity

        beforeChange: function(){},

        afterChange: function(){},

        slideshowEnd: function(){}, //Triggers after all slides have been shown

        lastSlide: function(){}, //Triggers when last slide is shown

        afterLoad: function(){} //Triggers when slider has loaded

	});

});

</script>

		

<div id="slider" class="found">

<?php 

	$category = get_option('wpns_category');

	$n_slices = get_option('wpns_slices');

?>

<?php query_posts( 'cat='.$category.'&posts_per_page=$n_slices' ); if( have_posts() ) : while( have_posts() ) : the_post(); ?>

	<?php if(has_post_thumbnail()) : ?>

<a href="<?php $title=(the_title() == 'Hormone Therapy') ?  'hormones' : '#'; ?>" title="<?php echo $title; ?>">
	<!--<a title="<?php the_title(); ?>">-->

		<?php the_post_thumbnail(); ?>

	</a>

	<?php endif ?>

	<?php endwhile; endif;?>

	<?php wp_reset_query();?>

</div>



<?php } 



function wpns_menu_function() {



?>



<div class="wrap">

<h2>WP Nive Slider</h2>

 

<form method="post" action="options.php">

    <?php settings_fields( 'wpns-settings-group' ); ?>

    <table class="form-table">

      

        <tr valign="top">

        <th scope="row">Category</th>

        <td>

        <select name="wpns_category" id="wpns_category"> 

			 <option value="">Select a Category</option> 

 			<?php 

 				$category = get_option('wpns_category');

  				$categories=  get_categories(); 

  				foreach ($categories as $cat) {

  					$option = '<option value="'.$cat->term_id.'"';

  					if ($category == $cat->term_id) $option .= ' selected="selected">';

  					else { $option .= '>'; }

					$option .= $cat->cat_name;

					$option .= ' ('.$cat->category_count.')';

					$option .= '</option>';

					echo $option;

  				}

 			?>

		</select>



        </tr>

    	

    	<tr valign="top">

        <th scope="row">Number of slices</th>

        <td>

        <label>

        <input type="text" name="wpns_slices" id="wpns_slices" size="7" value="<?php echo get_option('wpns_slices'); ?>" />

        </label>

        </tr>

        

        <tr valign="top">

        <th scope="row">Type of Animation</th>

        <td>

        <label>

        <?php $effect = get_option('wpns_effect'); ?>

        <select name="wpns_effect" id="wpns_effect">

        	<option value="random" <?php if($effect == 'random') echo 'selected="selected"'; ?>>Random</option>

        	<option value="sliceDown" <?php if($effect == 'sliceDown') echo 'selected="selected"'; ?> >sliceDown</option>

        	<option value="sliceDownLeft" <?php if($effect == 'sliceDownLeft') echo 'selected="selected"'; ?> >sliceDownLeft</option>

        	<option value="sliceUp" <?php if($effect == 'sliceUp') echo 'selected="selected"'; ?> >sliceUp</option>

        	<option value="sliceUpLeft" <?php if($effect == 'sliceUpLeft') echo 'selected="selected"'; ?> >sliceUpLeft</option>

        	<option value="sliceUpDown" <?php if($effect == 'sliceUpDown') echo 'selected="selected"'; ?> >sliceUpDown</option>

        	<option value="sliceUpDownLeft" <?php if($effect == 'sliceUpDownLeft') echo 'selected="selected"'; ?> >sliceUpDownLeft</option>

        	<option value="fold" <?php if($effect == 'fold') echo 'selected="selected"'; ?> >fold</option>

        	<option value="fade" <?php if($effect == 'fade') echo 'selected="selected"'; ?> >fade</option>

        </select>

        </label>

        </tr>

		

		<tr valign="top">

			<td>This is size of yours images. This plugin do not resize images.</td>

        </tr>

		

		<tr valign="top">

        <th scope="row">Width</th>

        <td>

        <label>

        <input type="text" name="wpns_width" id="wpns_width" size="7" value="<?php echo get_option('wpns_width'); ?>" />px

        </label>

        </tr>

		

		<tr valign="top">

        <th scope="row">Height</th>

        <td>

        <label>

        <input type="text" name="wpns_height" id="wpns_height" size="7" value="<?php echo get_option('wpns_height'); ?>" />px

        </label>

        </tr>

    

    </table>

 

    <p class="submit">

    <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />

    </p>

 

</form>

</div>



<?php } ?>

Open in new window

0
 
LVL 82

Accepted Solution

by:
hielo earned 84 total points
ID: 39268884
try:
<a href="<?php echo ( (the_title() == 'Hormone Therapy') ?  'hormones' : '#'); ?>" title="<?php echo the_title(); ?>">
		<?php the_post_thumbnail(); ?>

	</a>

Open in new window

0
 
LVL 6

Author Comment

by:poweraddict
ID: 39268896
nothing is going to work guys, the js file changes everything.

I just hard coded the link and from the link it will redirect to the appropriate page.

I'm giving you all credit for answers.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now