how to append php code in the shortcode in wordpress - wordpress

I am using the shortcode in the loop inside template file
and also using the lightbox form plugin.
<?php query_posts('showposts=9&post_type=packages') ?>
<?php while (have_posts()) :the_post(); ?>
<?php echo the_post_thumbnail(); ?>
...
...
<?php echo do_shortcode("[formlightbox text='Book Now' title=the_title][contact-form-7 id='383' title='Booking Form'][/formlightbox]"); ?>
<?php endwhile; ?>
Please note that in the shorcode there is title=the_title and it is not appened to the anchor tag.
But when I use title='hello'or something else it gets appended to the anchor tag.
I want current post's title should get appened to the rendered anchor tag via shortcode.
please help me

Break the string and use the string concatenation operator to combine the function into your string.
<?php echo do_shortcode("[formlightbox text='Book Now' title='" . get_the_title() . "'][contact-form-7 id='383' title='Booking Form'][/formlightbox]"); ?>
Update
This should use the get_the_title() as opposed to the_title() which echos the title.

Related

Shortcode inside other shortcode Wordpress ACF

how to use this function correctly:
<?php echo do_shortcode('[product id="<?php the_field('wyrozniony_produkt_id')?>"]'); ?>
I need write inside this in place 3931
<?php echo do_shortcode('[product id="3931"]'); ?>
This shortcode (textfield from ACF)
<?php the_field('wyrozniony_produkt_id')?>
Anyone have idea how to make this?
your syntax seems to be wrong
please check the updated code of yours
<?php
$product_id = get_field('wyrozniony_produkt_id');
echo do_shortcode('[product id="'.$product_id.'"]');
?>

How to get page title in wordpress

Well, I have tried
<?php echo get_the_title('About Us');?>
But the code is not working. I am using wordpress 4.1. This should work but it isn't. Has wordpress updated the functions?
Try this one, It's may help you
<?php single_post_title(); ?>
Thanks :)
Try this one,may it's help you
<?php echo get_the_title(); ?>
And if you want to get page or post title By id
<?php echo get_the_title(post->$ID); ?>
Thanks
You are giving wrong parameters to get_title. See the codex.
You should have used ID instead to get the title.
So your code would be
<?php echo get_the_title(13); //where 13 is the ID of the about us page ?>
NOTE: Parameters are optional.
You could use the_title() to display the title of the page. You can pass parameters for before and after HTML tags. For morr information, here are the docs:
https://developer.wordpress.org/reference/functions/the_title/
<?php
the_title();
?>
You can try this
<?php echo get_page_by_title( 'About' ); ?>
Reference
<?php
$page = get_page_by_title( 'About Us' );
echo get_the_title($page->ID)
?>

wordpress the_content not showing video

I am developing a separate website and for showing the blogs i am using the worpress.I have used following code to display blogs.It shows the textual contents properly but for video it just shows the player bar and not click able.
I have also checked themes index.php there is no the_excerpt.
When i check preview of the post using wordpress admin it shows the video properly.
can anyone help me resolve this?
here is my code..
<?php
global $more;
$posts = get_posts('category=3&numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) : setup_postdata( $post ); ?>
<?php $more = 1; ?>
<?php the_date(); echo "<br />"; ?>
<span style="color:#1C1644;font-size:1.3em !important;font-weight: bold;">
<?php the_title(); ?>
</span>
<div id="lol"><?php the_content(); ?>
</div>
<hr>
<?php
endforeach;
?>
Please try this
<?php
global $more;
$posts = get_posts('category=3&numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) :
setup_postdata( $post ); ?>
<?php $more = 1; ?>
<?php the_date(); echo "<br />"; ?>
<span style="color:#1C1644;font-size:1.3em !important;font-weight: bold;">
<?php echo the_title(); ?>
</span>
<div id="lol">
<?php echo the_content(); ?>
</div>
<hr>
<?php
endforeach;
?>
All you need to do to embed something into a post or page is to post the URL to it into your content area. Make sure that the URL is on its own line and not hyper-linked (clickable when viewing the post).
For example:
http://www.youtube.com/watch?v=dQw4w9WgXcQ
WordPress will automatically turn that into a YouTube embed when the post is viewed.
You can also optionally wrap the URL in the [embed] shortcode. It will accomplish the same effect, but does not require the URL to be on its own line.
It also allows you to set a maximum (but not fixed) width and height, like so:
[embed width="123" height="456"]http://www.youtube.com/watch?v=dQw4w9WgXcQ[/embed]
If WordPress fails to embed your URL you will get a hyper-link to the URL.
Use wp custom fields. Add video_embed custom field your post and add code.
<?php echo get_post_meta($post->ID, 'video_embed', true); ?>
Edit:
if(get_post_meta($post->ID, 'video_embed', true)){
echo get_post_meta($post->ID, 'video_embed', true);
}
else
{
the_content();
}

WordPress, custom single page content

I am trying to get a custom single page to spit out the title and content of the post, the title works fine, the content of the post doesn't seem to want to come through. I don't work much in wordpress so I am in the dark here, can someone tell me how to fix this? Here is my single-news.php code:
<?php get_header(); ?>
<div class="decade1">
<?php
echo get_the_title().'<br/>'; //Output titles of queried posts
echo get_the_content().'<br/>';
?>
</div>
<?php get_footer(); ?>
Thanks!!
You need the WordPress Loop before using tags like get_the_title().
<?php get_header(); ?>
<div class="decade1">
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
echo get_the_title() . '<br/>';
echo get_the_content() . '<br/>';
} // end while
} // end if
?>
</div>
<?php get_footer(); ?>
get_the_content() must be use in loop.
syntax:
get_the_content( $more_link_text, $stripteaser )
where $more_link_text and $stripteaser are optional.
read about it
and get_the_title() will output title only when it is in loop, otherwise you have to provide post id to display title.
get_the_title($post_id)

Drupal 7 Views - How to access unformatted $row variable in a custom template?

I just installed Views module for Drupal 7 and am trying to find out how to customize it.
So far, I have done the following things.
Created a content type specified views and named it as 'videotest'.
Created a custom theme as 'views-view-list--videotest.tpl.php'
The page is working without a problem.
Here is the custom template code I used (this is the default template from Views):
<?php print $wrapper_prefix; ?>
<?php if (!empty($title)) : ?>
<h3><?php print $title; ?></h3>
<?php endif; ?>
<?php print $list_type_prefix; ?>
<?php foreach ($rows as $id => $row): ?>
<li class="<?php print $classes_array[$id]; ?>"><?php print $row; ?></li>
<?php endforeach; ?>
<?php print $list_type_suffix; ?>
<?php print $wrapper_suffix; ?>
How do I prevent Views to format $row for me? I like to format each values in a node myself using foreach.
I tried to set the view style as 'unformatted' with unformatted custom template, but it also style each value for me.
You should to use fields templates not 'Display', 'Style', or 'Row'.
Or you can use both fields in 'Row' template. Ex:
print $fields['you_field_value']->raw;
Name of 'you_field_value' show as part of link in fields list of view display.
Or to get the value of field:
print $fields['field_pretitle_front']->content;
print $fields['your_field_value']->raw;
did not work for me, however the following did in my case.
$row->field_YOUR_FIELD[0]['rendered']['#markup'];

Resources