Get excerpt and permalink outside loop in wordpress - wordpress

I'm trying to get the post excerpt and permalink outside a wordpress loop, pulling the thumbnail and the title work fine but when trying to get the excerpt it doesn't work? And how would I get the permalink? My code so far is below.
Thanks!
<div id="featured">
<?php
$ftid = 104;
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ftid) );
?>
<img src="<?php echo $url; ?>" style="float:left;" />
<div class="featured-info">
<h2 class="post-title"><?php echo get_the_title($ftid); ?></h2>
<?php $my_post = get_post($ftid); echo $my_post->post_excerpt; ?>
</div>
</div>
And maybe if there is a better way of doing this you can point me in the right direction? :)

The permalink should work as is:
$permalink = get_permalink($ftid);
The excerpt though, when accessing the page object directly there actually has to be excerpt content (not just post content). If you didn't manually type in an excerpt on the post then nothing will appear. Inside the loop, the_excerpt() will automatically generate from the content if an excerpt hasn't been manually typed. Did you type a separate excerpt in the WP admin?

Look at wp_get_attachment_url() - you left the $ off the name of the $ftid variable.

Related

Remove featured image in Post

I want to remove the featured image in post and page, but keep it as thumbnail so that the site look good! My site is a wordpress based site.
Here's an example post of the site: http://www.tradingspotsilver.com/build-mt4-custom-ea-indicator-forex-free/
You could see that the featured image is on top of the post and occupy a lot of space. I've tried to look at the theme source but no luck.
The link given in your question is a single post page, you look in to your theme's root folder and can find a file named single.php, in that file you may find something like this
// "custom_size" could be anything like "single_page_image"
if ( has_post_thumbnail() ) : the_post_thumbnail('custom_size');
This line of code is responsible for showing the big image. Just remove this line and your image will not show up. Also, you may check this answer for custom image sizing.
For page template, you may look for a file named page.php and look for the similar code.
you can use timthumb for resizing:
with the code here: { https://code.google.com/p/timthumb/source/browse/trunk/timthumb.php }
create a file named timthumb.php in your theme folder, and at the place of the featured image php script, type:
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
//the_post_thumbnail();
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<div class="img-hold"> <img src="<?php bloginfo('template_directory') ?>/timthumb.php?src=<?php echo $url; ?>&w=219&h=125" width="219" height="125" /></div>
<p><? }
echo $content;
?></p>
change the value of height and width as per your wish at &w=, &h= and also width= , height=
hope this helps
just remove the the_post_thumbnail code in the single.php and page.php or content.php.
this function use in wordpress for show featured so just remove or comment it.
check your single.php and content.php page to solve this problem its right there
if you dont require that code comment it / or modify it as you want.
dont mess things go easy with it or otherwise you will end up getting error
I had the same issue and i could not find any solution in single.php
Its simple although:
just comment:
from content.php page
This is for the Dazzle Theme
I found mine in "content-single.php and removed :
<?php the_post_thumbnail( 'dazzling-featured', array( 'class' => 'thumbnail' )); ?>
Picture was gone from post.
It is obviously varies depending on theme.
For theme Freemium you need to remove the following lines in wp-content/themes/freemium/single.php:
<?php $freemium_feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); if($freemium_feat_image!="") { ?>
<img src="<?php echo $freemium_feat_image; ?>" alt="Banner" class="img-responsive img-responsive-freemium" />
<?php } ?>

How to display list categories in wordpress integration magento

Can help somebody. I spent several hours to find solution but without results
I tried to display the list of categories on homepage wordpress blog thru following code
<?php $category = Mage::registry('wordpress_category') ?>
<?php if ($category): ?>
<?php echo $category->getId() ?>: <?php echo $category->getName() ?>
<?php endif; ?>
But the method
Mage::registry('wordpress_category')
always return null.
I found that, i should probably be using the Fishpig_Wordpress_Block_Category_View. But i dont know where i should put it.
The following code will retrieve the current category when viewing a category page in your blog:
<?php Mage::registry('wordpress_category') ?>
This is not what you need. To view a list of categories, you could create a custom collection using the following:
<?php $categories = Mage::getResourceModel('wordpress/post_category_collection') ?>
A better way would be to use the category widget block:
<block type="wordpress/sidebar_widget_categories" name="wp.categories" template="wordpress/sidebar/widget/categories.phtml" />
You can create this in PHP using the following code:
<?php echo Mage::getSingleton('core/layout')
->createBlock('wordpress/sidebar_widget_categories')
->setTemplate('wordpress/sidebar/widget/categories.phtml')
->toHtml() ?>
The above code uses the default template, however, feel free to use your own custom template.

Pluginf for Different header image on every pages in wordpress

I need wordpress plugin for this kind of header image http://www.slb.com/services/drilling.aspx like in this web site. And this image will not be slider but it's static image on perticular page and category and also different image for all categories and pages.
Easiest & best way is create a custom field named banner & in your header.php place below code.
<div class="banner">
<?php if(get_post_meta($post->ID, 'banner', true)) : ?>
<img src="<?php echo get_post_meta($post->ID, 'banner', true); ?>" />
<?php endif; ?>
<div>
But as you want plugin to do this, have a look at plugin named Dynamic Header.

wordpress advance custom field plugin showing broken image?

I am using wordpress acf plugin to show some custom images with their description and some text. So first I just made the acf plugin fileds like this and assigned the page to the home page with the conditional tags Location-> Rules-> Page->is equal to-> Home
now when I made my content-page.php to show the image code like this
<?php
if( get_field('image') ):
?><img src="<?php the_field('image'); ?>" alt="" /><?php
endif;
?>
I am getting only a broken image. The firebug is showing image source like this
Kindly help me to solve this. I have already wasted one day behind it. So any help and suggestions will be really appreciable. Thanks
Here is the screen shot for my custom fields setup
Here is the firebug html code which is showing the image source
Had this problem too. This is what I came up with that works:
<?php if (get_field('staff_photo')) {
$imgarray = get_field( 'staff_photo' );
?>
<img src="<?php echo $imgarray['url'] ; ?>" alt="" class="staff-photo" />
<?php } ?>
So, what I did was put get_field('field_name') array into a variable, then took a WAG that the key was 'url', which it was. Seems like the ACF people need to update their documentation.
Hah! Discovered another way -- this way you can pick a size:
<?php
if ( get_field('staff_photo') ) {
$imgarray = get_field( 'staff_photo' );
$size = "thumbnail"; // (thumbnail, medium, large, full or custom size)
echo wp_get_attachment_image( $imgarray['id'], $size );
}
?>
For wp_get_attachemnt_image to work, you have to extract the image id, for which the key is, ta-da! 'id'.

Wordpress Customize the_content

I am quite new to Wordpress and try to customize my Wordpress theme. My posts are always different. But basically there is a title, a text and a NivoSlider/Image/Vimeo Video.
If I use the basic the_content function it displays the post like that:
<h2>Title of the Post</h2>
<p><div class="slider-wrapper">Slider</div>Text</p>
It always includes the Slider/Image/Video in the Tag. How can I split the_content object?
I would like to have my posts display like that e.g. for the NivoSlider:
<div class="slider-wrapper">Slider</div>
<h2>Title of the Post</h2>
<p><Text</p>
It would be really great if somebody could tell me the easiest way to do for all the different kinds of posts.
I hope you understand my explanation, if you need more details, just tell me.
Thanks in advanced.
Best,
Brigi
Personally, I would take the shortcode out from your Content Body altogether, and place it in a Custom Field (named something like "postSlider"). Then you can structure your template like so:
<?php
do_shortcode(get_post_meta(get_the_ID(), 'postSlider'));
?>
<h2><?php the_title(); ?></h2>
<p><?php the_content(); ?></p>
You needs to create a custom page template for your posts. In that page template you can define your slider. Then just put your text in the content section.
Before doing serious coding refer this: Stepping Into Templates
Thanks again for your answer. Finally I used the Types plugin for Wordpress. You can easily customize your own field and use it in your index.php file with the following code:
Custom Field Image:
<?php echo(types_render_field("field-slug-image", array("alt"=>"Product image", "width"=>"600","height"=>"300","proportional"=>"true"))); ?>
Shortcode Custom Field for the Slider:
<?php echo apply_filters('the_content', get_post_meta($post->ID, 'field-slug-slider', true)); ?>
Shortcode Custom Field for the Vimeo video:
<?php echo apply_filters('the_content', get_post_meta($post->ID, 'field-slug-video', true)); ?>
Title and Content:
<h2><?php the_title(); ?></h2>
<?php the_content('Read the full post',true);?>

Resources