Jump to content

Multiple commands in one statement with a single line output?


cswake

Recommended Posts

Hi, I'm modifying the following PHP code from a Wordpress plugin:

 

/* Byline. */

if ( $instance['byline'] )
echo do_shortcode( "<p class='byline'>{$instance['byline']}</p>" );

/* Entry title. */

if ( 'widget' !== $instance['entry_container'] && $instance['entry_title'] && $show_entry_title ) {
the_title( "<{$instance['entry_title']} class='entry-title'><a href='" . get_permalink() . "' title='" . the_title_attribute( 'echo=0' ) . "' rel='bookmark'>", "</a></{$instance['entry_title']}>" );
}
elseif ( 'widget' !== $instance['entry_container'] && $show_entry_title ) {
the_title( "<a href='" . get_permalink() . "' title='" . the_title_attribute( 'echo=0' ) . "' rel='bookmark'>", "</a>" );
}

 

The output currently is:

[ December 13, 2010 ]

Post Title

 

I'm trying to combine the two so that the output appears on one line.  What is the operator to execute multiple command in one statement?

 

Thanks.

What is the operator to execute multiple command in one statement?

 

I don't understand the question. What do you mean 'execute multiple command in one statement'?

 

if you want to put 2 strings together, just concatenate them with .

 

$str = "hello". " ". "world";
echo $str;
[code]

output:

hello world

Sorry if I wasn't clear, I'm just asking how to combine the Byline section into the Entry title.  The end result as I imagine it would look something like (this code doesn't work, of course):

 

if ( $instance['byline']&& 'widget' !== $instance['entry_container'] && $instance['entry_title'] && $show_entry_title ) {
echo do_shortcode( "<span class='byline'>{$instance['byline']}</span>" ) && the_title( "<{$instance['entry_title']} class='entry-title'><a href='" . get_permalink() . "' title='" . the_title_attribute( 'echo=0' ) . "' rel='bookmark'>", "</a></{$instance['entry_title']}>" );
}

 

 

 

dot (period) is the concatenation operator. so to combine the output of the 2 commands, you'd do something more like

 

echo do_shortcode( "<span class='byline'>{$instance['byline']}</span>" ) . the_title( "<{$instance['entry_title']} class='entry-title'><a href='" . get_permalink() . "' title='" . the_title_attribute( 'echo=0' ) . "' rel='bookmark'>", "</a></{$instance['entry_title']}>" );
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.