I'm not super familiar with wordpress, but I've been working on getting my layout written as a theme so I can use the wordpress platform. For some reason I can't get the_post_thumbnail function working.
so when use this
the_post_thumbnail(array(100,100));
its show me this error
Illegal offset type in
Have you enabled thumbnails in the functions.php?
In your functions.php, you should add this in order to enable featured thumbnails:
add_theme_support( 'post-thumbnails' );
And then call inside your loop, or inside your while:
<?php
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'large', true);
echo $image_url[0];
?>
It will return your featured image URL and then you can echo the $image_url[0] wherever you want.
Related
I have installed this plugin -> http://wordpress.org/plugins/wordpress-posts-timeline/ .
With this plugin you can create a post and it displays in a timeline. My problem is that images don't show when inserted in the post box.
I tried modifying the plugin code and put some get_attachment code inside the loop there but unfortunately didn't work.. I can get all images to show, but not by ID of the post.
Youtube support would be nice too, but maybe that gets clear if this question is answered.
Current state -> http://erwin.my89.nl/stage/sieh
// Edit
I have tried alot of code with wp_get_attachment stuff.
<?php
wp_get_attachment_image( $attachment_id, $size, $icon );
?>
&
<?php $uri = wp_get_attachment_image_src( $post->ID, 'medium' );
echo $uri[0];?>
But cant get it to work..
Thanks in advance.
The plugin is stripping HTML tags when building the content:
function timeline_text($limit){
$str = get_the_content('', true, '');
$str = strip_tags($str);
// etc...
You have to add <img> (and others) as an allowed tag on strip_tags():
$str = strip_tags($str, '<img>');
I having the following widget snippet in a wordpress theme functions file:
//display image links
foreach ($f as $post_id) {
echo 'id:'.$post_id;
echo get_the_post_thumbnail($post_id);
}
But get_the_post_thumbnail never returns anything.
Things tried:
checked $post_id is set correctly
posts have featured images set
add_theme_support( 'post-thumbnails' ); is set
I don't see what else I can do to solve this
I am using wordpress 3.6 and advanced custom field plugin 4.2.1.
advanced custom field settings - https://dl.dropboxusercontent.com/u/15109395/q/acf-media.png
my post - https://dl.dropboxusercontent.com/u/15109395/q/page-content.png
my single page code
<section id="contentLeft" class="single">
<?php if ( have_posts() ) { the_post(); the_content(); }?>
</section>
Result - https://dl.dropboxusercontent.com/u/15109395/q/page-front.png
but , i don't want that attachment image on content area. my local installation have no problem. not showing attachments. but my live website showing attachment uploaded to that post.
how can i solve this issue? please help me. Thanks.
My problem solved with this solution. Thanks.
http://wordpress.org/support/topic/thumbnails-magically-appearing-on-all-pages
if you want remove images from all posts and pages, simple copy the following code into your theme functions.php
<?php
function remove_images( $content ) {
$postOutput = preg_replace('/<img[^>]+./','', $content);
return $postOutput;
}
add_filter( 'the_content', 'remove_images', 100 );
?>
it will remove the images wherever the_content() have images
else you need to include this function in specific page , put the following code
<?php remove_filter( 'the_content', 'remove_images' ); ?>
I use this theme:
http://demo.themezilla.com/?theme=classica
Under the "recent projects" i want each posted portfolio post to display what kind of tag/skill-type it is connected to. This can be checked in the wp-admin page when you create a new portfolio post. I don't know what function i need to write in php to make this work.
Is there any easy way to solve this like when you show a posts excerpt?
<?php the_excerpt(); ?
I think you can use like this.
<?php the_tags( '<p>Tags: ', ', ', '</p>'); ?>
If it's stored as a custom variable (appears below the post content when editing it in the admin panel), you can usually access it like so:
get_post_meta($post->ID, 'key_name_here', true);
Check out the get_post_meta() Code Page for more details on the function.
Use get_the_term_list() to get the skill-type and strip_tags() to remove the links
$terms = get_the_term_list( $post->ID,'skill-type', '', ', ','' );
$terms = strip_tags( $terms );
I'm creating a custom post type for creating gallery posts. One of the things I took out was the 'editor' section since I have my own uploader. Since the HTML editor is gone (can't use shortcodes now), is there a wp function which is the equivalent of the [gallery] shortcode?
As per the Codex recommendation for outputting the [gallery] shortcode content directly in a template file, I would use do_shortcode():
<?php do_shortcode( '[gallery]' ); ?>
You can even pass accepted parameters:
<?php do_shortcode( '[gallery columns="4" size="medium"]' ); ?>
Got it. Here's the code for anyone else who wants to do the same thing. Throw this baby in your theme template file and try it out.
$images = get_children(array('post_parent'=>$post->ID, 'post_type'=>'attachment', 'post_mime_type' => 'image'));
foreach($images as $image){
echo wp_get_attachment_link($image->ID);
}
You can use the wordpress function make for this purpose
gallery_shortcode(array('orderby'=>ID));
by sure to call this after you setup the post