Hi I have this error in my website
my website is wordpress 4
i use post format
in post format i create this php to if page has quote post then dont load title and image and etc from quote post just show quote content is meta box (wordpress)
Notice: Use of undefined constant quote - assumed 'quote' in C:\xampp\htdocs\personal\wp-content\themes\personal\warp\systems\wordpress\layouts\_post.php on line 4
and
Notice: Use of undefined constant quote - assumed 'quote' in C:\xampp\htdocs\personal\wp-content\themes\personal\warp\systems\wordpress\layouts\_post.php on line 14
this is _post.php code in bellow
<?php $format = get_post_format(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('group'); ?>>
<?php
if ($format != quote ) {
$css_class = "b-box";
} else {
$css_class = "q-box";
}
echo "<div class=\"$css_class\">";
?>
<?php get_template_part('inc/post-formats'); ?>
<?php if ($format != quote ) : ?>
<div class="post-content">
<div class="blog-img-box">
<img src="<?php echo catch_that_image() ?>" alt="<?php the_title(); ?>" />
</div>
<div class="post-deco blog-icon-box">
<div class="hex hex-small">
<i class="fa blog-icon"></i>
<?php if ( $format != false ) :?><?php endif; ?>
</div>
</div><!--/.post-deco-->
<h2 class="blog-title">
<?php the_title(); ?>
</h2><!--/.post-title-->
<div class="blog-details row">
<div class="col-md-4"><i class="fa fa-calendar blog-details-icons"></i>
<p class="blog-details-icons-txt"><?php the_time('j M, Y'); ?></p>
</div>
<div class="col-md-4">
<a href="<?php comments_link(); ?>">
<i class="fa fa-comment blog-details-icons"></i>
<p class="blog-details-icons-txt"><?php comments_number( '0', '1', '%' ); ?> Comments</p></a>
</div>
<div class="col-md-4"><i class="fa fa-eye blog-details-icons"></i>
<p class="blog-details-icons-txt"><?php echo getPostViews(get_the_ID()); ?></p>
</div>
<div class="likes"><i class="fa fa-heart blog-details-icons"></i>
<p class="blog-details-icons-txt">18</p>
</div>
</div>
<div class="blog-txt">
<?php the_excerpt(); ?>
</div>
<div class="readmore-box"><p class="readmore-txt"><?php _e('Read More','anew'); ?></p></div>
</div><!--/.post-content-->
<?php endif ?>
</div><!--/.post-inner-->
</article><!--/.post-->
please check and say to me what i wrong
thank you !
If you want to use the quote as a literal string (line 4), not a variable name, you must enclose it into single or double quote characters (' or "). Otherwise, PHP thinks that you're referencing a PHP constant.
For reasons of backward compatibility, PHP falls back on using the string as literal, but it does throw an E_NOTICE error – the one you're experiencing.
verify that all variables have this sign $
correct variable $test
incorrect variable test
Related
I have a code on wordpress website (front-page.php), it's cut text and add "..." on title if text is over 35 characters.
Cut is ok but the points is always visible. Is it possible to add only if text is cut?
Thank you!
<div class="bxpd">
<h2><span><?= substr($post_title,0,35); ?></span>
<a href="<?= get_post_permalink($post_id); ?>">
<?= substr($postData->post_title, 0, 35)."..."; ?>
</a>
</h2>
<p><?= substr($postData->post_content,0,strpos($postData->post_content, ' ', 150))."..."; ?> </p>
</div>
<div class="bxpd">
<h2><span><?= substr($post_title,0,35); ?></span>
<a href="<?= get_post_permalink($post_id); ?>">
<?=
substr($postData->post_title, 0, 35). (strlen($postData->post_title) > 35 ? "..." : "");
?>
</a>
</h2>
<p><?= substr($postData->post_content,0,strpos($postData->post_content, ' ', 150))."..."; ?> </p>
You can adjust your code and put ... only if they are needed:
<div class="bxpd">
<h2><span><?= substr($post_title,0,35); ?></span>
<a href="<?= get_post_permalink($post_id); ?>">
<?= substr($postData->post_title, 0, 35)."..."; ?>
</a>
</h2>
<p><?= substr($postData->post_content,0,strpos($postData->post_content, ' ', 150)).
(strlen($postData->post_content)>150?"...":"");
?> </p>
</div>
I am using Osclass 3.5.3. In my log file, I keep seeing the following error:
"PHP Warning: implode(): Invalid arguments passed in"
The lines in question are:
<!-- <small><?php _e("Location", 'aiclassy');?>: <cite title="<?php echo implode(', ', $location); ?>"><?php echo osc_user_city(); ?><span class="glyphicon glyphicon-map-marker"></span></cite></small><br /><br /> -->
<!-- <span class="glyphicon glyphicon-envelope"></span> <?php printf(__('%s', 'aiclassy'), osc_item_contact_email()); ?><br /> -->
The whole code is wrapped up in like this:
<div class="well">
<div class="row">
<div class="col-sm-12">
<!-- <small><?php _e("Location", 'aiclassy');?>: <cite title="<?php echo implode(', ', $location); ?>"><?php echo osc_user_city(); ?><span class="glyphicon glyphicon-map-marker"></span></cite></small><br /><br /> -->
<!-- <span class="glyphicon glyphicon-envelope"></span> <?php printf(__('%s', 'aiclassy'), osc_item_contact_email()); ?><br /> -->
<?php osc_run_hook('item_detail', osc_user() ); ?>
<?php //voting_item_detail_user(); ?>
</div>
</div>
</div>
How do I resolvethis...any suggestions, please? Thank you, all.
If you are unsure about if the value for $location is an array or a string you could decide it right away when echoing the value.
<?php echo is_array($location) ? implode(', ', $location) : $location; ?>
This is meant as a replacement for the current
<?php echo implode(', ', $location); ?>
You need to pass an array to implode seconds parameter.
See the documentation here.
I'm inner joining two databases together here, when using the separate views individually they work fine, so do the databases, I think the cause of this is the inner join, but putting the query directly into phpmyadmin and replacing the $categoryID with a number works.
Some rows load, such as the images, but joined variables are undefined, What is causing the variables to be undefined?
Model:
function DisplayBySpecificCategory($categoryID)
{
$query = $this->db->query("SELECT * FROM CIUploads
INNER JOIN CIUsers ON CIUploads.UserID = CIUsers.UserID
WHERE CIUploads.UploadCategoryID = $categoryID
ORDER BY CIUploads.UploadTime DESC");
return $query->result();
}
Controller:
function SpecificCategory()
{
$categoryID=$this->uri->segment(3);
$this->load->model('Previews_model');
$this->load->model('Category_model');
$this->load->view('../includes/header.php');
$data['category'] = $this->Category_model->GenerateCategoryHeader($categoryID);
$data['allwork'] = $this->Previews_model->DisplayBySpecificCategory($categoryID);
$this->load->view('headers/Specific_category_header', $data);
$this->load->view('previews/Previews_view', $data);
$this->load->view('../includes/footer.php');
}
Header view:
<?php foreach ($category as $value2){ ?>
<header style="background-color:#<?php echo $value2->CategoryColor ?>">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="page-intro">
<h1 class="inverted text-center"><?php echo $value2->CategoryTitle ?></h1>
<p class="inverted text-center"><?php echo $value2->CategoryDescription ?></p>
</div>
</div>
</div>
</div>
</header>
<?php } ?>
Previews view:
<?php
if($value->UploadCategoryID == 2){
echo '<video muted class="video-responsive fit-centered">';
echo '<source src="'.base_url("/public/uploads/works")."/".$value->UploadedAt.'" type="video/mp4">Your browser does not support the video tag.';
echo '</video>';
}
else if($value->UploadCategoryID == 3){
echo '<iframe class="fit-centered" src="http://'.$value->UploadedAt.'" scrolling="no"></iframe>';
}
else{
echo '<img class="img-responsive fit-centered" src="'.base_url("/public/uploads/works")."/".$value->UploadedAt.'" alt="'.$value->UploadTitle.'">';
} ?>
<div class="overlay">
<p>
<i class="fa fa-eye fa-3x ease-color"></i>
</p>
</div>
</div>
<div class="hovereffect-information no-bounding">
<span class="category-tab pull-right text-center inverted" style="background-color:#<?php echo $value->CategoryColor ?>"><i class="fa <?php echo $value->CategoryIcon ?>"></i></span>
<p class="pull-left no-bounding text-uppercase preview-info"><?php echo $value->UploadTitle ?></p>
<img class="img-responsive small-profile-img pull-right hover-dim fit-centered" src="<?php echo base_url("/public/uploads/profile-images/")."/".$value->ProfileImg ?>" alt="<?php echo $value->Username ?>"/>
<p class="pull-left no-bounding text-uppercase preview-info">
<span class="preview-span"> <i class="fa fa-eye"></i> <?php echo $value->UploadViews ?> </span> |
<span class="preview-span"> <i class="fa fa-heart"></i> <?php echo $value->UploadLikes ?> </span> |
<span class="preview-span"> <i class="fa fa-comments"></i> <?php echo $value->UploadComments ?> </span>
</p>
</div>
</div>
<?php } ?>
Error:
Severity: Notice
Message: Undefined property: stdClass::$CategoryIcon
Filename: previews/Previews_view.php
Line Number: 31
Backtrace:
File:
/web/stud/u1263522/cmw/application/views/previews/Previews_view.php
Line: 31 Function: _error_handler
File:
/web/stud/u1263522/cmw/application/controllers/Views_controller.php
Line: 64 Function: view
File: /web/stud/u1263522/cmw/index.php Line: 292 Function:
require_once
In the question you have mentioned : Undefined property: stdClass::$CategoryID
whereas the error shows : Undefined property: stdClass::$CategoryIcon
If $CategoryIcon is undefined it means that you do not have a column called CategoryIcon in any of your tables.
Can you mention the details of the tables?
It is always a good practice to mention the column names in the query instead of *.
add your loading model before called in Controller , Check name is correct , Make sure that some name in (model = Class)
$this->load->model('model_name'); //
Or in Confige.php
I need to echo a lot of PHP and HTML.
I already tried the obvious, but it's not working:
<?php echo '
<?php if ( has_post_thumbnail() ) { ?>
<div class="gridly-image"><?php the_post_thumbnail('summary-image', array('class' => 'overlay', 'title'=> the_title('Read Article ',' now',false) ));?>
</div>
<?php } ?>
<div class="date">
<span class="day">
<?php the_time('d') ?></span>
<div class="holder">
<span class="month">
<?php the_time('M') ?></span>
<span class="year">
<?php the_time('Y') ?></span>
</div>
</div>
<?php } ?>';
?>
How can I do it?
You don't need to output php tags:
<?php
if ( has_post_thumbnail() )
{
echo '<div class="gridly-image">'. the_post_thumbnail('summary-image', array('class' => 'overlay', 'title'=> the_title('Read Article ',' now',false) )) .'</div>';
}
echo '<div class="date">
<span class="day">'. the_time('d') .'</span>
<div class="holder">
<span class="month">'. the_time('M') .'</span>
<span class="year">'. the_time('Y') .'</span>
</div>
</div>';
?>
You cannot run PHP code within a string like that. It just doesn't work. As well, when you're "out" of PHP code (?>), any text outside of the PHP blocks is considered output anyway, so there's no need for the echo statement.
If you do need to do multiline output from with a chunk of PHP code, consider using a HEREDOC:
<?php
$var = 'Howdy';
echo <<<EOL
This is output
And this is a new line
blah blah blah and this following $var will actually say Howdy as well
and now the output ends
EOL;
Use Heredocs to output muli-line strings containing variables. The syntax is...
$string = <<<HEREDOC
string stuff here
HEREDOC;
The "HEREDOC" part is like the quotes, and can be anything you want. The end tag must be the only thing on it's line i.e. no whitespace before or after, and must end in a colon. For more info check out the manual.
Use the colon notation
Another option would be to use the if with a colon (:) and an endif instead of the brackets:
<?php if ( has_post_thumbnail() ): ?>
<div class="gridly-image">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('summary-image', array('class' => 'overlay', 'title'=> the_title('Read Article ',' now',false) )); ?>
</a>
</div>
<?php endif; ?>
<div class="date">
<span class="day"><?php the_time('d'); ?></span>
<div class="holder">
<span class="month"><?php the_time('M'); ?></span>
<span class="year"><?php the_time('Y'); ?></span>
</div>
</div>
The internal set of single quotes in your code is killing the string. Whenever you hit a single quote it ends the string and continues processing. You'll want something like:
$thisstring = 'this string is long \' in needs escaped single quotes or nothing will run';
To do that, you must remove all ' charachters in your string or use an escape character. Like:
<?php
echo '<?php
echo \'hello world\';
?>';
?>
Use the show_source(); function of PHP. Check for more details in show_source. This is a better method I guess.
In the CMS i'm working on I'm using a foreach statement to display the returned database results.
but ever page load I get an error message saying the foreach statement im using has an invalid argument
here's the statement
<?php foreach ( $presults as $post ) { ?>
<!-- Post Frames -->
<div class="outerPost_frame">
<div class="postScreen">
<!--post date hidden show on hover -->
<span class="date_">
<p><?php echo date('j F', $post->date) ?></p>
</span>
<!-- post title -->
<span class="name_">
<p><?php echo htmlspecialchars($post->name) ?></p>
</span>
<span class="content_">
<?php echo $results['post']->content ?>
</span>
</div>
</div>
<?php } ?>
Try casting $presults to an array.
<?php foreach ( (array) $presults as $post ) { ?>
How are you setting up your array, could be a problem, but we would need an error msg to know for sure.
Try this though
<?php foreach ( $presults as $post ) { ?>
<!-- Post Frames -->
<div class="outerPost_frame">
<div class="postScreen">
<!--post date hidden show on hover -->
<span class="date_">
<p><?php echo date('j F', $post[date]) ?></p>
</span>
<!-- post title -->
<span class="name_">
<p><?php echo htmlspecialchars($post[name]) ?></p>
</span>
<span class="content_">
<?php echo $post[content] ?>
</span>
</div>
</div>
<?php } ?>