i want to get the wordpress title post to a span tag.
i use the code below with the_title() in span tags:
<?php echo '<div>
<img src="image.jpg"/>
<h2><span>'.the_title().'</span>
</h2></div>'; ?>
but the title is show in a tag P, the result is:
<p>TITLE_OF_THE_POST_IS_SHOW_HERE
<div>
<img src="image.jpg"/>
<h2><span></span>
</h2></div>
in result, the span tags is empty, how do insert the title in the span tag?
I would advice changing this
<?php echo '<div>
<img src="image.jpg"/>
<h2><span>'.the_title().'</span>
</h2></div>'; ?>
to something like this
<div>
<img src="image.jpg"/>
<h2>
<?php the_title( '<span>', '</span>' ); ?>
</h2>
</div>
the php the_title function see documentation Here accepts parameters so you can define the parent tag <span> inside of the wordpress function the_title().
Keep in mind that the_title shows the current post title. If you want to get a title from another post you can use get_the_title( post = 3 ) as Mark B mentioned above.
Related
trying to use <?php the_category( ' ' ); ?> to put in my category from my wordpress post.
within the loop html
<a href='<?php the_permalink(); ?>'>
<section id="post-<?php the_ID(); ?>" class="..">
<div>
<?php the_category( ' ' ); ?>
<?php the_title( '<h1>', '</h1>' ); ?>
</div>
</section>
</a>
Problem is that having the category php the section div's seems to get pulled out of the link (output has section outside link code.
Not having the category code it works perfectly.
You have an issue in your HTML: you have a <a> tag (inline element) with inside block type elements (like <div> and <section>).
Take a look at this page in order to properly understand the difference between inline and block elements.
While using the_category(), you are going to displays a link to the category or categories a post belongs to, so you are also placing a <a> tag inside another <a> tag.
Because you want just display the categories' names, you can use the following code
foreach((get_the_category()) as $category){
echo $category->name."<br>";
}
Review your formatting and everything will be work as expected.
I am trying to insert a custom tag after H3 tag with a certain class by inserting code into my theme's function.php file. Below is what I am doing but unable to achieve it.
If I have this, showing on a page currently:
<h3 class="title">TITLE HERE</h3>
<div class="desc">
I would like to insert a tag after h3 tag. Below is what I am trying to insert intp my theme functions.php file:
echo '<h3 class="title">TITLE HERE</h3>
<a tooltip="This is a test">TEST</a>
<div class="desc">'
As a result, I am just getting 'TEST' on the top of the page instead of showing it after the h3 tag.
Can you try this first.
Add **<div style="clear:both;"></div>** after your closing </h3> tag
OR
I think you are creating shortcode in function.php file. If you directly echo in your function then this problem will arise. First you assign the value to variable which you want to echo and then return this variable.
Eg:
function my_fun(){
$text='<h3 class="cuzd-title"> TITLE HERE</h3> <div style="clear:both;">
</div> <a data-tooltip="THIS IS TEST">TEST</a>';
return $text;
}
add_shortcode( 'shortcode_name', 'my_fun' );
now where you want these to be display just use
echo do_shortcode('[shortcode_name]');
I've got an image carousel in a site. I want to display the image alt tag or title below the image when I do mover over. At the same time I want to display that same name in another h1 tag.
The code is in PHP and Magento implementation. I know it is a simple trick. But I tried all the codes using jQuery after, append and replacewith functions. These functions are working. But I couldn't display the alt or title name.
Php Code:
<ul id="mycarousel" class="jcarousel-skin-tango alt">
<?php
// products
if(!isset($CatID))
$CatID = 10; // Set to classic collection if empty;
$_category = Mage::getModel('catalog/category')->load($CatID);
$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('status', 1)//enabled
->addCategoryFilter($_category);
foreach($products as $index=>$prod):
$product = Mage::getModel('catalog/product')->load($prod->getId());
echo '<li style="border: none;">
<a class="thumbActImg1" href="'.$product->getProductUrl().'" data-rel="'.(string)Mage::helper('catalog/image')->init($product, 'small_image')->keepFrame(FALSE)->resize($_resize, $_resize).'" alt="'. $product->getName() .'">
<div class="thumbActImg2">
<img src="'.$product->getThumbnailUrl(80, 80).'" alt="'. $product->getName() .'" />
</div>
</a>
</li>';
endforeach;
?>
</ul>
jQuery code:
jQuery(this,'img.thumbActImg2').after('<div class="pname"><?php echo $product->getName()?></div>');
jQuery('#pro_name h1').replaceWith('<h1><?php echo $product->getName()?></h1>');
Right now, I used php echo in order to display name. But it displaying the current page product name instead of mover over image name.
Could anyone help me out please.
Hi,
the PHP-Code is evaluated once, when the site is generated. So the <h1><?php echo $product->getName()?></h1> is always the same text.
You have to rewrite/get the current information from the image, when it's cycled (if I understand you). So here is what may work for you:
//insert the code, where the carousel is triggered
//get the alt attribute from image and replace h1 content
jQuery('#pro_name h1').html(jQuery('img.thumbActImg2').attr('alt'));
I hope this is what you're looking for, the problem isn't descripted very briefly.
Greetings Mat
I've a problem with the content of one node.
There's a loop to display the excerpt of last news on a page.
the content of the loop is :
<h2 class="title"><?php print $title; ?></h2>
<?php if ($node->field_news_thumb[0] && $node->field_news_thumb[0]['filepath']): ?>
<img src="/<?php print $node->field_news_thumb[0]['filepath']; ?>" width="200" >
<?php endif; ?>
<?php print_r($node->content['body']['#value']); ?>
But there is just one news for which the title and thumb are well displayed, but the content is empty.
In the backoffice I've just one paragraph in content.
I found that if I add a new paragraph, the first one will be displayed on the front.
When there's just one paragraph, if I click on the title to get fullpage node. The content is well displayed with exactly the same method :
<?php print_r($node->content['body']['#value']); ?>
How can I display the full content of these nodes ?
Ok I find the solution.
I have replace
print_r($node->content['body']['#value']);
By :
$news = node_load(array('nid' => $node->nid));
print_r($news->body);
This give me the full content. I just have to shorten as I want.
I am using a wordpress theme that has a custom post type called "link" which simply produces a post where the title links to an outside link you specify. It also includes some text in the body of the post. I would like to also be able to display an image. Right now it is not showing the image.
Here is the code:
elseif ( has_post_format( 'link' )) {
if(get_post_meta($post->ID, '_format_link_url', true)!=''){
$link = get_post_meta($post->ID, '_format_link_url', true);
}else{
$link = '';
}
?>
<h2 class="entry-title">
<a href="<?php echo $link; ?>" target="_blank" title="Follow this link">
<?php the_title(); ?>
</a>
</h2>
<p>
Is there anything I can add to make it display an image as well as text?
Thanks!
I can't see anywhere on this example where you are using an tag to insert an image. The img tag has two required attributes, src and alt. Src is the path to your image, whereas alt is the alternate text for the image. So:
<img src="images/myImage.png" alt="This Is My Image"/>
Hope that helps!