Multiple Featured Images Wordpress - wordpress

So my aim is to find a method of adding more thumbnails only for displaying on a custom post type, for example I wish to have a large image (not the same image) for a featured post and a different image for the default view.

In the end i followed this tutorial and it did exactly what i required to a T.
http://www.lifeonlars.com/wordpress/how-to-add-multiple-featured-images-in-wordpress

have you try this add_image_size
why don't you use custom post template plugin

I got a solution from online. I also customized some code. You can check this.
Step 1 Download this library from this link and put beside functions.php ( theme root ).
Step 2: Copy this code below to functions.php.
/*
* Code for Multiple Featured Image.
* Multiple Featured image is only for your selected post type.
*/
require_once('library/multi-post-thumbnails.php');
if (class_exists('MultiPostThumbnails')) {
new MultiPostThumbnails(array(
'label' => '2nd Feature Image',
'id' => 'feature-image-2',
'post_type' => 'your_post_type_name'
)
);
new MultiPostThumbnails(array(
'label' => '3rd Feature Image',
'id' => 'feature-image-3',
'post_type' => 'your_post_type_name'
)
);
new MultiPostThumbnails(array(
'label' => '4th Feature Image',
'id' => 'feature-image-4',
'post_type' => 'your_post_type_name'
)
);
};
Step 3 Check now.

I can write entire code here, but clicking on this tutorial link is much easier :)

Related

How can I make the user change any image on my wp theme just from the theme editor?

How can I make the user change any image on my wp theme just from the theme editor?
For example: I have a background image on my theme footer that i hard-coded, I want to give the user(admin) the ability to change it from the theme editor, and thanks on advanced
I don't want to use something like this:
<div class="footer-background background-image" style="background-image: url(<?php echo get_theme_file_uri( 'assets/images/bg.jpg' ) ?>)" >
If you can just give me a wp codex on this, it would be more than helpful, because I couldn't find any thing related to my problem on Google.
So, you could do something like that (in functions.php) :
add_action( 'customize_register', function( $wp_customize ) {
$wp_customize->add_section(
'section_img',
array(
'title' => 'Images',
'priority' => 35,
)
);
$wp_customize->add_setting(
'footer_image'
);
$wp_customize->add_control(
new WP_Customize_Image_Control(
$wp_customize,
'footer_image',
array(
'label' => 'Footer image',
'section' => 'section_img',
'settings' => 'footer_image'
)
)
);
});
And you get the value by doing (in footer.php) :
get_theme_mod('footer_image');
If I were you, I do followings
Install ACF plugin
Create an option Page
Create new custom field (image field) and assign it to previously created options page.
Update footer template to show the image from back end like this
Update footer image src to get back end ACF field value.
https://www.advancedcustomfields.com/resources/options-page/
https://www.advancedcustomfields.com/resources/image/

Using Code Snippets in Wordpress to remove a line of code from a plugin?

I want to remove a specific line of code from a plugin in WordPress. I can edit the plugin itself, but when it is updated it overwrites the changes I have done. I read that using the code snippet WordPress plugin I can have it always overwrite, regardless of updates.
If the line of code I want to be removed is the
'required'=>true
from the code below, how would I write that in the code snippet plugin? The plugin file I am editing is located at wp-store-locator/admin/class-metaboxes.php
`$meta_fields = array(
__( 'Location', 'wpsl' ) => array(
'address' => array(
'label' => __( 'Address', 'wpsl' ),
'required' => true
),`
Thanks so much

Register widget area above posts in WordPress Genesis child theme

I have a Genesis child theme that I'm working on (here's my test site) and I can't seem to figure out how to register a widget area above the posts. I see a lot of tutorials (like this one) that show how to add one that spans both columns (posts & sidebar), but I'd like to have one that is only above the posts, not the sidebar.
Looking at these hooks, it would be in the genesis_before_loop hook I believe. I tried tweaking the code in the tutorial I linked to but it didn't work out. Does anyone have the code or link to a better tutorial?
This is code I'm trying to use but it's not working:
/**
* Add widget above posts.
*/
//* Add widget above posts
add_action( 'genesis_loop’, ‘above_posts’ );
function above_posts() {
if (is_active_sidebar( ‘aboveposts’ )) {
genesis_widget_area( ‘aboveposts’, array(
'before' => '<div class=“aboveposts widget-area"><div class="wrap"',
'after' => '</div></div>'
) );
}
}
//* Register widget above posts areas
genesis_register_sidebar( array(
'id' => ‘aboveposts’,
'name' => __( ‘Above Posts’ ),
'description' => __( 'This is the above posts widget.’ ),
) );

Creating a delete confirmation for images using the Wordpress meta box plugin

I am using the Meta Box plugin for Wordpress. I can successfully create fields in the cms for users to upload images. I would like to extend this in two ways:
First, I would like a delete confirmation when users remove an image from the image gallery
Here is the code:
$meta_boxes[] = array(
'id' => 'project_media',
'title' => 'Project Media',
'pages' => array( 'project' ),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'name' => 'Media Gallery',
'desc' => 'Images should be sized to 983px x 661px',
'id' => $prefix . 'project_media_gallery',
'type' => 'image'
)
);
This creates upload functionality in the custom post type where users can add images to a slideshow. The problem is if the user accidentally clicks the delete button, there is no confirmation to make sure it is deleted. Can I somehow extend the plugin through functions and call an alert when this button is clicked? Something that does not involve editing the WP core?
Second, the base functionality requires the user to upload an image from their local machine. Is there a way to tap into the Media Library for this?
No idea how to even start tackling this one.
To answer the first question
First, I would like a delete confirmation when users remove an image from the image gallery
You can do that by calling a custom script file from the functions.php.
function alert_delete() {
if(is_admin()){
wp_register_script( 'alert_delete', get_bloginfo('template_url'). '/js/alert_delete.js', array('jquery'));
wp_enqueue_script('alert_delete');
}
}
and create a file named alert_delete.js in the js directory of your theme.
alert_delete.js:
// admin delete check
jQuery(document).ready(function(){
jQuery(".rwmb-delete-file").click(function() {
if (!confirm("Are you sure? This process cannot be undone.")){
return false;
}
});
});
In response to the second question...
Second, the base functionality requires the user to upload an image
from their local machine. Is there a way to tap into the Media Library
for this?
Get the latest version of the Meta Box Plugin first.
then change
'type' => 'image'
to
'type' => 'image_advanced'
which will allow you to upload from the existing Media Gallery or a new file from your computer.

Get table header to use pager url drupal 7

I have got a unique issue. In my drupal site, I have got a lot of nodes displayed in a teaser and for each node, I am using a table with a pager. The problem is, on initial load of the page, the table sort doesn't work. However, if I use the pager and move to a different page and then back, then the sorting works.
I investigated this issue and found out that on initial load, the url for the header links use the primary link, which is: mysite.com/node?sort=asc&order=Name. After I click on the pager, then the url for the header links, changes to this: mysite.com/mycallbackfunction?_=1348208999187&page=1&nid=13&pager_id=1&sort=desc&order=Name
If you notice, the url obviously are different, which is okay, but the main thing is, the nid is missing in the initial load. I would like the table headers to use the pager url, or some url that I specify, so the nid would appear in both cases as the function returns nothing if there is no nid.
This is the relevant code in mycallbackfunction which displays the table:
//Attach a theme table
$html = theme('table', array(
'header' => $header,
'rows' => $rows,
'attributes' => array(
"class" => array(
"my_table_box"
),
"cellspacing" => '0',
"cellpadding" => '0'
)));
//Pager theme
$html .= theme('pager', array(
'element' => $pager_id,
'parameters' => array(
'nid' => $nid,
'pager_id' => $pager_id),
'quantity' => ceil($count/5)
));
Hope someone might have an insight into this weird problem.
You can pass the custom parameter in theme('pager') function.
<?php
// e.g.
theme('pager', array('parameters' => array('nid' => $nid))
?>);
Let me know if you are looking for something else.
Good Luck!
-Imran

Resources