Wordpress post thumbnails (featured image) metabox not appearing in custom post - wordpress

I've enabled featured images with the following code:
if(function_exists('add_theme_support')){
add_theme_support('post-thumbnails');
set_post_thumbnail_size(145, 9999999999999999999999999999999999999999999, false);
}
and everything works fine except that I can't find the featured image metabox in my custom post editor. Under the "show" menu I only have the number of column and other 2 unrelated options. I'm on the last version of wordpress (3.1, I think?).
Can you help me? I've already tried everything I found on this website and elsewhere.
Thanks in advance.

The correct way to do this is inserting all this code in functions.php
add_theme_support('post-thumbnails', array('events'));
(where events is the name of my custom post, you should use yours)
function create_event() {
register_post_type( 'events',
array(
//...
'supports' => array('thumbnail', 'title', 'editor')
//...
)
);
(thumbnail does the trick, but don't forget title and editor if you want to be able to have a title in your post or edit it!)
And last be sure to tick the box called 'thumbnail' - I suppose, my installation is in another language - under screen options (screen options is a button in the upper right corner, Google the name if you can't find it).

Related

Any way to add metaboxes in custom settings page of custom post type in wordpress? [duplicate]

This question already has an answer here:
Add meta box to WordPress options page
(1 answer)
Closed 4 years ago.
Hi I would like to add metaboxes under custom settings page which is under a custom post type. I can create metaboxes for custom post types also I can create a theme options. But can't find any way to add the metaboxes on a custom settings page. Like my post type hierarchy is like below:
Products
- All item
- Add Item
- Product Category
- Product Settings
I want to add the metaboxes & create a options page on that settings page. Can you please guide me through this one.
I've been trying to follow this gist but can't find a way.
https://github.com/WebDevStudios/CMB2-Snippet-Library/blob/master/options-and-settings-pages/theme-options-cmb.php
Also can you let me know if I can achieve something by tweaking this code where key|value operates
$cmb = new_cmb2_box( array(
'id' => $this->metabox_id,
'hookup' => false,
'show_on' => array(
// These are important, don't remove
'key' => 'options-page',
'value' => array( $this->key, )
),
) );
I've created the settings page by this code
add_submenu_page('edit.php?post_type=ch_product_showcase', 'Product Showcase Settings', 'Showcase Settings', 'edit_posts', basename(__FILE__), array( $this, 'chProductShowcaseSettingsOptions') );
I've done it many times. Use this code and tweak it to your needs:
https://gist.github.com/turtlepod/5203512
Found as a link in the comments of this page:
https://gist.github.com/bueltge/757903
Originally posted here:
Wordpress - Add meta box to options page
Normally I don't like answering with links to another site, but in this case the code is on gist and hopefully will never go away!

Wordpress - Different sidebar for each page

Client needs an website to migrate into WordPress.
In this website each page has an sidebar with different content inside it
In some page accordion comes under sidebar, in some just text and images are visible
How to implement this in WordPress?
If template has to be created, there are many page it cant be done so
Even for every page different sidebar widget is not also possible
Guide me a way to implement this
A different sidebar (widget) are can be added to each page in two steps:
Add the sidebar to the theme template using the page slug as part of the sidebar name. This ensures that the sidebar has a unique name for that page.
Register the sidebars for each page in functions.php for your theme
Add the sidebar to the theme template
In your theme template, add the following code where you want the widget area to be:
<?php
global $post;
dynamic_sidebar( 'widget_area_for_page_'.$post->post_name );
?>
Register the sidebars
In functions.php for your theme add the following block of code to register the sidebars for each page in your site. Note that it includes draft pages etc so that you can edit the widgets while still in draft mode.
function myTheme_registerWidgetAreas() {
// Grab all pages except trashed
$pages = new WP_Query(Array(
'post_type' => 'page',
'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit'),
'posts_per_page'=>-1
));
// Step through each page
while ( $pages->have_posts() ) {
$pages->the_post();
// Ignore pages with no slug
if ($pages->post->post_name == '') continue;
// Register the sidebar for the page. Note that the id has
// to match the name given in the theme template
register_sidebar( array(
'name' => $pages->post->post_name,
'id' => 'widget_area_for_page_'.$pages->post->post_name,
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
) );
}
}
add_action( 'widgets_init', 'myTheme_registerWidgetAreas' );
Hope it helps!
There's a great plugin for this:
https://wordpress.org/plugins/custom-sidebars/
Sometimes it is necessary to show different elements on the sidebars
for some posts or pages. The themes nowadays give you some areas to
put the widgets, but those areas are common for all the posts that are
using the same template. NOTE: You need to use a theme that accepts
widgets to make this plugin work.
I think this is what you're looking for.
This can be done with the https://wordpress.org/plugins/jetpack/ plugin. Once activated you can choose what widgets display on what pages:
The Widget Visibility module enables you to configure widgets to appear only on certain pages (or be hidden on certain pages) by using the Visibility panel.
Visibility is controlled by five aspects: page type, category, tag, date, and author. For example, if you wanted the Archives widget to only appear on category archives and error pages, choose “Show” from the first dropdown and then add two rules: “Page is 404 Error Page” and “Category is All Category Pages.”
Just tried custom-sidebars with the latest version of wp. Had a hard time deleting it. Database is still messy. Plugin did not work. Maybe the 'pro' version is useful, but the 'non-pro' version would not add a sidebar to the page. It was clunky and did not allow per-page sidebars. It says its not been tested with the latest wp, maybe that's the problem.
You can create custom sidebar for for each post and pages with the help of plugin. There are a few plugins which enables you to create your custom sidebar. Here in this tutorial we are using Easy Custom Sidebars. Download and install this plugin in your website and activate it.
After successfully activating the plugin go to Appearance > Sidebar Replacement
From this page give a name to your custom sidebar and click on the Create Sidebar button. After that go to the Sidebar Properties option. Here you need to select the properties where you want to replace your created custom sidebar instead of theme sidebar. You can view your available option in the drop-down menu. Select it and provide a description on the Sidebar Description field.
Now in the last step select the post or pages to add this custom sidebar. You can see all the option in the left column. You can select specific post, page, category , tag, author to add this sidebar. Just select it and click Add to sidebar option.
For better understanding you can follow this tutorial

Reposition elements in Wordpress post editor

I'm developing a wordpress website and I've added some custom fields. They work just fine, but I wanted to reposition them in the admin editor.
So for example you have the WYSIWYG editor with some little widgets on the side, like categories, publish widget and so on. Some of my custom fields are just checkboxes, so I was wondering if it was possible to put those in the admin sidebar, rather than sticking them underneath the WYSIWYG editor.
How can that be achieved?
Check the documentation for add_meta_box.
add_meta_box(
$id,
$title,
$callback,
$post_type,
$context,
$priority,
$callback_args
);
$context - The part of the page where the edit screen section should be shown ('normal', 'advanced', or 'side').

Getting each image in custom WYSIWYG field - Advanced Custom Fields plugin - Wordpress

I'm using the Custom Post UI and Advanced Custom Fields plugin, One of my custom fields is a WYSIWYG field for uploading images (attached to a 'Project' custom post type).I would then like to get the images I uploaded to this WYSIWYG field one by one. Using echo get_field ('name of field') doesnt work because it returns all the images at once.l tried using
'attachment', 'post_per_page' => '-1', 'post_mime_type' => 'image', 'post_parent' => $post-> ID ); ?> ID ); ?>"
This also doesnt work as it returns all images attached to the post even those not in the WYSIWYG field i'm trying to target although in thumbnail sizes.
Note, I have other images attached to this same post but i just want images from a specific WYSIWYG field in the post. I'm actually trying to create an image swap gallery with the thumbnails as navigation so I created a wysiwyg field where the user can upload thumbnail images.I'm trying to use the ultimate image swap gallery used here - http://bit.ly/10eyycX
Sorry for the long post.Looking forward to any help I can get, I've been on this for weeks...

Wordpress 3 insert image to Custom Post Type item

I have a Custom Post Type and I am going to customize it to show a list of some products with images. I have all text fields working fine but I need also an image to be attached to each item. How can I do this?
If each post is a single item, you can add post thumbnail support in your theme, which allows users to either browse for or upload an image and assign it to the post.
add_theme_support('post-thumbnails')
You'll also need to add thumbnail to your supports array when you register your custom post type.
register_post_type('product', array(
'supports' => array('title', 'content', 'thumbnail')
))
You can then retrieve the thumbnail in your theme files using get_post_thumbnail(). Check out the other post thumbnail functions in wp-includes/post-thumbnail-template.php.

Resources