Img Src Not Working - Genesis - wordpress

I have a simple question, you might know it.
<img src="images/sample.jpg" />
In a regular wordpress theme it should be like this ..
<img src="<?php bloginfo('template_directory'); ?>/images/sample.jpg" />
Right?
What about in Genesis themes?

If you are using a Genesis child theme, you should reference the stylesheet directory:
src="<?php echo get_stylesheet_directory_uri(); ?>/images/sample.jpg"

Every theme consist their own user defined functions to implement the functionality to expend more functionality beside basic that you are using.
I am not familiar with the Genesis theme, but i also used CANVAS and many more. It is up on the theme developer that how do he/she used the trick so that the theme functionality will be easily to extend.
Let's take and example:
<img src="<?php bloginfo('template_directory'); ?>/images/sample.jpg" />
the alternative of this:
function get_template_image( $image_name = "sample.jpg" ){
echo '<img src="'. get_template_directory_uri() .'/images/'. $image_name .'" />';
}
and add this function into the functions.php file. and call it like this.
get_template_image( "sample.jpg" );

Related

how to edit $woo_options['woo_featured_height'

I have a old wordpress site that is defining some CSS using this code:
$fixed_height = ' style="height: ' . $woo_options['woo_featured_height'] . 'px;"';
<div class="slide <?php echo $css_class; ?>"<?php echo $fixed_height; ?>>
I cannot figure out where the $woo_options['woo_featured_height'] is defined. I have searched the entire codebase and there is no such value.
That's a woocommerce options array and most likely the option you are looking for comes from a database table and won't exists in your codebase. See this link for more information.

Wordpress ACF Plugin - wp_get_attachment_image function doesn't work with ACF Options Page?

I'm trying to get an image asset shown on the front-end using the wp_get_attachment_image WordPress function, but it doesn't seem to work with my options page on ACF.
Here is my code:
<?php
$image = get_field('logo', 'option');
$size = 'full'; // (thumbnail, medium, large, full or custom size)
if( $image ) {
echo wp_get_attachment_image( $image, $size );
}
?>
Which looks like this on the back-end:
The picture you see above is an options page in ACF and when I try to query that image into the wp_get_attachment_image function, it doesn't work. However, when I run this code:
<img data-src="<?php the_field('logo', 'option'); ?>" alt="footer logo" class="lazyload" />
which is within an image tag, it works just fine.
I copied and pasted what was shows on the ACF docs located here (Basic Display ID), but it's not showing the image on the front-end.
Anything I'm missing guys?
Thanks a lot!
Return value in field should be Image ID. See Screenshot
What is the return value type you used? Image Array, Image URL, Image ID
And you need to get a field like this:
get_field('logo'); why do you add option?
More info here:
https://www.advancedcustomfields.com/resources/image/
wp_get_attachment_image requires the first parameter to be an image ID. In your case, if you are seeing the image using the code <img data-src="<?php the_field('logo', 'option'); ?>" alt="footer logo" class="lazyload" /> then get_field('logo', 'option') is returning the url of the image.. not the ID which is what you need if you are using wp_get_attachment_image.
What you need to do is change the Return Value of your logo field to Image ID.
Then you might have to re upload the image.
And also change this code <img data-src="<?php the_field('logo', 'option'); ?>" alt="footer logo" class="lazyload" /> to <img data-src="<?php echo wp_get_attachment_url(get_field('logo', 'option')); ?>" alt="footer logo" class="lazyload" />
ACf plugin returns value as you have set the return type.
If you have sent the return type as Image array then :
$image[0] -> full or $image[0][$full] or $image[$full] depending on the number of image uploaded.
If you have set return type as Image url:
<img src="<?php $image; ?>"> would do the work.
If you are setting return type as Image Id:
$img2 = wp_get_attachment_image_src(get_post_thumbnail_id($image),
$full); echo $img2[0];
I guess above methods will surely help you out.
Thanks

Responsive WordPress thumbnails

I can easily make images within a post responsive, but am have an issue getting custom post type thumbs to do the same b/c WP automatically inserts a width and height. I am looking for a way to at least override these default widths/heights on them. Anyone happen to have a solution for this?
Thanks in Advance!
- j
This is what you want in your CSS:
img {
max-width: 100%;
height: auto;
}
The first declaration makes sure all images won't exceed the width of their containing element. The auto declaration for height ensures all images retain their proportions when scaled down even when they have size attributes in the img element. So in a way this overwrites the size attributes.
You should use WP's wp_get_attachment_image_src() to output the URL of the thumbnail and then proceed with building your own <img/> tag and responsive-ing it.
<img src="<?php $img=wp_get_attachment_image_src(get_post_thumbnail_id($post->ID)); echo $img[0]; ?>" alt="<?php the_title(); ?>"/>
If you want a specific size, insert this: wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'large')
<img src="<?php $img=wp_get_attachment_image_src(
get_post_thumbnail_id($post->ID),large);
echo $img[0]; ?>" alt="<?php the_title(); ?>"
style="display:block; width:50%;"/>
That should do it.

Adding next and previous buttons to static pages in wordpress?

I'm trying to add next and previous buttons to the static pages on my wordpress site.
I've been able to find some content on how to add these buttons to your blog post but haven't been able to find anything like this regarding static pages.
I'd like to add next and previous buttons to appear on the child pages within all the parent pages on my site, so you'd be able to use a link to navigate to the next/previous page located within the same parent.
Does anyone know how I could go about doing this or of any plugin that might help me out?
--
Thanks to markratledge, I've almost got it, but I just having one problem.
It seems the next and previous links are working almost how I'd like but they are coming in in alphabetical order when I want to to match the order I've got my pages ordered in.
this is what I've tried but it doesn't seem to work
$pagelist = get_pages('child_of='.$post->post_parent.'sort_column=menu_order');
Seems I just figured it out was missing &... should look like this.
$pagelist = get_pages('child_of='.$post->post_parent.'&sort_column=menu_order');
This should work, from the Wordpress Codex (Next and Previous Links « WordPress Codex).
Exclude pages with parameters in get_pages: http://codex.wordpress.org/Function_Reference/get_pages
(Or this plugin http://wordpress.org/extend/plugins/next-page/):
<?php
$pagelist = get_pages('sort_column=menu_order&sort_order=asc');
$pages = array();
foreach ($pagelist as $page) {
$pages[] += $page->ID;
}
$current = array_search($post->ID, $pages);
$prevID = $pages[$current-1];
$nextID = $pages[$current+1];
?>
<div class="navigation">
<?php if (!empty($prevID)) { ?>
<div class="alignleft">
<a href="<?php echo get_permalink($prevID); ?>"
title="<?php echo get_the_title($prevID); ?>">Previous</a>
</div>
<?php }
if (!empty($nextID)) { ?>
<div class="alignright">
<a href="<?php echo get_permalink($nextID); ?>"
title="<?php echo get_the_title($nextID); ?>">Next</a>
</div>
<?php } ?>
</div>

Wordpress: how to make a post template with a fix image placement?

I am building a simple WP theme, but now I am stuck. I need to add an image on a fixed place for post_template A and 2 images on post_template B
Like so:
title
img
date
content
title
img img
date
content
Is it possible to make a template and on the admin side have the corresponding # of upload fields?
You can do that with custom fields...
In the edit page view add a custom field called "img1" for instance and the value should be the image url.
Then in your template A file you can output the image with:
<?php
$myimage = get_post_meta($post->ID, 'img1', true);
if ($myimage) { ?>
<img src="<?php echo $myimage; ?>" />
<?php } ?>
And in template B you just do that 2 times ;)

Resources