How to get page title in wordpress - 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)
?>

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 do I figure out if a record is a page or a post in wordpress

I am in search.php and I get, for a certain query, a set of results (pages and posts). Now, within the loop I am using to display such results, I need to figure out if the current item is actually a post or a page.
How do I do that? Is there a conditional tag to do it? I couldn't find it :(
Thanks
You can use is_page( $post->ID ) for pages and is_single( $post->ID ) for posts.
You can retrieve and check the post type of a post with get_post_type().
echo 'The post type is: ' . get_post_type( get_the_ID() );
The right answer is the following (sorry guys):
<?php while (have_posts()) : the_post(); ?>
<?php if ($post->post_type === "post"): ?>
it's a post!
<?php endif; ?>
<?php endwhile; ?>

Get next post's permalink in Wordpress

I'm using this code to get a link to the next post in Wordpress
<?php next_post_link('%link', '', TRUE); ?>
And it gives me this result:
All I need is a URL like this:
http://www.someaddress.com/post/3/
Please help
Try:
Previous Post:
<?php echo get_permalink(get_adjacent_post(false,'',false)); ?>
Next Post:
<?php echo get_permalink(get_adjacent_post(false,'',true)); ?>

Diamond MultiSite Widget

I am using Diamond MultiSite Widget in my site. Alongwith post title, url, description, I also want to display the post thumbnail. I have tried many times, contacted the plugin author for help but in vein. Does anyone know how to do it?
Ref: Please check 'Latest Questions' block in this quotation page.
Thanks.
First of all, you have to get the post id to belong that you get a post thumbnail image of that
Second, you have to display the post-featured Image.
Then this code is not working. please specify your actual requirement.
<?php $pages = get_pages(array('child_of' => 1)); ?>
<?php foreach ($pages as $page): ?>
<?php echo get_the_post_thumbnail($page->ID, 'thumbnail'); ?>
<h1><?php echo $page->post_title; ?></h1>
<?php echo $page->post_content; ?>
<?php endforeach; ?>

Themeing in views , drupal 7

Goal : To add a div wrapper for the fields so as to group the fields per result.
So views is displaying all the results as fields and I need to theme it as per each result. So each result will have the name, image ....
You can see the current results view here : http://www.iamvishal.com/dev/prosearch/%20/%20/%20/%20/%20
I tried to theme it using views-view-unformatted.tpl.php file but It won't do anything. I did change the tpl to suit my view such as views-view-unformatted--properityresults--page.tpl.php.
It won't work. Any clues what is going wrong ?
Below is the code:
<?php if (!empty($title)): ?>
<h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
<div class="<?php print $classes_array[$id]; ?>">
<?php print $row; ?>
</div>
<?php endforeach; ?>
The correct template file was views-view--properityresults--page.tpl.php
and not views-view-unformatted--properityresults--page.tpl.php.
cheers,
Vishal
I will mark is solved after a day as per the system settings.

Resources