ad thumbnail to aw blog posts in magento - html

in magento 1.8.1 i have added a thumbnail image to aw blog posts header and into the aw blog sidebar widget next to the each headline
i did these:
In app/code/community/AW/Blog/Block/Manage/Blog/Edit/Form.php
change:
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
'method' => 'post',
));
to
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
'method' => 'post',
'enctype' => 'multipart/form-data'
));
In app/code/community/AW/Blog/Block/Manage/Blog/Edit/Tab/Form.php
add
$fieldset->addField('featured_image', 'image', array(
'name' => 'featured_image',
'label' => 'Featured Image'
));
below the line
$fieldset = $form->addFieldset('blog_form', array('legend' => Mage::helper('blog')->__('Post information')));
In app/code/community/AW/Blog/controllers/Manage/BlogController.php
add
if(isset($_FILES['featured_image']['name']) and (file_exists($_FILES['featured_image']['tmp_name']))) {
try {
$uploader = new Varien_File_Uploader('featured_image');
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader->setAllowRenameFiles(false);
// setAllowRenameFiles(true) -> move your file in a folder the magento way
// setAllowRenameFiles(true) -> move your file directly in the $path folder
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir('media') . DS .'blogpic'.DS;
$uploader->save($path, $_FILES['featured_image']['name']);
$data['featured_image'] = $_FILES['featured_image']['name'];
}catch(Exception $e) {
}
}
// handle delete image
else {
if(isset($data['featured_image']['delete']) && $data['featured_image']['delete'] == 1)
$data['image_main'] = '';
else
unset($data['featured_image']);
}
below the line
$model = Mage::getModel('blog/post');
And added a "featured_image" column to the aw_blog table in database. Use the type VARCHAR(255) default null and null enable .
and add
<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$post->getFeaturedImage() ?>" alt="featuredImage" />
to
/app/design/frontend/base/default/template/aw_blog/blog.phtml
below line
<?php foreach ($posts as $post): ?>
<div class="postWrapper">
<div class="postTitle">
<h2><a href="<?php echo $post->getAddress(); ?>" ><?php echo $post->getTitle(); ?></a></h2>
the problem is: the images are saving in right place in media/blogpic but they are not shown in frontend

In your blog.phtml subst
<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$post->getFeaturedImage() ?>" alt="featuredImage" />
with
<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).DS.'blogpic'.DS.$post->getFeaturedImage() ?>" alt="featuredImage" />
Hope it helps.

The easiest way to add a featured image or thumbnail image to the Magento version of AWBlog without coding is as follows:
-In the blog post go to the SHORT CONTENT text field
-In that field enter your image url
<img src="{{media url="wysiwyg/blogimages/myimages/your.jpg"}}" alt="folding chairs" />
-Underneath that enter your blurb that shows
When you save and open the blog post in the blog overview you will see you featured image shows with the content blurb just below it.

Related

Yii2 Pagination with Tabs

I have 5 tabs on one page. All the tabs have different content, but on one of them i need to have pagination. When click on pagination the page is refreshing and the current opened tab is closed and show by default first tab ... I want when click on pagination, the current tab to be open and the refresh only part with data information.
here is my code:
<?php
Pjax::begin([
'id' => 'w0',
'enablePushState' => true, // I would like the browser to change link
'timeout' => 10000 // Timeout needed
]);
$spec = Specifications::find()->where('active = 1')->orderBy(['sort' => SORT_ASC]);
$count = $spec->count();
$pagination = new Pagination(['totalCount' => $count, 'defaultPageSize' => 20]);
$models = $spec->offset($pagination->offset)
->limit($pagination->limit)
->all();
echo LinkPager::widget([
'pagination' => $pagination,
'hideOnSinglePage' => true,
'prevPageLabel' => 'Предишна',
'nextPageLabel' => 'Следваща'
]);
if ($spec) { ?>
<div class="form-group">
<label>Спецификации</label></br>
<?php
foreach ($models as $singleSpec) {
echo $singleSpec->id." ".$singleSpec->title;
}
?>
</div>
<?php } ?>
<?php Pjax::end() ?>
remove 'id'=>'w0' from Pjax, it is refreshing your page

wp query not working with custom post type > category

I'm using html5-blank for my theme.
all queries work fine when pulling from standard wordpress post type... it breaks when trying to pull from 'html5-blank' post type.
Here's the query:
<?php $my_query = new WP_Query('category_name=spotlight&showposts=2');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID; ?>
<!-- pull thumbnail image -->
<article class="article_wrap">
<div class="widget_thumb">
<a href="<?php echo get_permalink(); ?>">
<?php echo get_the_post_thumbnail(); ?>
</div>
<h1 class="widget_title"><?php the_title(); ?></h1>
<p class="widget_spot_description"><?php the_excerpt(); ?></p>
</article>
<?php endwhile; ?>
here's functions.php:
function create_post_type_html5()
{
register_taxonomy_for_object_type('category', 'html5-blank'); // Register Taxonomies for Category
register_taxonomy_for_object_type('post_tag', 'html5-blank');
register_post_type('html5-blank', // Register Custom Post Type
array(
'labels' => array(
'name' => __('HTML5 Blank Custom Post', 'html5blank'), // Rename these to suit
'singular_name' => __('HTML5 Blank Custom Post', 'html5blank'),
'add_new' => __('Add New', 'html5blank'),
'add_new_item' => __('Add New HTML5 Blank Custom Post', 'html5blank'),
'edit' => __('Edit', 'html5blank'),
'edit_item' => __('Edit HTML5 Blank Custom Post', 'html5blank'),
'new_item' => __('New HTML5 Blank Custom Post', 'html5blank'),
'view' => __('View HTML5 Blank Custom Post', 'html5blank'),
'view_item' => __('View HTML5 Blank Custom Post', 'html5blank'),
'search_items' => __('Search HTML5 Blank Custom Post', 'html5blank'),
'not_found' => __('No HTML5 Blank Custom Posts found', 'html5blank'),
'not_found_in_trash' => __('No HTML5 Blank Custom Posts found in Trash', 'html5blank')
),
'public' => true,
'hierarchical' => true, // Allows your posts to behave like Hierarchy Pages
'has_archive' => true,
'supports' => array(
'title',
'editor',
'excerpt',
'thumbnail'
),
'can_export' => true, // Allows export in Tools > Export
'taxonomies' => array(
'post_tag',
'category'
) // Add Category and Post Tags support
));
}
I'm checking the category box in the custom post type but the query does not populate the post. It only shows the posts from the standard post type.
Noooooooo!
You should specify the post type in the wp query:
$my_query = new WP_Query('category_name=spotlight&posts_per_page=2&post_type=html5-blank');
Edit: replaced deprecated showposts by posts_per_page

Different sidebars for different pages on Wordpress

I'm trying to design a theme on WordPress (version 3.3.2) but I am having a few problems in having the sidebar display a different set of widgets on certain pages.
I have tried several online tutorials and this one in particular http://www.rvoodoo.com/projects/wordpress/wordpress-tip-different-sidebars-on-different-pages/ but unfortunately there is no change in the sidebar when I move to a different page
I registered two sidebars on my functions.php as shown below, one which I would consider as main, and the other as a custom sidebar, and I also added different widgets to these sidebars.
<?php register_sidebar( //register sidebar
array(
'name' => 'Right-side',
'before_widget' => '<div class="rightwidget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
));
register_sidebar( //register second sidebar
array(
'name' => 'Second-right',
'before_widget' => '<div class="rightwidget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
));
?>
Following that, I created the files sidebar.php and sidebar-second.php to be able to call them.
sidebar.php
<div id="sidebar">
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Right-side')) : ?>
<h3 class="widget-title">No widget added</h3>
<p> Please add some widgets</p>
<?php endif; ?>
</div><!--ends sidebar-->
sidebar-second.php
<div id="sidebar">
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Second-right')) : ?>
<h3 class="widget-title">No widget added</h3>
<p> Please add some widgets</p>
<?php endif; ?>
</div><!--ends sidebar-->
And then I added replace my <?php get_sidebar() ; ?> statement with following conditional
<?php if( is_page('225') ) : ?>
<?php dynamic_sidebar('second'); ?>
<?php else : ?>
<?php get_sidebar() ; ?>
<?php endif ; ?>
However only the widgets added to the sidebar.php are displayed on every page. Any help on how I could change this, or pointers on what I could be doing wrong. Thanks.
I looks like you are using <?php dynamic_sidebar('second'); ?> where you should be using <?php get-sidebar('second'); ?>
What get_sidebar('foo') does is look for a file named 'sidebar-foo.php' in the root directory of your theme and includes it. dynamic_sidebar('bar'), on the other hand, looks for a sidebar registered with:
<?php register_sidebar( array( 'name' => 'bar' ... ) ) ?>
Hope this helps!
Why don't you use the Custom Sidebar Plugin?
It's really easy to use and does not need any coding
You have two sidebars. when you want to use the sidebar-second file on a particular page, instead of calling
<?php get_sidebar('second') ; ?>
TRY
<?php get_sidebar('sidebar-second.php') ; ?>
this should do the trick

lightbox effect on wordpress post attached images

I have this code to display the attached images on a post:
<?php
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID,
'exclude' => get_post_thumbnail_id()
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo '<a href="';
echo wp_get_attachment_url( $attachment->ID );
echo '" rel="lightbox">';
echo wp_get_attachment_image( $attachment->ID, 'large' );
echo '</a>';
}
}
?>
But i cannot work out why the Lightbox is not working! I have tried colorbox, shadowbox, ligthbox plugins etc... it just does not load. When you click on the image, it just opens in page.
What am i doing wrong?
See if your theme call
wp_head();
in your header file and
wp_footer();
in your footer file the plugins don't work if youar missing this.

Wordpress; image not appearing post loop

I have post about this before, but I didn't get any conclusive answer but I'm really hoping someone can help me. I have setup some custom post types, and with them, some custom fields using Wordpress 3's UI.
One of the fields I have set up is called banner_image, but in the loop, it doesn't output the image.
<?php echo get_post_meta($post->ID, 'banner_image', true); ?>
This simply outputs the ID number of the post. If I set the function to false, I get an array with this ID in and nothing else. How do I get the path to the image? I can't work this out and Googling reveals a sea of content not related to my problem, it's a real difficult one to search for so you're my only hope!
Many thanks,
Michael.
<?php
global $post;
$tmp_post = $post;
$args = array(
'post_status' => 'publish',
'post_type' => 'work',
'order' => 'DESC'
);
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<?php if( get_post_meta($post->ID, 'show_in_home_banner', true) == "yes" ) { ?>
<li class="slide">
<div class="slide-image">
<a href="<?php echo get_page_link($post->ID) ?>">
<?php echo get_post_meta($post->ID, 'banner_image', true); ?>
</a>
</div>
<div class="slide-content">
<h3 class="slide-header"><?php echo get_post_meta($post->ID, 'sub_title', true); ?></h3>
<p class="slide-title"><strong><?php echo the_title(); ?></strong></p>
</div>
</li>
<?php } ?>
<?php endforeach; ?>
Try this
<?php echo get_post_meta($post->ID, 'banner_image', $single); ?>
Apparently, the custom field 'banner_image' doesn't have the right value. I guess it doesn't save the correct value first. You may want to install the Simple WP FirePHP plugin (http://wordpress.org/extend/plugins/simple-wp-firephp/) and check the value with the fb() function.