How to display post title in Wordpress?

2019-06-14 12:39发布

I'd like to generate the wordpress post title in the following javascript code: I'm placing this code under the content in my wordpress posts.

<script charset="utf-8" type="text/javascript">
document.write('\x3Cscript type="text/javascript" charset="utf-8" src="http://adn.ebay.com/cb?programId=1&campId=5337203820&toolId=10026&customId=posttop&keyword=**POST-TITLE**&width=728&height=90&font=1&textColor=000000&linkColor=0000AA&arrowColor=8BBC01&color1=709AEE&color2=[COLORTWO]&format=ImageLink&contentType=TEXT_AND_IMAGE&enableSearch=y&usePopularSearches=n&freeShipping=n&topRatedSeller=y&itemsWithPayPal=n&descriptionSearch=n&showKwCatLink=n&excludeCatId=&excludeKeyword=&catId=177913%2C179767%2C1059&disWithin=200&ctx=n&autoscroll=n&flashEnabled=' + isFlashEnabled + '&pageTitle=' + _epn__pageTitle + '&cachebuster=' + (Math.floor(Math.random() * 10000000 )) + '">\x3C/script>' );

The keyword= part of the script is where I need to generate the wordpress post title. I was trying keyword="<?php single_post_title(); ?>" but it doesn't generate the wordpress post title... not sure if I'm on the right track or not.

Any help would be appreciated. Please remember I'm a newbie. If I forgot to mention something please ask. I'll be quick to respond.

Thanks a lot!

标签: wordpress
3条回答
forever°为你锁心
2楼-- · 2019-06-14 12:57

There's a simple way to do it for blog posts and normal pages. Here it is:

<?php the_title(); ?>
查看更多
Explosion°爆炸
3楼-- · 2019-06-14 13:01
//loop start

foreach($allnews as $news):
 $title=get_the_title($news->ID);

 //following code print your post title
 echo $news->post_title; 
 //also you can written
 keyword="<?php echo $title; ?>"

 endforeach; 
//end loop  
查看更多
We Are One
4楼-- · 2019-06-14 13:11

inside your loop see if ( have_posts() ) and while, use this inside the while statement.

$title= get_the_title();

Now the variable is set, you can use it later unless it is overwritten.

in your js:

keyword="<?php echo $title; ?>"
查看更多
登录 后发表回答