Showing attached images of certain size in Wordpress posts - image

I am currently using WordPress to build my portfolio website. The site consists of:
a homepage showing "project" posts (using post categories).
an about us page
a projects page (very similar to homepage) showing thumbnails and titles of recent projects.
a project detail page (this is a click through from either the homepage or projects page and shows detail on a particular project.
On the project detail page I have an image slider which I want to show the work associated with that project. I have used the following function call to return all images associated with the post:
<?php display_images_in_list('medium'); ?>which calls the following function:
function display_images_in_list($size = thumbnail) {
if($images = get_posts(array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => -1, // show all
'post_status' => null,
'post_mime_type' => 'image',
'orderby' => 'menu_order',
'order' => 'ASC',
))) {
foreach($images as $image) {
$attimg = wp_get_attachment_image($image->ID,'medium');
echo "<div class='slide'>".$attimg."</div>";
}
}
}
Even though I have specified I would like medium images returned my slider still features the thumbnail image which I uploaded to show on another page.
How can I show only medium images?

when you upload image as attachment to post wp creates thumbnails. You cannot upload a thumbnail. If you upload big image, and thumb image both will be shown. You need to upload only big images and than it will show medium size as you wish.

Related

Laravel - Set page title when using Response::make to view pdf file

I am trying to set the page title in Laravel to be the name of the file that is being viewed in the browser. I have looked through the documentation and questions on stack overflow and cannot seem to find the solution. The page title keeps defaulting to the primary key
public function download(SomeModel $document)
{
if(Storage::disk('s3')->exists($document->file_path)) {
return \Response::make(Storage::disk('s3')->get($document->file_path), 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="'. $document->custom_file_name .'"'
]);
}
return view('errors.404');
}
How can I make it to where the <title></title> of the page is using the $document->custom_file_name as opposed to being the id.
You need to set the Title metadata on your pdf document, then the browser will interpret it as the title automatically.
http://www.w3.org/TR/WCAG20-TECHS/PDF18.html

Converting html to pdf after clicking on download button in codeigniter

I have created a resume builder application.User enters all required details and i am storing all details in database. Then i am fetching those records and displaying it in different templates. I have created 3 templates. Now I want to give download as pdf and download as docx two download buttons. Once user clicks on any of buttons file will be downloaded in their chosen format. Either pdf or docx.
Is it possible to achieve in codeigniter?
i used Tcpdf
Controller Code is
the code written in controller download $this - > load - > library("Pdf");
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set auto page breaks
$pdf - > SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf - > setImageScale(PDF_IMAGE_SCALE_RATIO);
// Add a page
// This method has several options, check the source code documentation for more information.
$pdf - > AddPage();
// Set some content to print
$html = $this - > load - > view('resume/res_template1_view', array('left_sidebar' => 'sidebar/left_sidebar', ' right_sidebar' => 'sidebar/right_sidebar'), $data, TRUE);
// Print text using writeHTMLCell()
$pdf - > writeHTML($html, 0, 0, '', '', 0, 1, 0, true, '', true);
//$pdf->writeHTML($html, true, false, true, false, '');
// Close and output PDF document
// This method has several options, check the source code documentation for more information.
$pdf - > Output('resume.pdf', 'D');
Probably you need to use some library in CI to achieve this. Please check below.
you can use Html2Pdf for CI3 library. https://github.com/shyamshingadiya/HTML2PDF-CI3
How to Use
There are 4 options you a required to set in order to create a PDF; folder, filename, paper and HTML
//Load the library
$this->load->library('html2pdf');
//Set folder to save PDF to
$this->html2pdf->folder('./assets/pdfs/');
//Set the filename to save/download as
$this->html2pdf->filename('test.pdf');
//Set the paper defaults
$this->html2pdf->paper('a4', 'portrait');
//Load html view
$this->html2pdf->html(<h1>Some Title</h1><p>Some content in here</p>);
The create function has two options 'save' and 'download'. Save will just write the PDF to the folder you choose in the settings. Download will force the PDF to download in the clients browser.
//Create the PDF
$this->html2pdf->create('save');
Advanced usage
Theres no reason why you can't build and pass a view to the html() function. Also note the create() function will return the saved path if you choose the 'save' option.
$data = array(
'title' => 'PDF Created',
'message' => 'Hello World!'
);
//Load html view
$this->html2pdf->html($this->load->view('pdf', $data, true));
if($path = $this->html2pdf->create('save')) {
//PDF was successfully saved or downloaded
echo 'PDF saved to: ' . $path;
}
Please check above mentioned solution. Let me know if it not works.

Displaying pdf in laravel

I'm creating a site where an author uploads a pdf file. The way I've created my site is there is a page where story titles is shown, if a person clicks on the title it uses the story slug to go to the story, but I want a pdf to be displayed when the the title is clicke d. I'm not sure where to start. I have tried barryvdh/laravel-dompdf, but it doesn't have a "partial" section to display a pdf. It only allows for the pdf to be viewed as a whole page. I hope I made sense.
Something similar to this Google Books
Try this way :
$filename = 'test.pdf';
$path = storage_path($filename);
return Response::make(file_get_contents($path), 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="'.$filename.'"'
]);
Try this html object tag :
<div>
<object data="test.pdf" type="application/pdf" width="300" height="200">
alt : test.pdf
</object>
</div>

Laravel 4 imagecache intervention not displaying images

Here's the product page with an imagecached image: http://kmk-prof.kz/product/dx700lc
As you can see - image is not being displayed and has following url: /imagecache/catalogue/dx700lc-541a82fe99ac3.jpg
But when i try to browse that image just in my uploads folder - http://kmk-prof.kz/uploads/dx700lc-541a82fe99ac3.jpg it displays just fine.
Why could imagecache not work?
Here's the imagecache config.php:
'route' => 'imagecache',
'paths' => array(
public_path('uploads'),
),
'templates' => array(
'catalogue' => function($image) {
return $image->fit(213, 213);
},
),
It's very hard to tell you why the image is not displaying without any code.
Looking at the site, your image (in the html) is looking for a file in /imagecache/catalogue/dx700lc-541a82fe99ac3.jpg when your file is in uploads/dx700lc-541a82fe99ac3.jpg.
you can do 2 things:
change the code to load the file from uploads/dx700lc-541a82fe99ac3.jpg.
or, change your image path to /imagecache/catalogue/dx700lc-541a82fe99ac3.jpg
if you want more help, please post your code.
PS. your IMAGE URL link doesn't work ^_^

The url from an image via custom field (wordpress)

Am not even sure if this can be done but...
Ive added a feed from my forums to wordpress it works great but I need it to auto add the url of the image in a custom field from the images in the post (feed) first image would be fine as its only ahve a slider
Is there any way to do this?
Details
Ok I think I did not explain this very well so made a few screen shots
This is my slider at the minute with my
This is an imported post one other feed I was using
On this image you can see the custom field (which I have to fill in after every import)
Adding the image url into the custom field
and finaly a view of the slider working
This is what am trying to do (auto) so my feed from my booru / forums / 2 other of my sites and (2 other peoples) sites make my home page on a new site
Hope this explain it alot more
This uses the external Simple Pie library built into WordPress to fetch the feed, get the image url and create a new post for each item and save the image url as a custom field.
To activate the process we have to hook into wp_cron. The code below does it daily but it would probably be better to do it weekly to prevent overlap. Some overlap will probably occur so this still needs a way to check if we have already imported the image
First we need a function to save the custom field after the post has been created. This section comes from another answer I found on WordPress Answers.
Edit:
This needs to be wrapped in a plugin to schedule the cron event and the cron event was missing the action to make it fire.
Edit:
Final version below tested and it works but the feed the OP is getting is using relative url's so the domain name needs to be added somewhere in the output code.
<?php
/*
Plugin Name: Fetch The Feed Image
Version: 0.1
Plugin URI: http://c3mdigital.com
Description: Sample plugin code to fetch feed image from rss and save it in a post
Author: Chris Olbekson
Author URI: http://c3mdigital.com
License: Unlicense For more information, please refer to <http://unlicense.org/>
*/
//Register the cron event on plugin activation and remove it on deactivation
register_activation_hook(__FILE__, 'c3m_activation_hook');
register_deactivation_hook(__FILE__, 'c3m_deactivation_hook');
add_action( 'c3m_scheduled_event', 'create_rss_feed_image_post');
function c3m_activation_hook() {
wp_schedule_event(time(), 'weekly', 'c3m_scheduled_event');
}
function c3m_deactivation_hook() {
wp_clear_scheduled_hook('c3m_scheduled_event');
}
function create_rss_feed_image_post() {
if(function_exists('fetch_feed')) {
include_once(ABSPATH . WPINC . '/feed.php'); // include the required file
$feed = fetch_feed('http://animelon.com/booru/rss/images'); // specify the source feed
}
foreach ($feed->get_items() as $item) :
// global $user_ID;
$new_post = array(
'post_title' => $item->get_title(),
'post_status' => 'published',
'post_date' => date('Y-m-d H:i:s'),
//'post_author' => $user_ID,
'post_type' => 'post',
'post_category' => array(0)
);
$post_id = wp_insert_post($new_post);
if ($enclosure = $item->get_enclosure() )
update_post_meta( $post_id, 'feed_image_url', $enclosure->get_link() );
endforeach;
}

Resources