Inserting mysql inside a div inside an array - html

I have created a database to access the images inside a slider which uses jquery. The problem starts when I try to insert the connection given that it is an array:
<?php
$slides = array(
'<div data-thumb="images/slider/slides/image1_small.jpg" data-src="images/slider/slides/image1.jpg">
<div class="camera_caption fadeFromBottom">
Text 1 below image
</div>
</div>',
'<div data-thumb="images/slider/slides/image2_small.jpg" data-src="images/slider/slides/image2.jpg">
<div class="camera_caption fadeFromBottom">
Text 2 below image
</div>
</div>',
'<div data-thumb="images/slider/slidesimage3_small.jpg" data-src="images/slider/slides/image3.jpg">
<div class="camera_caption fadeFromBottom">
Text 3 below image
</div>
</div>'
);
shuffle($slides);
foreach ($slides as $slides) {
echo "$slides\n";
}
?>
My question is, is there a way to change that array to access the images and the text? I've tried with a while loop but couldn't figure it out.
Update: What I want is to change the array to
<?php
$query = "SELECT * FROM tblslider";
if ($result=mysqli_query($connection, $query)) {
while ($slides = mysqli_fetch_array($result)) {
'<div data-thumb="images/slider/slides/<? echo $row_DataSlider['strImagesmall'] ?>" data-src="images/slider/slides/<? echo $row_DataSlider['strImage'] ?>">
<div class="camera_caption fadeFromBottom">
<? echo $row_DataSlider['strText'] ?>
</div>
</div>'
}
}
?>
obviously this is not possible but im looking for a solution to get something like it

I believe you have a typo in your foreach...foreach ($slides as $slides) (using $slides twice)
I'd put:
foreach ($slides as $s) {
echo $s . "</br>";
}

Related

Display latest wordpress featured images on static html page

I have a wordpress blog page installed in subfolder of my website(converted from html)and a static html home page.
I would like to display 3 latest posts and its featured images on home page. With code below i can display latest posts text but i dont know how to show featured images of posts. Into index.php of a wordpress custom theme i placed featured photo inside a div:
<div id="blogphoto"><?php the_post_thumbnail(); ?></div>
This is the code on static html index.php page which is pulling out latest post. Can anyone help me to get featured images of these posts too?
<div id="wp-post">
<?php
$args = array('numberposts'=>1);
$recent_posts=wp_get_recent_posts($args);
foreach( $recent_posts as $recent_post ){
echo "<h3>".$recent_post['post_title']."</h3> <br>";
echo "<span>".$recent_post['post_date']."</span> <br>";
echo "<p>".$recent_post['post_content']."</p><br><br>";
}
?>
</div>
<div id="wp-post2">
<?php
$args = array('numberposts'=>1 , 'offset'=>1 );
$recent_posts=wp_get_recent_posts($args);
foreach( $recent_posts as $recent_post ){
echo "<span>".$recent_post['post_title']."</span> <br>";
echo "<p>".$recent_post['post_content']."</p><br><br>";
}
?>
</div>
<div id="wp-post3">
<?php
$args = array('numberposts'=>1 , 'offset'=>2 );
$recent_posts=wp_get_recent_posts($args);
foreach( $recent_posts as $recent_post ){
echo "<span>".$recent_post['post_title']."</span> <br>";
echo "<p>".$recent_post['post_content']."</p><br><br>";
}
?>
</div>
Please try to this code the_post_thumbnail getting the feature image
<?php
if ( $query->have_posts() ) {
$i = 1;
while($query->have_posts()) {
echo '<div id="wp-post-'.$i.'">';
$query->the_post();
?><h2><?php the_title(); ?></h2>
<?php
if ( has_post_thumbnail() ) { // only print out the thumbnail if it actually has one
echo '<p>post says it has a featured image</p>'; // double checking
the_post_thumbnail('thumbnail');
} else {
echo '<p>this post does not have a featured image</p>';
}
echo '</div>';
$i++;
}
} else {
echo '<p>no posts found</p>';
}
?>

Wordpress: previous_post_link() sits on top, after div "entry-content", no matter where I place it

I have installed a plugin which is custom post type, I am trying to use the previous_post_link() and next_post_link() to get previous and next posts.
It is working fine but the only problem is that I am placing it in my 4th div container where as it always sits on top of page right after div "entry-content".
Is it a known issue?
Here is the piece of code:
function some_function () {
global $post;
if ('team' == get_post_type() && is_single() && in_the_loop()) {
$fields = WPMTPv2_OPTIONS()->fields;
$meta = WPMTPv2_FIELDS($post->ID);
$tmp = '<div id="wpmtp-single-wrap">';
$tmp .= '<div class="wpmtp-vcard">';
$tmp .= '<div class="wpmtp-vcard-left">';
$tmp .= wpmtpv2_featured_img($post->ID);
$previous = previous_post_link('%link', '<div class="wpmtp-gonext">view next</div>');
$next = next_post_link('%link', '<div class="wpmtp-goback">go back</div>');
// $tmp .= '<div class="wpmtp-goback">go back</div>';
// $tmp .= '<div class="wpmtp-gonext">view next</div>';
$tmp .= $previous;
$tmp .= $next;
$tmp .= '</div>';
...........
..........
..........
........
return $tmp;
}
If I place the commented html code instead or previous and next functions, it works fine. Which mean that html and css are right in place, and the problem is in the functions I guess.
And this is what I get after inspecting it in firebug:
<article .....>
<h2 .....></h2>
<div class="meta"></div>
<div class="entry-content">
<a href="link to next" rel="prev">
<div class="wpmtp-gonext">view next</div>
</a>
<a href="link to previous" rel="next">
<div class="wpmtp-goback">go back</div>
</a>
<div id="wpmtp-single-wrap">
<div class="wpmtp-vcard">
<div class="wpmtp-vcard-left">
.....
....
....
....
try this code:
<?php
function some_function () {
global $post;
if ('team' == get_post_type() && is_single() && in_the_loop()) {
$fields = WPMTPv2_OPTIONS()->fields;
$meta = WPMTPv2_FIELDS($post->ID);
?>
<div id="wpmtp-single-wrap">
<div class="wpmtp-vcard">
<div class="wpmtp-vcard-left">
<?php echo wpmtpv2_featured_img($post->ID); ?>
<div class="wpmtp-goback"><?php previous_post_link( '%link', __( ' go back', 'twentyeleven' ),TRUE ); ?></div>
<div class="wpmtp-gonext"><?php next_post_link( '%link', __( 'view next', 'twentyeleven' ),TRUE ); ?></div>
<?php
// replace **twentyeleven** with your theme name
//or try with this line
//previous_post_link('%link', '<div class="wpmtp-gonext">view next</div>');
//next_post_link('%link', '<div class="wpmtp-goback">go back</div>');
?>
</div>
<?php
.........
.........
........
return $tmp;
}
or best to try this plugin : wp-pagenavi
This plugin provides the wp_pagenavi() template tag which generates fancy pagination links.
thanks

How to Display Custom Post Type's Gallery (images ) in Through WP_Query

I am trying to load an Image Slider images from a Custom Post Type image Gallery Feature. For example let say I have an Custom Post Type called banner which I can load images to it's Gallery and I have an HTML code like this:
<div class="item active">
<img src="assets/img/ban1r.jpg" alt="">
<div class="carousel-caption">
slide 1
</div>
</div>
<div class="item active">
<img src="assets/img/ban2r.jpg" alt="">
<div class="carousel-caption">
slide 1
</div>
</div>
Can you please let me know how I can use the custom WP_Query to retrive the images from the custom post and load them into slider instead of above HTML?
So far I have done something like this but it is not displaying any image!
<?php
$args = array( 'post_type' => 'banner');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$gallery = get_post_gallery_images($post);
foreach( $gallery as $image ) {
echo '<div class="item active">';
echo '<img src="' . $image . '">';
echo '</div>';
}
endwhile;
?>
I tried something like this before 2 months ago, and working great for me.
global $wpdb;
$query = "select * from $wpdb->posts
where
post_type = 'banner' and
post_status = 'publish'";
$results = $wpdb->get_results($query, ARRAY_A);
foreach( $results as $result ){
echo '<div id="'.$result['ID'].'" class="listen">';
echo get_the_post_thumbnail( $result['ID'], array(200, 200) );
</div>';
}
Take a look on get_the_post_thumbnail

Random Color CSS - Prevent Using Twice

I asked a question previously - HERE - about how I could set my border-color to a random color. I have this working.
As you'll see, I have a possible 7 colors in my array. How can I edit my code so that once a color has been chosen, it won't be reused. There are 3 divs on my page that the color will be used on, so I'd like 3 different colors from the possible 7.
Full code of how I'm using it:
<div id="featured-posts" class="container_12">
<?php
global $post;
$myposts = get_posts('numberposts=3&category=12');
foreach($myposts as $post) :
?>
<?php global $post; ?>
<?php
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 5600,1000 ), false, '' );
?>
<?php
$colors = array("#000000", "#949c51", "#571c1e", "#f36533", "#782a80", "#f6a41d", "#ed1b24");
$randomColor = $colors[array_rand($colors)];
?>
<a href="<?php the_permalink(); ?>">
<div class="grid_4 featured-home" style="background: url(<?php echo $src[0]; ?> ) !important;">
<div class="featured-details" style="border-color: <?php echo $randomColor; ?>;">
<h4 style="color: <?php echo $randomColor; ?>;"><?php the_title(); ?></h4>
<p><?php the_excerpt(); ?> <q style="color: <?php echo $randomColor; ?>; font-weight:bold !important;">Read more ></q></p>
</div>
<div class="featured-lower" style="border-color: <?php echo $randomColor; ?>;"></div>
</div></a>
<?php endforeach; ?>
</div>
You could shuffle and then pop the last element off the array each time:
Define your colours array once (this would need to be removed from your loop):
$colors = array("#000000", "#949c51", "#571c1e", "#f36533", "#782a80", "#f6a41d", "#ed1b24");
Then each time you use randomColor you shuffle it and remove the last element of the array to use:
shuffle($colors);
$randomColor = array_pop($colors);
You have to add a function where a random color is choosen from the array, deleted from array and returned. Then you have to call this function on your inline-style settings.
But you should really avoid inline-styles. You could also do something like this with SASS in a far more cleaner way.

How to wrap every 3 div's contents in a div?

I need every three divs of class "loopcontent" to be wrapped in a new div of class "threeacross". I'm new to WordPress and really not a PHP guy yet, but I'm learning as I go.
Here's my loop:
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<div class="loopcontent">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
} else {
// the current post lacks a thumbnail
}
?>
<h1><?php the_title(); ?></h1>
<?php the_excerpt(); ?>
</div>
<?php endwhile; else : ?>
<div class="loopcontent">
<h1>Page Not Found</h1>
<p>Looks like the page you're looking for isn't here anymore. Try browsing the categories, archives, or using the search box below.</p>
<?php include(TEMPLATEPATH.'/searhform.php'); ?>
</div>
<?php endif; ?>
Something like this should work. This keeps a running count and places your div wraps every three posts. Let me know if this helps. If not, let me know what it's outputting, and I can tweak it:
<?php
if(have_posts()) : for($count=0;have_posts();$count++) : the_post();
$open = !($count%3) ? '<div class="threeacross">' : ''; //Create open wrapper if count is divisible by 3
$close = !($count%3) && $count ? '</div>' : ''; //Close the previous wrapper if count is divisible by 3 and greater than 0
echo $close.$open;
?>
<div class="loopcontent">
<?php
if(has_post_thumbnail()) the_post_thumbnail();
else{
// the current post lacks a thumbnail
}
?>
<h1><?php the_title(); ?></h1>
<?php the_excerpt(); ?>
</div>
<?php endfor; else : ?>
<div class="loopcontent">
<h1>Page Not Found</h1>
<p>Looks like the page you're looking for isn't here anymore. Try browsing the categories, archives, or using the search box below.</p>
<?php include(TEMPLATEPATH.'/searhform.php'); ?>
</div>
<?php endif; ?>
<?php echo $count ? '</div>' : ''; //Close the last wrapper if post count is greater than 0 ?>