Ads not showing in WordPress post - php

Despite returning the adinserter() function correctly, the ads are not appearing and only the ad header is being displayed. I am not sure what is causing this problem and would greatly appreciate any assistance in resolving this issue. Could it be an error in my code or a configuration problem with the plugin? I am hoping for some guidance and support in fixing this problem.
Also while consoling this error was showing:
Uncaught TagError: adsbygoogle.push() error: No slot size for availableWidth=0
Here's the php code
function insert_ad_codes($content) {
if (!function_exists('adinserter')) return $content;
$paras = explode("</p>", $content);
$total_paras = count($paras);
$insert_at = [];
// // check if device is mobile
if (wp_is_mobile()) {
$insert_at = [
floor($total_paras * 0.4),
floor($total_paras * 0.8)
];
} else {
$insert_at = [
floor($total_paras * 0.4),
floor($total_paras * 0.8)
];
}
foreach ($insert_at as $index) {
$paras[$index] .= '<div class="ad-container ad-container-1">'
. '<div class="ad-header ad-header-1">Ad Header</div>'
. '<div class="ad-content ad-content-1">' . adinserter(1) . '</div>'
. '</div>';
}
$content = implode("</p>", $paras);
$content = preg_replace('/(<p[^>]*>)/i', '<div class="ad-container ad-container-16">'
. '<div class="ad-header ad-header-16">Ad Header</div>'
. '<div class="ad-content ad-content-16">' . adinserter(1) . '</div>'
. '</div>' . '$1', $content, 1);
$content = preg_replace('/(<p[^>]*>.*?<\/p>)/i', '$1' . '<div class="ad-container ad-container-1">'
. '<div class="ad-header ad-header-1">Ad Header</div>'
. '<div class="ad-content ad-content-1">' . adinserter(1) . '</div>'
. '</div>', $content, 1);
return $content;
}
add_filter( 'the_content', 'insert_ad_codes');
css and js
add_action( 'wp_head', function () { ?>
<style>
.ad-container {
position: fixed;
bottom: 0;
right: 0;
height: 0;
overflow: hidden;
transition: height 0.3s;
}
.ad-header {
background-color: #333;
color: #fff;
padding: 10px;
text-align: center;
}
.ad-content {
background-color: #fff;
padding: 10px;
display: none;
}
.ad-container.expanded {
height: 300px;
}
.ad-container.expanded .ad-content {
display: block;
}
</style>
<script>
var ad = document.querySelector('.ad-container');
var observer = new IntersectionObserver(function(entries) {
if (entries[0].isIntersecting) {
ad.classList.add('expanded');
} else {
ad.classList.remove('expanded');
}
});
observer.observe(ad);
</script>
<?php } );

Related

Unable to get lazy load data in codeigniter using AJAX

I am doing an e-commerce website. Just want to implement lazy load. I can fetch the data at first load but again if I scroll down no data can be fetched.
**HTML CODE**
<div class="row" id="fetchedprodducts">
<div class="row" id="load_data_message"></div>
<div id="load_data"></div>
</div>
**CSS**
#-webkit-keyframes placeHolderShimmer {
0% {
background-position: -468px 0;
}
100% {
background-position: 468px 0;
}
}
#keyframes placeHolderShimmer {
0% {
background-position: -468px 0;
}
100% {
background-position: 468px 0;
}
}
.content-placeholder {
display: inline-block;
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
-webkit-animation-name: placeHolderShimmer;
animation-name: placeHolderShimmer;
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
background: #f6f7f8;
background: -webkit-gradient(linear, left top, right top, color-stop(8%, #eeeeee), color-stop(18%, #dddddd), color-stop(33%, #eeeeee));
background: -webkit-linear-gradient(left, #eeeeee 8%, #dddddd 18%, #eeeeee 33%);
background: linear-gradient(to right, #eeeeee 8%, #dddddd 18%, #eeeeee 33%);
-webkit-background-size: 800px 104px;
background-size: 800px 104px;
height: inherit;
position: relative;
}
.post_data
{
padding:24px;
border:1px solid #f9f9f9;
border-radius: 5px;
margin-bottom: 24px;
box-shadow: 0px 0px 5px #eeeeee;
}
**AJAX**
<script>
$(document).ready(function(){
var url = window.location.href;
var idx = url.indexOf("product");
var slugx = url.indexOf("product");
var slug = url.substring(idx).split("/")[1];
var line = url.substring(slugx).split("/")[2];
var limit = 8;
var start = 0;
var action = 'inactive';
function lazy_load(limit){
var output = '';
for(var count = 0; count < limit; count++)
{
output += '<div class="post_data col-md-4 col-12">';
output += '<p><span class="content-placeholder" style="width:90%; height: 30px;"> </span></p>';
output += '<p><span class="content-placeholder" style="width:90%; height: 80px;"> </span></p>';
output += '</div>';
}
$('#load_data_msg').html(output);
}
lazy_load(limit,slug,line);
function load_data(limit,start,slug,line)
{
$.ajax({
url:BASE_URL+'front/Products/fetch',
method:"POST",
data:{limit:limit,start:start,slug:slug,line:line},
cache: false,
success:function(data)
{
if(data == '')
{
$('load_data_msg').html('<h3> No Product is available </h3>');
}
else{
$('#fetchedprodducts').append(data);
$('#load_data_msg').html("");
action = 'inactive';
}
}
});
}
if(action == 'inactive')
{
action = 'active';
load_data(limit, start,line,slug);
}
$(window).scroll(function(){
if($(window).scrollTop() + $(window).height() > $("#load_data").height() && action == 'inactive')
{
lazy_load(limit);
action = 'active';
start = start + limit;
setTimeout(function(){
load_data(limit, start);
}, 1000);
}
});
});
</script>
**Controller**
public function fetch(){
$output ='';
$limit = $this->input->post('limit');
$start = $this->input->post('start');
$line = $this->input->post('line');
$slug = $this->input->post('slug');
$data = $this->Userfront_model->fetch_data($limit,$start ,$line,$slug);
if($data->num_rows() > 0){
foreach($data->result() as $row)
{
$output .= "<div class='post_data col-md-3 col-6'>
<a class='all-link--pro' href='" . site_url('product_view/' . $row->id . "/" . $row->slug ) . "'>
<img style='box-shadow: 0px 0px 22px 0px #616161' class='img-fluid img-size' src='" . base_url('assets/img/posts/' . $row->main_img) . " '>
<p>" . $row->title . "</p>
<p> <b>" . $row->uniquecode. "</b> </p>
<p>Rs " . $row->price. "</p>
</a>
</div>";
}
}
echo $output;
}
MODEL
function fetch_data($limit, $start,$line,$slug)
{
$this->db->order_by('cv_products.id', 'DESC');
$this->db->select('cv_products.*, cv_category.name as categoryname,product_line.id as lineid, product_line.name as linename,cv_category.id as category_id,delivery_time.id as deliverid, delivery_time.name as timingname' );
$this->db->join('cv_category','cv_category.id = cv_products.category', 'left');
$this->db->join('product_line','product_line.id = cv_products.product_line', 'left');
$this->db->join('delivery_time','delivery_time.id = cv_products.timing', 'left');
$this->db->from('cv_products');
$this->db->where('cv_products.product_line' , $line);
$this->db->where('product_line.slug' , $slug);
$this->db->limit($limit, $start);
$query = $this->db->get();
return $query;
}
I am able to fetch the first 8 products but unable to get the rest of the products while scrolling.
NOTE:
if i remove the where clause from model it work perfectly
You haven't passed the values line and slug to the function call load_data inside scroll method.
$(window).scroll(function(){
if($(window).scrollTop() + $(window).height() > $("#load_data").height() && action == 'inactive')
{
lazy_load(limit);
action = 'active';
start = start + limit;
setTimeout(function(){
load_data(limit, start, line, slug); // pass missing parameters here
}, 1000);
}
});

image in mPdf not showing in server though works well in localhost

In WordPress project I am using mPDF to generate pdf and send it as attachment via Mandrill. The only problem is Images aren't showing in pdf rather a square box with red cross is showing. But it works perfectly fine in localhost.
Code:
$html = create_html($quote);
function create_html($quote = NULL) {
$logo = get_field( 'logo', 'option' );
$image = get_field( 'image', 'option' );
$title = get_field( 'title', 'option' );
$sub_title = get_field( 'sub_title', 'option' );
$content_image = get_field( 'content_image', 'option' );
$content = get_field( 'content', 'option' );
$html = '<!DOCTYPE html><html>';
$html .= '<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>';
$html .= '<style>
body {
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
font-size14px;
line-height:1.5;
font-weight: normal;
}
.container {
max-width: 690px;
margin: 0 auto;
}
figure{
padding:0;
}
.mailContent {
float: left;
width: 100%;
}
.top-mail.centerAlign {
padding-top: 30px;
padding-bottom: 20px;
float: left;
width: 100%;
}
.mid-mail.centerAlign {
padding-top: 20px;
padding-bottom: 10px;
float: left;
width: 100%;
}
figure.mail-fig {
padding-bottom: 20px;
float: left;
width: 100%;
}
.mailContent h1 {
color:#4A5467;
font-size: 85px;
padding-top: 20px;
padding-bottom: 30px;
float: left;
width: 100%;
font-weight: normal;
font-family: "CycloneBackground";
}
.mailContent .highlight-text {
padding-bottom: 30px;
max-width: 650px;
margin: 0 auto;
font-size: 22px;
line-height: 1.5;
}
.bot-mail {
border-top: 1px solid #eee;
// margin-top: 10px;
padding-top: 40px;
padding-bottom: 50px;
float: left;
width: 100%;
}
.blue-logo{
margin-right: 80px;
}
.bot-mail p, .top-mail-text p{
font-size: 16px;
overflow: hidden;
}
.wrapper690, .wrapper400{
max-width: 690px;
margin: 0 auto;
}
.wrapper400{
max-width: 400px;
}
img.db-comma {
padding-top: 10px;
padding-bottom: 12px;
}
.mailContent2 .top-mail.centerAlign {
padding-bottom: 30px;
}
.centerAlign{
text-align: center;
}
.fLeft{
float:left;
}
</style>';
$html .= '</head>';
$html .= '<body>';
$html .= '<div class="container"><div class="row"><div class="col-sm-12">';
if(!empty($quote)) {
$html .= '<div class="mailContent wrapper690 mailContent2">';
$html .= '<div class="top-mail centerAlign">';
$html .= '<img src="'.$logo.'" alt="" class="fLeft">';
$html .= '<div class="wrapper400 fRight top-mail-text">';
$html .= '<img src="'.get_stylesheet_directory_uri().'/assets/images/db-comma.PNG" alt="double comma" class="db-comma">';
$html .= $quote;
$html .= '</div>';
$html .= '</div>';
} else {
$html .= '<div class="mailContent wrapper690">';
$html .= '<div class="top-mail centerAlign"><img src="'.$logo.'" alt=""></div>';
}
$html .= '<div class="mid-mail centerAlign">';
$html .= '<figure class="mail-fig"><img src="'.$image.'" alt=" group"></figure>';
if(!empty($title)) {
// $html .= '<h1>'.$title.'</h1>';
$html .= '<h1>test</h1>';
}
if(!empty($sub_title)) {
$html .= '<p class="highlight-text">'.$sub_title.'</p>';
}
$html .= '</div>';
$html .= '<div class="bot-mail">';
if(!empty($content_image)) {
$html .= '<img src="'.$content_image.'" alt=" logo blue" class="fLeft blue-logo">';
}
if(!empty($content)) {
$html .= $content;
}
$html .= '</div>';
$html .= '</div>';
$html .= '</div></div></div>';
$html .= '</body>';
$html .= '</html>';
return $html;
}
$mpdf = new mPDF();
$mpdf->SetDisplayMode('real');
$html = mb_convert_encoding($html, 'UTF-8', 'UTF-8');
$mpdf->WriteHTML($html);
ob_clean();
$path_certificate = ABSPATH."certificates/";
$certificate_filename = 'Gåvobevis_'.$_SESSION['first_name'].'_'.$_SESSION['last_name'].'_'.uniqid();
$certificate_filename = $certificate_filename.'.pdf';
$mpdf->Output($path_certificate.$certificate_filename, 'F');
mail sending:
$attachment = file_get_contents($path_certificate.$certificate_filename);
$attachment_encoded = base64_encode($attachment);
$params = array(
'html' => $message,
"text" => null,
"from_email" => $from,
"from_name" => "Admin",
"subject" => $subject,
"to" =>array(array('email' => $to )),
"track_opens" => true,
"track_clicks" => true,
"auto_text" => true,
"attachments" => array(
array(
'content' => $attachment_encoded,
'type' => "application/pdf",
'name' => $certificate_filename,
)
)
);
I am getting image from admin as custom option. Image url is coming as : http://xxx.xx.x.xxx/projectname/wp-content/uploads/2017/08/e-img1.png
Any help/suggestions are welcome. Thanks in advance.
is the image link http://xxx.xx.x.xxx/projectname/wp-content/uploads/2017/08/e-img1.png local ... meaning is that the same server running mpdf. if so, that path may not be accessible. try using an internal path to in image, and actually wordpress will probably be happy with a relative path to its root; (e.g. /wp-content/uploads/2017/08/e-img1.png)
if that is not an issue ... perhaps your live server lacks the graphics library for rendering, which was discussed here; mPDF 5.7.1 - image displays as a broken [x]
My images also worked only in localhost. I think it has something to do with ssl. Anyway, if anyone needs a solution: https://mpdf.github.io/what-else-can-i-do/images.html#image-data-as-a-variable
Essentialy you get the content of an image file outside of a template and then pass it there as a variable:
$mpdf->imageVars['myvariable'] = file_get_contents('alpha.png');
In template:
<img src="var:myvariable" />
For me the problem is permission error in some of the mPDF folder.
Ensure that you have write permissions set for the following folders:
/ttfontdata/
/tmp/
/graph_cache/
https://mpdf.github.io/installation-setup/installation-v6-x.html
Hope this helps.
For me the only solution that worked was using the relative path on the server:
/var/www/www.domain.com/myimg.jpg

rss feed pulls in featured posts but need limited description

I figured out how to limit my post words. The problem I am having is that my css code almost centers the 3 posts but it still favors the left side a little. These will not be the colors that I will be using they are just helping me with layout. If anyone could help in anyway it would be greatly appreciated!
Here is the php code
<section id="blog">
<div class="container-fluid">
<div class="row">
<div id="blog_title">
Featured Posts
</div><!--END BLOG TITLE-->
<div id="featured_posts">
<?php
// output RSS feed to HTML
output_rss_feed('http://www.bmcsquincy.com/featured_posts/feed', 20, true, true, 200);
// Check http://www.systutorials.com/136102/a-php-function-for-fetching-rss-feed-and-outputing-feed-items-as-html/ for description
// RSS to HTML
/*
$item_cnt: max number of feed items to be displayed
$max_words: max number of words (not real words, HTML words)
if <= 0: no limitation, if > 0 display at most $max_words words
*/
function get_rss_feed_as_html($feed_url, $max_item_cnt = 10, $show_date = true, $show_description = true, $max_words = 0, $cache_timeout = 7200, $cache_prefix = "/tmp/rss2html-")
{
$result = "";
// get feeds and parse items
$rss = new DOMDocument();
$cache_file = $cache_prefix . md5($feed_url);
// load from file or load content
if ($cache_timeout > 0 &&
is_file($cache_file) &&
(filemtime($cache_file) + $cache_timeout > time())) {
$rss->load($cache_file);
} else {
$rss->load($feed_url);
if ($cache_timeout > 0) {
$rss->save($cache_file);
}
}
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
);
$content = $node->getElementsByTagName('encoded'); // <content:encoded>
if ($content->length > 0) {
$item['content'] = $content->item(0)->nodeValue;
}
array_push($feed, $item);
}
// real good count
if ($max_item_cnt > count($feed)) {
$max_item_cnt = count($feed);
}
$result .= '<ul class="feed-lists">';
//ADDED THIS FOR POST AMOUNT
$max_item_cnt = 3;
$max_words = 25;
for ($x=0;$x<$max_item_cnt;$x++) {
$title = str_replace(' & ', ' & ', $feed[$x]['title']);
$link = $feed[$x]['link'];
$result .= '<li class="feed-item">';
$result .= '<div class="feed-title"><strong>'.$title.'</strong></div>';
if ($show_date) {
$date = date('l F d, Y', strtotime($feed[$x]['date']));
$result .= '<small class="feed-date"><em>Posted on '.$date.'</em></small>';
}
if ($show_description) {
$description = $feed[$x]['desc'];
$content = $feed[$x]['content'];
// find the img
$has_image = preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $content, $image);
// no html tags
$description = strip_tags($description, '');
// whether cut by number of words
if ($max_words > 0) {
$arr = explode(' ', $description);
if ($max_words < count($arr)) {
$description = '';
$w_cnt = 0;
foreach($arr as $w) {
$description .= $w . ' ';
$w_cnt = $w_cnt + 1;
if ($w_cnt == $max_words) {
break;
}
}
$description .= " ...";
}
}
// add img if it exists
//ADDED THE P IN DESCRIPTION LINE TO FOR A BREAK BY IMAGE
if ($has_image == 1) {
$description = '<p> <img class="feed-item-image" src="' . $image['src'] . '" /></p>' . $description;
}
$result .= '<div class="feed-description">' . $description;
//ADDED THE P IN THIS TO LINE BREAK CONTINUE READING
$result .= '<p> Continue Reading »</p>'.'</div>';
}
$result .= '</li>';
}
$result .= '</ul>';
return $result;
}
function output_rss_feed($feed_url, $max_item_cnt = 10, $show_date = true, $show_description = true, $max_words = 0)
{
echo get_rss_feed_as_html($feed_url, $max_item_cnt, $show_date, $show_description, $max_words);
}
?>
</div><!--END FEATURED POSTS-->
<div class="col-md-12 col-sm-12 col-xs-12" id="blog_btn_section">
<div id="btn_see_work" class="col-md-12 text-center"><a class="button btn btn-default btn-md wp5 delay-3s" id="btn-intro" href="./contact.php" target="_top">SEE MORE
</a>
</div><!--END BUTTON-->
</div><!--END COL SPAN-->
</div><!--END ROW-->
</div><!--END CONTAINER-->
</section><!--END SECTION BLOG-->
Here is my CSS that is giving me alignment troubles
#blog {
background-color: yellow;
color: #dbdbdb;
width: 100%;
padding-top: 50px;
padding-bottom: 50px;
margin: 0px auto 0px auto;
}
#blog_title {
text-align: center;
font-family: pathwaygothic;
font-size: 2em;
color: green;
padding-bottom: 50px;
}
#blog_btn_section {
padding-top: 50px;
}
#featured_posts {
background-color: pink;
max-width: 1200px;
margin: 0px auto 0px auto;
padding: 5px;
}
#featured_posts ul {
display: inline-block;
margin: 0px auto 0px auto;
text-align: center;
padding: 0px;
}
#featured_posts li {
list-style-type: none;
text-align: left;
padding: 30px;
float: left;
font-family: pathwaygothic;
font-size: 1em;
background-color: purple;
max-width: 1200px;
margin-left: 25px;
}
.feed-lists {
background-color: aqua;
width: 100%;
}
.feed-title a {
color: red;
}
.feed-date {
color: aqua;
}
.feed-description {
width: 300px;
}
.feed-lists li {
background-color: green;
}
.feed-item-image:hover {
opacity: .5;
background-color: #333333;
transition: 0.5s ease;
}

Can you use phpmyadmin to put wordpress posts to an external site?

I know it may be a stupid question. I have a website that I have built in PHP and I have a section that I would like 3 responsive posts to pull in from Wordpress.
I have tried using API and JSON curls and not having any luck, mostly because I lack knowledge on those things. Didn't know if it could be easier to pull into PHPMyAdmin then I could code to pull in the info from that and make it responsive?
If I were doing this I would rig my WordPress site to publish an RSS feed of the articles you're trying to present, and use some JavaScript to present that feed on your customized PHP web site.
There are WordPress plugins and JavaScript components available to do all that.
So here is my revised php
<section id="blog">
<div class="container-fluid">
<div class="row">
<div id="featured_posts">
<?php
// output RSS feed to HTML
output_rss_feed('http://www.bmcsquincy.com/featured_posts/feed', 20, true, true, 200);
// Check http://www.systutorials.com/136102/a-php-function-for-fetching-rss-feed-and-outputing-feed-items-as-html/ for description
// RSS to HTML
/*
$item_cnt: max number of feed items to be displayed
$max_words: max number of words (not real words, HTML words)
if <= 0: no limitation, if > 0 display at most $max_words words
*/
function get_rss_feed_as_html($feed_url, $max_item_cnt = 10, $show_date = true, $show_description = true, $max_words = 0, $cache_timeout = 7200, $cache_prefix = "/tmp/rss2html-")
{
$result = "";
// get feeds and parse items
$rss = new DOMDocument();
$cache_file = $cache_prefix . md5($feed_url);
// load from file or load content
if ($cache_timeout > 0 &&
is_file($cache_file) &&
(filemtime($cache_file) + $cache_timeout > time())) {
$rss->load($cache_file);
} else {
$rss->load($feed_url);
if ($cache_timeout > 0) {
$rss->save($cache_file);
}
}
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
);
$content = $node->getElementsByTagName('encoded'); // <content:encoded>
if ($content->length > 0) {
$item['content'] = $content->item(0)->nodeValue;
}
array_push($feed, $item);
}
// real good count
if ($max_item_cnt > count($feed)) {
$max_item_cnt = count($feed);
}
$result .= '<ul class="feed-lists">';
//ADDED THIS FOR POST AMOUNT
$max_item_cnt = 3;
for ($x=0;$x<$max_item_cnt;$x++) {
$title = str_replace(' & ', ' & ', $feed[$x]['title']);
$link = $feed[$x]['link'];
$result .= '<li class="feed-item">';
$result .= '<div class="feed-title"><strong>'.$title.'</strong></div>';
if ($show_date) {
$date = date('l F d, Y', strtotime($feed[$x]['date']));
$result .= '<small class="feed-date"><em>Posted on '.$date.'</em></small>';
}
if ($show_description) {
$description = $feed[$x]['desc'];
$content = $feed[$x]['content'];
// find the img
$has_image = preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $content, $image);
// no html tags
$description = strip_tags($description, '');
// whether cut by number of words
if ($max_words > 0) {
$arr = explode(' ', $description);
if ($max_words < count($arr)) {
$description = '';
$w_cnt = 0;
foreach($arr as $w) {
$description .= $w . ' ';
$w_cnt = $w_cnt + 1;
if ($w_cnt == $max_words) {
break;
}
}
$description .= " ...";
}
}
// add img if it exists
//ADDED THE P IN DESCRIPTION LINE TO FOR A BREAK BY IMAGE
if ($has_image == 1) {
$description = '<p> <img class="feed-item-image" src="' . $image['src'] . '" /></p>' . $description;
}
$result .= '<div class="feed-description">' . $description;
//ADDED THE P IN THIS TO LINE BREAK CONTINUE READING
$result .= '<p> Continue Reading »</p>'.'</div>';
}
$result .= '</li>';
}
$result .= '</ul>';
return $result;
}
function output_rss_feed($feed_url, $max_item_cnt = 10, $show_date = true, $show_description = true, $max_words = 0)
{
echo get_rss_feed_as_html($feed_url, $max_item_cnt, $show_date, $show_description, $max_words);
}
?>
</div><!--END FEATURED POSTS-->
</div><!--END ROW-->
</div><!--END CONTAINER-->
</section><!--END SECTION BLOG-->
Here is my css
#blog {
background-color: yellow;
color: #dbdbdb;
width: 100%;
padding-top: 100px;
padding-bottom: 100px;
margin: 0px auto 0px auto;
}
#featured_posts {
background-color: pink;
max-width: 1200px;
margin: 0px auto 0px auto;
padding: 5px;
}
#featured_posts ul {
display: inline-block;
margin: 0px auto 0px auto;
text-align: center;
padding: 0px;
}
#featured_posts li {
list-style-type: none;
text-align: left;
padding: 30px;
float: left;
font-family: pathwaygothic;
font-size: 1em;
background-color: purple;
max-width: 1200px;
margin-left: 25px;
}
.feed-lists {
background-color: aqua;
width: 100%;
}
.feed-title a {
color: red;
}
.feed-date {
color: aqua;
}
.feed-description {
width: 300px;
}
.feed-lists li {
background-color: green;
}

not getting suitable output in fetching image and its description

I want to display images and their description(on hover) dynamically in a localhost application.
I am getting a vertical output:
but I want the images to be show horizontally (to a certain extent), like this:
I tried the following
PHP
<?php
$c = mysql_connect("localhost", "abc", "xyz");
mysql_select_db("root");
$q = "select * from product";
$qc = mysql_query($q);
$count = 0;
while ($ans = mysql_fetch_array($qc)) {
if ($count == 0 || $count == 1 || $count == 2) {
$title = $ans[1] . " " . $ans[2];
print '<div class="img-wrap">';
print "<img id='display_img' src='products/$ans[8]'width=300 height=200 title='$title'>";
print '<div class="img-overlay">';
print '<h4>' . $title . '</h4>';
print '<p>' . $ans[9] . '</p>';
print '</div>';
print '</div>';
}
$count++;
if ($count == 3) {
print "<br />";
$count = 0;
}
}
?>
CSS
.img-wrap {
height:200px;
position:relative;
width:300px;
margin:10px;
}
.img-overlay {
background-color:#000;
bottom:0;
color:#fff;
height:200px;
width:300px;
opacity:0;
position:absolute;
z-index:1000;
transition-duration:0.5s;
cursor:pointer;
}
.img-overlay h4, .img-overlay p {
padding:0 10px;
}
.img-wrap:hover .img-overlay {
opacity:0.75;
transition:opacity 0.5s;
}
b {
background-color:#aa490e;
color:#fff;
font-size:36px;
padding: 0 15px;
padding-left:65px;
padding-bottom:25px;
font-family:"Courier New", Courier, monospace;
}
Try changing .img-wrap as following:
.img-wrap
{
float:left;
clear:none;
height:200px;
position:relative;
width:300px;
margin:10px;
}
You can add display: inline-block to .img_wrap:
.img-wrap {
...
display: inline-block;
}
Or you can use float: left. But in this case make sure you clear: both after the last item.
http://jsfiddle.net/tRRVv/

Categories