The following code is for a Wordpress plugin, it displays points and tank of a user:
<?php
if(function_exists('cp_displayPoints') && $authordata->ID){
echo '<span class="cubepoints_buddypress">'; cp_displayPoints($authordata->ID); echo '</span>';
if(function_exists('cp_module_ranks_getRank')) echo ' <span class="cupepoints_buddypress_rank">'.cp_module_ranks_getRank($authordata->ID).'</span>';
}
?>
I am trying to extract these two echo functions from the If statement but only succeeded with one of them. I can echo the points like this:
<?php cp_displayPoints($authordata->ID); ?>
Works fine. Now I tried doing the same with the second echo:
<?php cp_module_ranks_getRank($authordata->ID); ?>
But it did not work. Obviously, there is some basic thing that I am missing here. Do you know what it is?
The first one likely prints directly to output, while the second returns its value. So, you need to echo() the second one, just as they're doing in your sample code:
<?php echo cp_module_ranks_getRank($authordata->ID); ?>
Related
I have a variable given to me by my cms
I want to add one space before that but have tried many things lol and all dont work, below is what I have tried so far.
<?php echo str_repeat('', 1) htmlencode('$postcode_coveringsRecord['postcode']) ?>
<?php echo htmlencode(' $postcode_coveringsRecord['postcode']) ?>
<?php echo htmlencode('. $postcode_coveringsRecord['postcode'].) ?>
<?php echo ' ''htmlencode('$postcode_coveringsRecord['postcode'])' ?>
<?php echo htmlencode(' ''$postcode_coveringsRecord['postcode']) ?>
How can I minipulate
where as the variable gives me one blank space prior to the variable content.
cheers for any input
emma
These ones should work
echo ' '.htmlencode($postcode_coveringsRecord['postcode']);
or
echo ' '.htmlencode($postcode_coveringsRecord['postcode']);
I'm trying to find the category ID of a post and then use it in the short code below. To find the category id I'm using <?php the_category_ID(); ?>, but i'm not sure how to use the output from category id and replace it in include_categories=. i.e. i want to replace number 4 with the current category ID i got from <?php the_category_ID(); ?>.
<?php echo do_shortcode('[include_categories="4"]'); ?>
i tired doing the following, but it didn't work. Any ideas will be appreciated.
<?php echo do_shortcode('[include_categories="<?php the_category_ID(); ?>"]'); ?>
I know i can't use php inside another php code, but i'm not sure how to place the category id between the quotation.
Thanks.
A couple of things: (1) you can't have nested <?php ?> tags, (2) the_category_ID() has been deprecated since WordPress 0.71. You'll want to use get_the_category() instead.
The correct solution would be:
<?php echo do_shortcode('[include_categories="' . get_the_category() . '"]'); ?>
The dots . "concatenate" the string with the returned values of get_the_category(). You can read more about string operators in the PHP docs.
Try with -
<?php echo do_shortcode('[include_categories="'.the_category_ID().'"]'); ?>
Use this to add php verial in short code:
<?php $category=the_category_ID();
echo do_shortcode("[include_categories=$category]"); ?>
this is the piece of code I'm not sure how to deal with:
<?php echo get_post_meta($post->ID, 'smartslider2', true); ?>
<?php echo do_shortcode('[smartslider2 slider="InsertHere"]'); ?>
I simply want to insert the first echo instead of InsertHere. The first echo should output the content of a custom field. The second should recall the slider with the specific number inserted in the custom field. When trying different possibilities I only get errors.
Can anybody help?
Thank you :)
Don't echo the first value, use it directly inside your second echo.
<?php
echo do_shortcode('[smartslider2 slider="'.get_post_meta($post->ID, 'smartslider2', true).'"]');
?>
Or you can easily put that first value in a variable and use that variable in the second line
<?php $slider = get_post_meta($post->ID, 'smartslider2', true); ?>
<?php echo do_shortcode('[smartslider2 slider="'.$slider.'"]'); ?>
I am going to retrieve some data from database and display it in php file.
It seems like it can connect to my localhost's database,because code like:
<?php foreach($goods as item ):?>
haven't occur any errors.
but when it comes to the codes like,
<?php echo $item->logo;?>
on my browser, it simply display
logo;?>
what's wrong with my codes or setting.
As the file is quite big and I think the system config problem(I have reinstalled wampserver), I just show a little bit
my code:
<?php echo sizeof($goods);?>
<td class="td_f"><IMG src="http://127.0.0.1:8020/UB_real//public/photos/frontimg/<?php echo $item->logo?>"> </td>
<?php endforeach; ?>
You have an error in your code:
Where you said:
<?php foreach($goods as item ):?>
Must be:
<?php foreach($goods as $item ); ?>
Note the missing $ before item, and the semicolon ; not the :
If you need to list all the returned values in $goods (for testing purposes), you can always do:
echo '<pre>';
print_r($goods);
echo '</pre>';
I have a table of data in wordpress...
in the following code...
echo '<tr><td>Category</td><td>:</td><td>'. the_category(', ') .'</td></tr>';
category name is not displaying in correct position, it is displaying above all the row...
i can't figure out the problem... everything seems perfect...
Use get_the_category_list(', '). See documentation.
get_the_category_list() returns the result, the_category() prints the result
Well that is something that echo will do with functions that print result you should use it like this
<?php // some code ?>
<tr><td>Category</td><td>:</td><td><?php the_category(', ') ?></td></tr>
<?php // some code ?>
Use functions in html.