Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Excerpt changing according to post title. For removing the blank space.
I want to adjust (increase or decrease) the excerpt depending on the title of the post. For example (http://www.webdesignerdepot.com/) here in this site the excerpt is adjusted according to the post title. When the post title is large, the excerpt is decreased and vice versa. This excerpt is adjusted according to the letters in the post title.
Suppose there is no excerpt added. I want every thing from start. I found a post (http://www.rlmseo.com/blog/changing-excerpt-size-dynamically/) which is a correct answer to my question, but the code is not working - it is old, not updated, and was written in 2008.
My index.php snippet
<div class="mcr-post-area mcr-handheld">
<div class="mcr-item-warp">
<a class="mcr-title2-link" href="<?php the_permalink() ?>"><h2 class="mcr-title2-header"><?php the_title(); ?></h2></a>
<div class="mcr-below-title">
<span class="mcr-author">
<i class="icon-user"></i><span> <?php the_author(); ?> </span>
</span>
<span class="mcr-date">
<i class="icon-calendar-empty"></i> <?php the_time('M j, Y ') ?>
</span>
<span class="mcr-comment">
<i class="icon-comments"></i>
<?php comments_number( 'no responses', 'one response', '% responses' ); ?>
</span>
<div style="clear:both;"></div>
</div>
</div><!--mcr-item-warp-->
<div class="mcr-post-detial" style="height: auto;">
<div style="margin: 0px; padding: 0px; border: 0px;">
<div class="entry-home">
<?php the_excerpt(strlen(the_title())); ?>
<?php the_excerpt(); ?>
</div>
</div>
</div>
</div>
<?php
// Dynamically resize excerpt according to title length
$rem_len = ""; //clear variable
$title_len = strlen(get_the_title()); //get length of title
if($title_len <= 35){
$rem_len=188; //calc space remaining for excerpt
}elseif($title_len <= 70){
$rem_len=146;
}elseif($title_len <= 105){
$rem_len=104;
}elseif($title_len <= 140){
$rem_len=62;
}
$trunc_ex = substr(get_the_excerpt(), 0, $rem_len); //truncate excerpt to fit remaining space
if(strlen($trunc_ex) < strlen($post->post_excerpt)) $trunc_ex = $trunc_ex . " [...]";
echo "<p>" . $trunc_ex . "</p>"; //display excerpt
?>
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am creating a blog page. I want to create a small highlights section on the home page.
I created the highlight part from the admin panel, when I make changes, it appears from the database, but I cannot pull the information on the front side. Only the name of the blog will appear in the highlights. Where is the problem?
<div class="card text-center my-5">
<div class="card-header baslik-blog">
En Çok Okunan Blog Yazıları
</div>
<ul class="list-group list-group-flush">
<?php
$blogsor=$db->prepare("SELECT * FROM blog where blog_onecikar=:blog_onecikar");
$blogsor->execute(array(
'blog_onecikar' =>1,
));
while($blogcek=$blogsor->fetch(PDO::FETCH_ASSOC)){
?>
<a href="blog-page" class="blog-a">
<li class="list-group-item"><i class="fas fa-angle-double-right float-start"></i>
<?php $blogcek['blog_ad'] ?>
</li>
</a>
<?php } ?>
Tüm Blog Yazıları
</ul>
</div>
change
<?php $blogcek['blog_ad'] ?>
to
<?php echo $blogcek['blog_ad'] ?>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have an Owl slider in my current project, in which up to three images from the database are to be displayed. I can also call up all the data I need without any problems, but if I want to display 2 or 3 pictures in the slider, only the first picture is displayed and the other pictures wont displayed without an error.
What is the problem?
<div class="container" style="margin-top: 10px;">
<div class="owl-carousel owl-theme">
<?php
$operator_one_id = escape($_GET['operator_one']);
$query = "SELECT * FROM strat WHERE player_one_operator_id = $operator_one_id";
$select_operator_one_strat = mysqli_query($connection, $query);
$row = mysqli_fetch_assoc($select_operator_one_strat);
$player_one_operator_id = $row['player_one_operator_id'];
$player_one_image_top = $row['player_one_image_top'];
$player_one_image_ground = $row['player_one_image_ground'];
$player_one_image_base = $row['player_one_image_base'];
echo "<div class='item'><img src='./assets/img/maps/strats/$player_one_image_top' alt='Operator One Top Strat'></div>";
echo "<div class='item'><img src='./assets/img/maps/strats/$player_one_image_ground' alt='Operator One Ground Strat'></div>";
echo "<div class='item'><img src='./assets/img/maps/strats/$player_one_image_base' alt='Operator Base Strat'></div>";
?>
</div>
</div>
![
Left picture 1, right picture 2]1
This is an example of how html is rendered. With the following options you can change almost every class the way you want.
<div class="owl-carousel owl-theme owl-loaded">
<div class="owl-stage-outer">
<div class="owl-stage">
<div class="owl-item">...</div>
<div class="owl-item">...</div>
<div class="owl-item">...</div>
</div>
</div>
</div>
While loop will display all images in database until you not limit query, so, you dont need to specify each image.
Your php codes in while loop should look like this :
<div class="owl-carousel owl-theme owl-loaded">
<div class="owl-stage-outer">
<div class="owl-stage">
<?php while($row = mysqli_fetch_assoc($select_operator_one_strat)){ ?>
<div class="owl-item">
<img src="path-to-image/<?php echo $row['image-name']; ?>" />
</div>
<?php }?>
</div>
</div>
</div>
Documentation : https://owlcarousel2.github.io/OwlCarousel2/docs/api-classes.html
But you are trying to display specific images so your codes should look like this without while loop :
<div class="owl-carousel owl-theme owl-loaded">
<div class="owl-stage-outer">
<div class="owl-stage">
<?php $row = mysqli_fetch_assoc($select_operator_one_strat);?>
<div class="owl-item">
<img src="path-to-image/<?php echo $row['image-1']; ?>" />
</div>
<div class="owl-item">
<img src="path-to-image/<?php echo $row['image-2']; ?>" />
</div>
<div class="owl-item">
<img src="path-to-image/<?php echo $row['image-3']; ?>" />
</div>
<div class="owl-item">
<img src="path-to-image/<?php echo $row['image-4']; ?>" />
</div>
</div>
</div>
</div>
Marquee is another choice
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I am starting a cart session on my cart page but cart dropdown is not updating with a count until I refresh the page. I just want to update the div without reloading.
I am using foreach but it doesn't work. What should I do now.
<?php
session_start();
require_once("product.php");
?>
<li class="header-cart dropdown default-dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="true">
<div class="header-btns-icon">
<i class="fa fa-shopping-cart"></i>
<?php
if(isset($_SESSION['cart'])){
?>
<span class="qty"><?php echo count($_SESSION['cart'])?></span>
<?php
}else{
?>
<span class="qty">0</span>
<?php
}
?>
</div>
<strong class="text-uppercase">My Cart:</strong>
<br>
<span>Shop Now</span>
</a>
<div class="custom-menu">
<div id="shopping-cart">
<div class="shopping-cart-list">
<?php
#$cart = unserialize(serialize($_SESSION['cart']));
$total = 0;
if($cart){
foreach($cart as $k=>$v)
{
$total += $v->price * $v->quantity;
?>
<div class="product product-widget">
<div class="product-thumb">
<img src="<?php echo $v->img;?>" height="50" width="60" alt="">
</div>
<div class="product-body">
<h3 class="product-price"><?php echo $v->price;?> <span class="qty">x1</span></h3>
<h2 class="product-name"><?php echo $v->name;?></h2>
</div>
<button class="cancel-btn" style="margin-right:8px;"><i class="fa fa-trash"></i></button>
<?php }
?>
<div class="shopping-cart-btns">
<button class="main-btn">View Cart</button>
<button class="primary-btn" style="margin-left:15px;">Checkout <i class="fa fa-arrow-circle-right"></i></button>
</div>
<?php
}
else{
echo '<p style="color: red;">No Product is added in your cart</p>';
}
?>
</div>
</div>
</li>
I want to update the cart div when I click on Add to cart.
As you have not provided enough code to work with, I will post the concept and hope you will be able to do it, also comment if you have any more doubts I'm always open to help
So firstly you need to write a function that asynchronously fetches
the data - Which means it fetches the data without having the page to
reload.
So you need to write the PHP code in a PHP file instead of in the HTML page, for example,
cart.php or where ever you have written your query to fetch the count
of the cart from database.
Once you have done that then you need to write an AJAX call to the
button of Add to Cart, So when you click on add to cart, it triggers
the ajax request and fetches the data from the backend which is
passed from your cart.php
for example , write this code inside your add to cart button
fetch("cart.php")
.then(res=>res.json)
.then(res=>{
//You will get the count here and just append it inside the tag where your count is displayed
//For example :
count.innerHTML = res
})
Don't forget to json_encode($count); in the PHP file so that you can receive the data in JSON format
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
All of this needs to be inside my loop so I don't know if I can break it (don't think I can) but I need PHP to read it as HTML.
$movieDetails =
<header class="masthead" role="banner">
<div class="logo-container">
<a class="logo" href="">Movie Details</a>
</div>
</header>
<div class="bubble-container">
<div class="speech-bubble speech-bubble-top">
Text that goes into the bubble
</div>
</div>
You can just close your PHP tag to render text that will display as HTML.
<?php
foreach($movies as $movie) {
?>
<div>
<?php echo htmlspecialchars($movie); ?>
</div>
<?php
}
?>
$movieDetails = <<<HTML
<header class="masthead" role="banner">
<div class="logo-container">
<a class="logo" href="">Movie Details</a>
</div>
</header>
<div class="bubble-container">
<div class="speech-bubble speech-bubble-top">
Text that goes into the bubble
</div>
</div>
HTML;
echo $movieDetails;
http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I was wondering what will be the best way to show the number of items and the total price for those item which are already in cart(shopping basket).
The header.php page is on all my pages. so whatever page the user goes to they should be able to still see what the number of item in page and total price.
For an example if I had about 7 items my cart and let's say those item cost about $600.78. How cab I count those item up and show the number and total price in the div below.
example
Let's say u go on Nike website and buy 3 pairs of Nike shoes. If u look on top of the page it tells u how many items u have in your basket and the total price for all those items.
My header.php
<div class="cart">
<div class="shbag">
<a href ="cart.php">
</div>
<ul>
<li class="item"><a>
Item
<span id="items">0</span>
</a></li>
<li class="cart_price"><a href=""
title="Cart">
Total £
<span id="cart_total">0.00</span></a></li>
<!--cart page -->
<li><a href="cart.php">
<span class="check_bdr"
title="Checkout">View bag</span></a></li>
</ul>
</div>
Thanks in Advance
Here is my approach:
header.php
<?php require_once('minicart.php'); ?>
<div class="cart">
<div class="shbag">
<a href ="cart.php">
</div>
<ul>
<li class="item">
Item <span id="items"><?php echo cart_item_count() ?></span>
</li>
<li class="cart_price">
<a href="" title="Cart">Total £
<span id="cart_total"><?php echo cart_total() ?></span>
</a>
</li>
<!--cart page -->
<li>
<a href="cart.php">
<span class="check_bdr" title="Checkout">View bag</span>
</a>
</li>
</ul>
</div>
minicart.php
<?php
function cart_item_count()
{
return count($_SESSION['cart_array'])
}
function cart_total()
{
// calculate your cart total here
return $cart_total;
}