Wordpress: how to get an image in more/excerpt? - wordpress

I need to make a homepage of a wordpress blog show just 1 paragraf of text followed by more, and below a big nice image.
However, excerpt does not take images.
Also, if i put the more page divider, no image appears. and even if it does, the 'more' link should be after the text, not after the image.
How can i get this to work?
UPDATE:
I noticed that in the source code, there is a link to an image, but it is not the right link.
currently my blog is at www.domain.com/wordpress and will be moved to www.domain.com.
currently the image has the code:
<img width="800" height="990" alt="" src="../wp-content/uploads/2011/05/2010_06_01_archive.jpg" title="2010_06_01_archive">
Somehow the build-in linkage is broken

Use wordpress's in-built "featured image" (can be set on post's editing page in wordpress admin).
On the page displaying the excerpts:
<div id="excerpts">
<?php
$args = array( 'numberposts' => 3, 'category'=> '1,3,5' ); }
// set number of excepts to show
// and optionally restrict to certain categories
$posts = get_posts($args);
foreach($posts as $post) : setup_postdata($post);
?>
<div class="single-excerpt">
<h3><?php the_title(); ?></h3>
<?php if ( has_post_thumbnail()) the_post_thumbnail('excerpt-thumb'); ?>
<!-- displays thumbnail if it exists -->
<p><?php the_excerpt();?></p>
</div><!-- single-excerpt -->
<?php endforeach; ?>
</div><!-- excerpts -->
In your theme's functions.php:
if ( function_exists( 'add_image_size' ) ) add_theme_support( 'post-thumbnails' );
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'excerpt-thumb', 0, 100, false );
// define excerpt-thumb size here
// in the example: 100px wide, height adjusts automatically, no cropping
}
function new_excerpt_length($length) {
return 42;
// define length of excerpt in number of words
}
add_filter('excerpt_length', 'new_excerpt_length');

You could also use the Wordpress plugin Easy Custom Auto Excerpt which allows you to configure the excerpt to include shortcode, images, and all HTML.

Make sure the image is properly sized, and the physical size is minimized as much as possible. (Gif is usually the best format for this.)
http://codex.wordpress.org/Image_Size_and_Quality

Related

Show sign-up link for non-logged in users instead Buddypress Activity Loop

How to show login link for non-logged in users instead Buddypress Activity Loop?
Is there an easy way to do this in theme functions.php file?
I know how to add notice before loop with: action_activity_loop_start but how to hide the whole loop?
Option 1
You can use something like this:
add_filter( 'bp_get_template_part', static function( $templates, $slug, $name ) {
if ( $slug === 'activity/index' && ! is_user_logged_in() ) {
$templates = [];
}
return $templates;
}, 10, 3 );
This snippet will completely hide the default activity loop, with all filters, forms, etc, rendering an empty page instead of all BuddyPress Activity.
This may not be a desirable way.
Option 2
In the $templates variable you can also define your own path to a custom template (like activity/logged-out.php, so it will look like this:
$templates = [ 'activity/logged-out.php' ];
You will need to create a wp-content/themes/theme-name/buddypress/activity/logged-out.php file with something like this:
<?php do_action( 'bp_before_directory_activity' ); ?>
<div id="buddypress">
<?php do_action( 'bp_before_directory_activity_content' ); ?>
<div id="template-notices" role="alert" aria-atomic="true">
<?php do_action( 'template_notices' ); ?>
</div>
<?php do_action( 'bp_before_directory_activity_list' ); ?>
<div class="activity" aria-live="polite" aria-atomic="true" aria-relevant="all">
CUSTOM TEXT FOR LOGGED OUT USERS.
</div><!-- .activity -->
</div>
You can check activity/index.php file to decide what you need and what you don't, but I think this is a good idea to remove the majority of content and hooks.
Option 3
If you use the BuddyPress Legacy Template Pack (check in BuddyPress settings) you can copy /wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/activity/index.php file into your theme: wp-content/themes/theme-name/buddypress/activity/index.php and do the modification where needed. Check the line around 235 which has this: <?php bp_get_template_part( 'activity/activity-loop' ); ?>.
For BuddyPress Nouveau Template Pack everything is basically the same, but you will need to deal with wp-content/plugins/buddypress/bp-templates/bp-nouveau/buddypress/activity/index.php file. You will need to wrap its div#activity-stream into is_user_logged_in() check before display the whole div and its content, something like this:
<?php if ( is_user_logged_in() ) : ?>
<div id="activity-stream" class="activity" data-bp-list="activity">
<div id="bp-ajax-loader"><?php bp_nouveau_user_feedback( 'directory-activity-loading' ); ?></div>
</div><!-- .activity -->
<?php endif; ?>
This way you will basically override the default BuddyPress template file with your own.
Please remember about the ajax functionality of the page (filtering etc).

Small thumbnail image not appearing in wordpress meta-grid plugin

Thumbnail image is inside Media-Grid plugin -> Grid Builder -> select any grid from grid list ->small thumbnail image in front of 'select an item' drop down list
Thumbnail image not appear online but work fine locally.
Can you please tell me where to start ?
here is image
enter link description here
For cropping thumbnail image, you it would not a proper way to use plugins:
Try with this code, it will helps you for all the rest of thumbnails in your whole site...
Put this code in your function.php file
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'custom-post-thumb', 140, 140,true );
}
Now use this in your code:
<?php if ( has_post_thumbnail()) : ?>
<?php the_post_thumbnail('custom-post-thumb', array('class' => 'attachment')); // here array('class' => 'attachment') apply if you want to apply class to that anchor tag ?>
<?php endif; ?>
Thanks

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 } ?>

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'.

How do I sort by a custom field without manually creating a new page?

Having a bit of an issue with Wordpress here. In all honesty I've always designed my sites from scratch and "coded" from the ground up. Lately I've been trying to work with WP as I've heard good things about it.
It would appear that WP gives you many things for free (e.g. dynamic "pages" based on CATEGORIES). However, I would like to know how to manipulate these freebies without reinventing the wheel. For example, I would like to have my SUB-MENU display a list of post categories. But I would like to sort those categories by a CUSTOM FIELD.
Now, I could reinvent the wheel and manually create (and link to) a new page for each sort, so on and so forth, (which I don't fundamentally mind doing) however, I'm hoping there is a way around this via plugins or otherwise. I've seen several tutorials on custom queries, but they stop short of implementation -- they simply give the query without telling exactly whether to create a new page or plug it into a function somewhere.
Any input would be most appreciated.
Best.
At the top of category.php template in your theme's root directory, add the following to add your custom sort field to the query:
<?php
function is_valid_custom_sort_field($field)
{
// implementation left as an exercise for the questioner
return true;
}
if ($_REQUEST['sort_custom_field'] && is_valid_custom_sort_field($_REQUEST['sort_custom_field'])) {
query_posts($query_string . '&orderby='.$_REQUEST['sort_custom_field']);
}
See:
http://codex.wordpress.org/Function_Reference/query_posts
If your theme doesn't have a category.php, here is a simple default template to base it on (copied from the included twentyten theme):
<?php
/**
* The template for displaying Category Archive pages.
*/
get_header(); ?>
<div id="container">
<div id="content" role="main">
<h1 class="page-title"><?php
printf( __( 'Category Archives: %s', 'twentyten' ), '<span>' . single_cat_title( '', false ) . '</span>' );
?></h1>
<?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo '<div class="archive-meta">' . $category_description . '</div>';
/* Run the loop for the category page to output the posts.
* If you want to overload this in a child theme then include a file
* called loop-category.php and that will be used instead.
*/
get_template_part( 'loop', 'category' );
?>
</div><!-- #content -->
</div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Resources