I have a code that can get me the category_id of an item. This is the code:
<?php echo lavada_category_id() ; ?>
I want to know how I can add this code. Inside this, I want to replace the number 2 in here;
<?php lavada_query_item("category=2");?>
with:
<?php echo lavada_category_id() ; ?>
I know you cannot do like this
<?php lavada_query_item("category=<?php echo lavada_category_id() ; ?>");?>
But how can I do it?
Why not store it into a variable and then use that variable?
<?php
$catID = lavada_category_id();
lavada_query_item("category={$catID}");
?>
OR if you just want category ID to be passed into lavada_query_item do this:
lavada_query_item($catID);
The syntax error that you have is that you can not use <?php within <?php
You just need to concatenate the string like this:
<?php lavada_query_item("category=". lavada_category_id() );?>
I think this is what you are looking for:
<?php lavada_query_item(lavada_category_id());?>
The value returned from thelavada_category_id() function will be passed into the lavada_query_item() function.
Related
I'm trying to use the PHP function thingy echo, it sends out something weird.
When I write:
<?php
echo'<p>Hello</p>'
?>
And what I get out is:
Hello
') ?>
^^ This thing, I don't know why but it's there
I can remove those parts from the code and they disappears but it kind of ruins the code..
You need to put ';' at the end of line like this : <?php echo'<p>Hello</p>'; ?>
You forgot this: ;
So please insert it at the end of echo smth:
<?php
echo'<p>Hello</p>';
// here it is ^
?>
Put ; at the end
<?php
echo'<p>Hello</p>';
?>
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'm using WordPress. I appreciate being shown the code, but this is one I am interested in straight out learning how to do myself too - so if you know where I can find a tutorial or can give me information I'd appreciate it!
I'm calling posts and want to include a PHP code within a PHP code, this is for a theme options panel.
<?php
query_posts('cat=-51&posts_per_page=3&paged='.$paged);
if (have_posts()) :
?>
Where the 51 is I want to put:
<?php echo get_option('to_postc_home'); ?>
Where the 3 is I want to put:
<?php echo get_option('to_posti_home'); ?>
If I'm interpreting right, this is what you need, use the concatenation operator . to use those functions in place of plain text ex: 'this is text' versus 'this '.get_option('stuff').' text'
<?php
query_posts('cat='.get_option('to_postc_home').'&posts_per_page='.get_option('to_posti_home').'&paged='.$paged);
if (have_posts()) :
?>
To include a php file from another file you use the include function
You can use it whereever you want
<?php
query_posts('cat=-51&posts_per_page=3&paged='.$paged);
if (have_posts()) :
?>
hello world
<?php echo get_option('to_postc_home');
endif;
<?php
$a = get_option('to_postc_home');
$b = get_option('to_posti_home');
query_posts("cat={$a}&posts_per_page={$b}&paged={$paged}");
if (have_posts())
?>
That is called string concatenation, and you are already using that on the first line of your code, when you concatenate the literal string 'cat=-51&posts_per_page=3&paged=' with the variable $paged. In PHP, the . operator does that.
So, in your code, you can do this:
<?php
query_posts('cat=-' . get_option('to_postc_home') . '&posts_per_page=' . get_option('to_posti_home') . '&paged='.$paged);
?>
This will inject the output of the function calls at the places you indicated.
<?php
$cat = get_option('to_postc_home');
$per_page = get_option('to_posti_home');
query_posts("cat=${cat}&posts_per_page=${per_page}&paged=".$paged);
if (have_posts())
?>
I'm calling a function like this:
<?php print get_thumbnail('http://url.com/?skin=rss'); ?>
Being a php newbie, I'm wondering if there is a way to change the http://url.com part based on a custom metadata I have set up in Wordpress. So I guess it would look something like this:
<?php print get_thumbnail('<?=$video_src?>/?skin=rss'); ?>
Is something like this possible?
Yes, you have the right idea, you just don't need to re-open PHP tags since you're already inside some. You can use . to concatenate (join together) the value of $video_src and "?skin=rss".
<?php print get_thumbnail($video_src . "?skin=rss"); ?>
Try this:
<?php print get_thumbnail($video_src . '/?skin=rss'); ?>
Keep in mind that <?= $foo ?> is shorthand for <?php echo $foo; ?>. <?= ?> won't be expanded in strings, but you can achieve something similar using double quoted strings:
<?php print get_thumbnail("$video_src/?skin=rss"); ?>
Yes, except within PHP, you don't need to enter the PHP tags again.
<?php print get_thumbnail($video_src . '/?skin=rss'); ?>