I have a created a custom post type with team members and I want to hover on one member and show the overlay-text for that member, then over on the next member show the overlay text for the next member and so on.
Right now when I hover over a random team member it shows all the "overlay-text" divs :
Here is my code:
<?php
$loop = new WP_Query( array( 'post_type' => 'team', 'orderby'=>'post_id', 'order'=>'ASC' ) );
if($loop->have_posts() ) :
while($loop->have_posts() ) : $loop->the_post(); ?>
<div class="col-sm-4">
<div class="team-member">
<div class="member-img">
<?php the_post_thumbnail(); ?>
</div>
<h4><?php the_title(); ?></h4>
<?php the_content(); ?>
<div class="overlay-text">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem maxime id accusantium voluptates. Assumenda, maiores illum nemo aspernatur pariatur. Magnam nihil, enim rerum cupiditate reprehenderit animi dolorum eveniet, voluptas explicabo.</p>
</div>
</div>
</div>
<?php endwhile;
endif;
?>
I know the overlay-text paragraph is hard coded I am trying to find a solution to this also.
CSS for overlay-text:
.team-member .overlay-text {
opacity: 0;
visibility: hidden;
background: rgba(15, 175, 151, 0.95) none repeat scroll 0 0;
color: #fff;
bottom: 0;
left: 15px;
padding: 15px;
position: absolute;
right: 15px;
top: 0;
transition: all 0.5s ease-in-out 0s;
}
.team-member .overlay-text.active {
opacity: 1;
visibility: visible;
}
Javascript for overlay text:
function showOverlay() {
jQuery('.team-member').hover(function(){
jQuery('.overlay-text').addClass('active');
},
function(){
jQuery('.overlay-text').removeClass('active');
});
}
you need this so it only adds the class to that specific one
JS:
function showOverlay() {
$('.team-member').on('mouseenter',function(){
$(this).find('.overlay-text').addClass('active');
}).on('mouseleave',function(){
$(this).find('.overlay-text').removeClass('active');
});
}
Related
I'm trying to create a PHP page that displays 6 data from a table at a time however there is a problem with the layout of how these data are displayed, I believe this problem comes from the styling
The layout is supposed to look something like this:
Screen shot 01
Screen shot 02
I have tried playing around with every single div element on the code below, however, I am unable to find the right width that the data is displayed like the image, right now I'm not sure anymore where the problem with the layout comes from.
This is how it looks like:
Screen shot
PHP:
<div id="greenLine"></div>
<div id="content">
<div class="container">
<form action="search_product.php" method="post"> <!--Action: Sent to "search_product.php" Method: The data will be displayed by "post"-->
<label>Search Product:<br></label>
<input type="text" name="search" placeholder="Enter Product Name"> <!--The name of the numbers inputted are "nilai"-->
<input type="submit" id="submit" name="submit" value="Submit">
</form>
<?php
$koneksi = new mysqli ("localhost","REDACTED","REDACTED","cm0491_progress_business_db_2");
$sql = "SELECT * FROM `product_tbl` LIMIT 6";
$querynews = $koneksi->query($sql);
$rownews = $querynews->fetch_assoc();
// var_dump($rownews); exit;
do {
?>
<div class="product_item">
<div class="number_icon"><?php echo $rownews['id_product']; ?></div>
<h2 class="product_title"><?php echo $rownews['name_product']; ?></h2>
<img src="images/<?php echo $rownews['gambar_product']; ?>"width="200"><br>
<p class="product_desc"><?php echo $rownews['description_product']; ?>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore.
</p>
Read More<br><br><br>
</div>
<?php }while($rownews = $querynews->fetch_assoc()); ?>
</div>
<!--- END CONTENT WRAPPER -->
</div>
CSS:
#greenLine { background:url(../images/bg_top_img.jpg) center no-repeat #305D00; height:20px;}
#content { background:#fff; min-height:500px; margin-left:0%;}
.container {width:1200px; height:100%;margin:auto; overflow:auto; overflow-y:hidden; overflow-x:hidden; margin-left:20%;}
.product_item { min-height:280px; width:270px; margin:20px; float:left;}
.number_icon { height:56px; width:56px; background:url(../images/dropcap1.gif); text-align:center; font-size:43px; float:left; margin-bottom:10px; color:#FFF; }
.product_desc { line-height:20px; min-height:60px; color:#696969; margin-top:10px; font-size:14px; font-style:italic; auto;}
I'm genuinely confused with what's happening to the layout and would greatly appreciate anyone willing to help, thank you.
P.S Avoid posting database variables or passwords
Use flex to achieve consistent results, I have your removed php codes for simplicity, just echo where necessary
.product_item{
display:flex;
flex-direction:column;
}
.product_item .title_area{
display:flex;
flex:1;
align-items: center;
}
.product_item .number_icon{
background:green;
width:20px;
height:20px;
border-radius:50%;
color:white;
text-align:center;
line-height:20px;
margin-right:5px;
}
.product_item img{
width:100%;
max-height:200px;
object-fit:cover;
}
<div class="container">
<div class="product_item">
<div class="title_area">
<div class="number_icon">1</div>
<h2 class="product_title">Furniture</h2>
</div>
<img src="http://placehold.it/200x150">
<p class="product_desc">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore.
</p>
Read More<br><br><br>
</div>
</div>
<!--- END CONTENT WRAPPER -->
</div>
I have a controller for homepage which gives $posts var which includes that post title and body and sometimes there may be a large amount of text in the body
return view('posts.index',compact('posts'));
and I want to hide all paragraph text and add a button called ReadMore which shows full paragraph
I saw the following bootstrap examples
function myFunction() {
var dots = document.getElementById("dots");
var moreText = document.getElementById("more");
var btnText = document.getElementById("myBtn");
if (dots.style.display === "none") {
dots.style.display = "inline";
btnText.innerHTML = "Read more";
moreText.style.display = "none";
} else {
dots.style.display = "none";
btnText.innerHTML = "Read less";
moreText.style.display = "inline";
}
}
<h2>Read More Read Less Button</h2>
<p>Lorem ipsum imperdiet, nulla et dictum interdum, nisi lorem egestas vitae scel<span id="dots">...</span><span id="more">erisque enim nibh tempor porta.</span></p>
<button onclick="myFunction()" id="myBtn">Read more</button>
in the above example text there is span id in middle and here I don't know how do I add that span between $post->body data. is there any way to make a ReadMore and ShowLess feature?
I am currently showing data as
<p>{!!$post->body!!} </p>
Try something like given below code:
{{ substr( $post->body, 0, random_int(60, 150)) }}
And for read more you can link the single article in anchor tag:
Read more
I have a CSS approach. You can set a CSS class to style it as an truncated text (when the max height exceeded with long text):
.post .post-short-description {
height: 36px;
display: -webkit-box;
overflow: hidden;
text-overflow: ellipsis;
-webkit-line-clamp: 2; /* How many lines before truncated */
-webkit-box-orient: vertical;
}
In your view.blade.php:
#php
$hasLongBody = strlen($p->body) >= 150;
#endPhp
<div class="post">
<h3> {{ $p->title }} </h3>
<p class="post-short-description"> {{ $p->body }} </p>
<a href="{{ route('postDetail', $p->id) }}" #class([
'd-none' => !$hasLongBody
])> Readmore </a>
</div>
A client of mine wants a "project of the month" feature on his Wordpress site. But with a archive page.
My idea was to create a custom post type and call it projects. In here the client can manage projects and make new ones.
With this piece of code i can take the content from the latest project post, and put that content on the main "project of the month" page, while all the past projects are on the archive page.
$latest_cpt = get_posts("post_type=projects&numberposts=1");
$my_postid = $latest_cpt[0]->ID; //This is page id or post id
$content_post = get_post($my_postid);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
This works ... but not really.
The project pages are build using visual composer. And some of the elements have background colors or padding. Visual composer gives these elements unique classes like
.vc_custom_1516702624245
And adds the custom style tag when the page loads. Something like this
<style type="text/css" data-type="vc_shortcodes-custom-css">
.vc_custom_1516711125312 {
padding-top: 75px !important;
padding-bottom: 75px !important;
background-color: #f3f5f6 !important;
}
.vc_custom_1516702624245 {
background-color: #f3f5f6 !important;
}
.vc_custom_1516711013808 {
margin-top: -106px !important;
}
.vc_custom_1516702490896 {
padding-left: 50px !important;
}
.vc_custom_1516703325534 {
margin-top: -15px !important;
}
.vc_custom_1516702744160 {
background-position: center !important;
background-repeat: no-repeat !important;
background-size: cover !important;
}
.vc_custom_1516702987431 {
padding-right: 65px !important;
}
.vc_custom_1516709810401 {
border-radius: 3px !important;
}
</style>
The problem with my approach is that visual composer does not create the style tag for the post content that is being loaded.
So therefore a lot of minor styling details are lost.
Image: Page content on archive page (how it should look)
Image: Page content on "project of the month" page
TL:DR visual composer style not generating post_content
You can use part of the addShortcodesCustomCss function of Vc_base:
$shortcodes_custom_css = get_post_meta( $id, '_wpb_shortcodes_custom_css', true );
if ( ! empty( $shortcodes_custom_css ) ) {
$shortcodes_custom_css = strip_tags( $shortcodes_custom_css );
echo '<style type="text/css" data-type="vc_shortcodes-custom-css">';
echo $shortcodes_custom_css;
echo '</style>';
}
replacing $id with yours $my_postid and, if needed, the echo with $content .=
Heres a function combining what i've seen across various stack overflow topics.
If you are using WPBakery for a page builder and want to use the WP_JSON api to serve your content to the frontend such as Angular or React you need to do a few things.
Tell wordpress to render the WP Bakery shortodes into actual HTML
Tell wordpress to include the dynamically generated css classes in the API response.
To do this I simply did the following:
add_action( 'rest_api_init', function ()
{
register_rest_field(
'page',
'content',
array(
'get_callback' => 'compasshb_do_shortcodes',
'update_callback' => null,
'schema' => null,
)
);
});
function compasshb_do_shortcodes( $object, $field_name, $request )
{
WPBMap::addAllMappedShortcodes(); // This does all the work
global $post;
$post = get_post ($object['id']);
$output['rendered'] = apply_filters( 'the_content', $post->post_content );
$output['css'] = '';
$shortcodes_custom_css = get_post_meta( $object['id'], '_wpb_shortcodes_custom_css', true );
if ( ! empty( $shortcodes_custom_css ) ) {
$shortcodes_custom_css = strip_tags( $shortcodes_custom_css );
$output['css'] .= $shortcodes_custom_css;
}
return $output;
}
This basically returns the following:
"content": {
"rendered": "<div class=\"row\"><div class=\"col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>I am text block. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.</p>\n\n\t\t</div>\n\t</div>\n</div></div></div></div><div class=\"row\"><div class=\"col-sm-6\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>I am text block. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.</p>\n\n\t\t</div>\n\t</div>\n</div></div></div><div class=\"col-sm-6\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>I am text block. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.</p>\n\n\t\t</div>\n\t</div>\n</div></div></div></div><div class=\"row\"><div class=\"col-sm-4\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>I am text block. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.</p>\n\n\t\t</div>\n\t</div>\n</div></div></div><div class=\"col-sm-4 vc_col-has-fill\"><div class=\"vc_column-inner vc_custom_1631795792357\"><div class=\"wpb_wrapper\"><h2 style=\"text-align: left;font-family:Abril Fatface;font-weight:400;font-style:normal\" class=\"vc_custom_heading\" >This is custom heading element</h2>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>I am text block. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.</p>\n\n\t\t</div>\n\t</div>\n</div></div></div><div class=\"col-sm-4\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\"></div></div></div></div><div class=\"row\"><div class=\"col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\"><div style='color:#FF0000;' data-foo='something'></div></div></div></div></div>\n",
"css": ".vc_custom_1631795792357{background-color: #afafaf !important;}"
},
You can then use the html on your frontend for example using angular by creating a dynamic route that feeds the slug in as a parameter, then simply connect a resolver service to it to hit the api for that page, if it's found, render the page, if not redirect to a 404.
The css can then be added in on component load by appending to the head.
And hey presto, you get WpBakery powered Angular.
Also for SEO, you can use SSR and WP Yoast to control and append meta tags from the WP Admin.
Any questions or improvement suggestions let me know.
function usp_modify_post_type($post_type) {
return 'post,footer,header,page,product,'; // Edit post type as needed
}
add_filter('usp_post_type', 'usp_modify_post_type');
I am using the code snippet available here
My PHP code is :
<?PHP
/*** This is for bottomless listing of record from a table ****/
$sql = 'SELECT * FROM agency_list ORDER BY id DESC LIMIT 0, 5';
$query = $dbo4->prepare($sql); // dbo4 coming from config.php
$query->execute();
$list = $query->fetchAll();
?>
The relevant css code is:
.content {
padding: 10px;
min-height: 100px;
text-align: center;
}
#loader {
text-align: center;
display: none;
}
#items {
list-style: none;
text-align: left;
}
#items li {
margin: 0 0 10px 0;
background: #FFFFFF; /* original -- f1f0f0*/
border: 1px solid #999999;
border-radius: 5px;
color: #333333;
}
#items li h2 {
font-size: 18px;
padding: 5px;
}
#items li p {
padding: 5px;
}
The java script code (end-less-scroll.js) is as following:
var is_loading = false; // initialize is_loading by false to accept new loading
var limit = 5; // limit items per page
$(function() {
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
if (is_loading == false) { // stop loading many times for the same page
// set is_loading to true to refuse new loading
is_loading = true;
// display the waiting loader
$('#loader').show();
// execute an ajax query to load more statments
$.ajax({
url: 'load_more.php',
type: 'POST',
data: {last_id:last_id, limit:limit},
success:function(data){
// now we have the response, so hide the loader
$('#loader').hide();
// append: add the new statments to the existing data
$('#items').append(data);
// set is_loading to false to accept new loading
is_loading = false;
}
});
}
}
});
});
Above code is invoking load_more.php which has following code:
<?PHP
include 'config.php';
$last_id = $_POST['last_id'];
$limit = 5;
if (isset($_POST['limit']))
{
$limit = intval($_POST['limit']);
}
// selecting the items for page params
try
{
$sql = 'SELECT * FROM agency_list WHERE id > :last_id ORDER BY id DESC LIMIT 0, :limit';
$query = $dbo4->prepare($sql);
$query->bindParam(':last_id', $last_id, PDO::PARAM_INT);
$query->bindParam(':limit', $limit, PDO::PARAM_INT);
$query->execute();
$list = $query->fetchAll();
}
catch (PDOException $e)
{
echo 'PDOException : '. $e->getMessage();
}
$last_id = 0;
foreach ($list as $rs)
{
$last_id = $rs['id'];
?>
<li>
<h2> <a href='#'><?PHP echo '[' .$rs['id'] .'] ' . $rs['agency_nm']; ?></a>
<img height = "32px" width = "32px" src="images/face_smile_1.png"></h2>
<blockquote>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Et non ex maxima parte de tota iudicabis?
Item de contrariis, a quibus ad genera formasque generum venerunt. Sit enim idem caecus, debilis.
Duo Reges: constructio interrete.
<BR>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Et non ex maxima parte de tota iudicabis?
Item de contrariis, a quibus ad genera formasque generum venerunt. Sit enim idem caecus, debilis.
Duo Reges: constructio interrete.
</p>
</blockquote>
<h5> <?PHP echo $rs['agency_addr_landmark']; ?></h5>
<h5> <?PHP echo $rs['agency_city']. ' - ' . $rs['agency_pin'] . ' [' . $rs['agency_state'] . '] ' ; ?></h5>
<h5> <?PHP echo $rs['agency_contact_per_1']; ?></h5>
<h5> <font color = "maroon"><?PHP echo $rs['agency_contact_addr1'];?></font></h5>
<p style="align:right;">
Details
Update
More
</p>
<BR>
</li>
<BR>
<?PHP
}
if ($last_id != 0)
{
echo '<script type="text/javascript">var last_id = '.$last_id.';</script>';
}
// sleep for 1 second to see loader, it must be deleted in prodection
sleep(1);
?>
And finally the fetched records are being listed in this div (in HTML file)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript" src="js/end-less-scroll.js"></script>
<div class="row">
<div class="twelve columns">
<div class="content">
<ul id="items">
<?PHP
$last_id = 0;
foreach ($list as $rs)
{
$last_id = $rs['id']; // keep the last id for the paging
?>
<li>
<h2> <a href='#'><?PHP echo '[' .$rs['id'] .'] ' . $rs['agency_nm']; ?></a><img height = "32px" width = "32px" src="images/face_smile_1.png"></h2>
<blockquote>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Et non ex maxima parte de tota iudicabis? Item de contrariis, a quibus ad genera formasque generum venerunt. Sit enim idem caecus, debilis. Duo Reges: constructio interrete.
<BR>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Et non ex maxima parte de tota iudicabis? Item de contrariis, a quibus ad genera formasque generum venerunt. Sit enim idem caecus, debilis. Duo Reges: constructio interrete.
</p>
</blockquote>
<h5> <?PHP echo $rs['agency_addr_landmark']; ?></h5>
<h5> <?PHP echo $rs['agency_city']. ' - ' . $rs['agency_pin'] . ' [' . $rs['agency_state'] . '] ' ; ?></h5>
<h5> <?PHP echo $rs['agency_contact_per_1']; ?></h5>
<h5> <font color = "maroon"><?PHP echo $rs['agency_contact_addr1'];?></font></h5>
<p style="align:right;">
Details
Update
More
</p>
<BR>
</li>
<BR>
<?PHP
}
?>
<script type="text/javascript">var last_id = <?PHP echo $last_id; ?>;</script>
</ul>
<!-- this is the paging loader, now is hidden, it wiil be shown when we scroll to bottom -->
<p id="loader"><img src="images/ajax-loader.gif"></p>
</div><!-- content -->
<hr>
</div>
</div>
My problem is that
(1) The code is working perfectly fine if I sort the records by ASC order in both the MySQL queries given. However, if I change the sorting order from ASC (as given in the linked tutorial) to DESC, the logic only lists for 5 records, then first 4, 3, 2, 1 records again and stops work. I know I am doing something very silly in the logic, but unable to find my mistake. Please help me.
(2) Assume that I need to sort by some other column (which is not the PRIMARY key - id being PRIMARY KEY here) e.g. suppose I want to sort the records by agency_nm and the list them using this in the bottom less listing fashion, am I supposed to make some changes in AJAX part (or load_more.php) as well? Sorry but I am not good in AJAX - hence this silly question.
Thanks / Regards to all for your kind help and suggestions.
Change the line:
$sql = 'SELECT * FROM agency_list WHERE id > :last_id ORDER BY id DESC LIMIT 0, :limit';
$sql = 'SELECT * FROM agency_list WHERE id < :last_id ORDER BY id DESC LIMIT 0, :limit';
All you have to do is change this operator: > to <
I am trying to create a paragraph and next to that paragraph are images that are generated randomly from a database table. The main container is called ".container" and this includes every element. .container is set to width: 90%. The paragraph (.header) floats to the left and has a width of 70%. The generated images (.recommend) floats to the right and has a width of 30%. Everything works out fine, but the only problem is that when I set the images to take up the whole space of the .recommend div (width: 100%), but it doesn't do that. Instead, the width of the images are 30%. How do I make the images take up the whole space of the .recommend div?
<!DOCTYPE html>
<html>
<head><link type="text/css" rel="stylesheet" href="/science/template.css"></head>
<body>
<div class="container">
<div class="header">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div class="recommend">
<?php
$numArray = array();
for ($i = 1; $i <=10; $i++)
{
$numArray[$i] = $i;
}
shuffle($numArray);
$resultSet = $db->query("SELECT * FROM table");
if ($resultSet->num_rows != 0)
{
while ($rows = $resultSet->fetch_assoc())
{
$id = $rows["id"];
$image1 = $rows["image1"];
$image2 = $rows["image2"];
$image3 = $rows["image3"];
$title = $rows["title"];
$title2 = $rows["title2"];
$title3 = $rows["title3"];
echo "<div class=row>";
if ($id == $numArray[0])
{
echo "<div class=col-md-4 id=left><img src=$image1><p>$title</p></div>";
}
if ($id == $numArray[1])
{
echo "<div class=col-md-4 id=left><img src=$image1><p>$title</p></div>";
}
if ($id == $numArray[2])
{
echo "<div class=col-md-4 id=left><img src=$image1><p>$title</p></div>";
}
echo "</div>";
}
}
?>
</div>
</div>
</body>
</html>
CSS
.container{
background--color: green;
width: 90%;
height: auto;
}
.header{
background-color: blue;
float: left;
width: 70%;
}
.recommend{
background-color: red;
width: 30%;
float: right;
}
.recommend img{
width: 100%;
}
It would be FAR more useful to see the rendered HTML than the PHP that generates the html.
The image is taking the full width of the containing div - which is set to 30% width. This markup: <div class=col-md-4 id=left> is using a Bootstrap grid class. And, col-md-4 tells the div to be 4/12 (or 30%) of the width of the parent. Since the parent is .recommend, then the div is 30%, and the image inside is 100% of THAT (which means it is 30% of the .recommend div)
So, you can either remove the col-md-4 class from the divs, or you can try and resolve it another way.
According to the CSS provided .recommend div is set to width:30%
All the child elements that have width:100% (images) will only take up as much space as .recommend div, which is 30%