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 7 years ago.
Improve this question
Using advanced custom fields plugin on my wordpress site. I have a select option in one of the custom post types which determines if post going to be a link to another page or call out popup.
Here is how it looks.
<!-- here goes a code defining post type. Works fine -->
<?php $hmltype = get_field('post_url_or_popup'); ?>
<div class="tablecell midlineunit middle">
<a class="table midunithref mw1" <?php if ($hmltype == hml_url) { echo 'href="<?php the_field('hplb_url'); ?>" ' } endif; ?> >
</a>
</div>
Must be a syntax error, but I'm just starting out with php, so, kind of difficult to find the mistake.
What is hml_url? Is it a variable called $hml_url..? Back to your issues, you're using endif; here completely wrong. You can only ever call it if you instantiate it like this:
if(condition) :
do stuff;
endif;
Now to fix your print.
<a class="table midunithref mw1" <?php echo ($hmltype == hml_url) ? 'href="'. the_field('hplb_url'); .'"' : ''; ?> >
You'll need to figure out/tell us what hml_url is for us to solve your issue. You would've also seen the error if you turned your error reporting on. You can do this by adding this to the top of your script:
ini_set('display_errors', 1);
error_reporting(-1); // or you could do E_ALL
Related
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 5 years ago.
Improve this question
Here Is the link that I have tried
<a href="<?php echo $this->config->item('base_url') . 'index.php/back-office-panel/User_master#tab4' ?>">
But its not working
suggest answers.
I want to go to edit of that particulate section which is tab format.
Simple pass the uri parameter 'index.php/back-office-panel/User_master/tab4'
<a href="<?php echo $this->config->item('base_url') . 'index.php/back-office-panel/User_master/tab4' ?>">
PHP: Check the condition and echo the active class in tab.
if(isset($this->uri->segment(3)) && $this->uri->segment(3)=='tab4'){
echo 'active';
}
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 6 years ago.
Improve this question
I have a php code which echos a html element:
<?php echo the_content(); ?>
It's resulting in:
<p>MY CUSTOM TEXT FROM ANOTHER PAGE INSIDE MY SITE</p>
How can I remove the <p> & </p> from the result?
I don't want to manually remove the tags <p> & </p> from the page it's coming from, because it is also used in another page in html.
*Edited
I'm currently trying this: *But it's not working...
$content = the_content();
echo strip_tags($content);
and
$content = the_content();
$content = strip_tags($content);
echo ($content);
You could use strip_tags():
<?php echo strip_tags(the_content()); ?>
Also:
<?= strip_tags(the_content()) ?>
I did it to work with this:
<?php echo substr(strip_tags($post->post_content), 0, 160) . '...'; ?>
Probably I was using the element the_content() from wordpress which includes automatically an HTML element <p> & </p> for the front-end page, with post_content it gets the inner content from the post without the f*cking <p> & </p>
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 7 years ago.
Improve this question
Edit: Fixed, moved <?php include(haeder.php); ?> to the top and replaced the outsourced part with <?php showheader(); ?>.
I've been creating a little website, and as its menubar started to get full I wanted to "outsource" it to a separate file.
<body>
<div style="width:800px;margin:0px auto">
<!-- outsourced part -->
<div style="height:50px;background-color:#ff0000">
Header
</div>
<!-- end of outsourced part -->
<div style="margin-top:10px;background-color:#00ff00">
hello world
</div>
</div>
</body>
So I copied the outsourced part and pasted it into a new file called header.php and replaced it with
<?php include("header.php") ?>
so now the code is
<body>
<div style="width:800px;margin:0px auto">
<?php include('header.php') ?>
<div style="margin-top:10px;background-color:#00ff00">
hello world
</div>
</div>
</body>
Now when I open the website again the header and everything after it has moved downwards. How can I prevent this from happening? I have PHP 5.6.14 installed on XAMPP and PHP 5.3.3 on a Linux server.
Uploaded the 2 files here
I tested your file and I could see the issue. Usually this is because you got an invisible character in the page. So go into the Chrome debugger, Elements view, and expand the code. You'll find the following before your header <div> tag.
"
"
from the debugger, you can delete it, and you'll see your page displays fine again. So cleanup your 2 php file. One is having an invisible character.
I believe the reason is that your index.php file in UTF8-BOM encoded while the header.php is just UTF8 - make sure to use the same encoding to avoid these issues.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am building a wordpress theme and for some reason my list of pages are showing outside the li when I view the source
<ul class="tabs">
<?php
while ( $queryObject->have_posts()) : $queryObject->the_post();
echo sprintf('<li>%s</li>', the_title());
endwhile;
?>
</ul>
And when I review the source in the inspector in chrome
<ul class="tabs">
Deans’ Corner<li></li>
Education Plan<li></li>
Counselors’ Corner<li></li>
</ul>
I got to be missing something simple
Take a look at the docs for the_title():
https://codex.wordpress.org/Function_Reference/the_title
Displays or returns the title of the current post.
[...]
$echo
(Boolean) (optional) Display the title (TRUE) or return it for use in PHP (FALSE).
Default: TRUE
the_title() takes an optional parameter $echo which decides whether it should return or echo the title of the page. Since you did not fill it and it defaults to the echo option, your code does not work.
If the_title() echoes, you won't be able to use it directly with sprintf().
Therefore, you can do just use HTML...
<li><?= the_title(); ?></li>
The below example is unnecessary because of the_title()'s optional parameters as pointed out in Timosta's answer.
Or you can use output buffering if you need to use the_title() as a function argument:
ob_start()
the_title();
$title = ob_get_clean();
echo sprintf('<li>%s</li>', $title);
The problem is that by default the_title() echos the title instead of returning it. You can actually specify what to echo before and after the title so there is no need for using sprintf().
This should work:
<ul class="tabs">
<?php
while ( $queryObject->have_posts()) : $queryObject->the_post();
the_title('<li>', '</li>');
endwhile;
?>
</ul>
Check the WordPress Codex:
http://codex.wordpress.org/Function_Reference/the_title
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 8 years ago.
Improve this question
I got a simple PHP code like this one:
<div id="master">
<div id="info">
<?php include 'division.php';
echo $winrate;
?>
</div>
<div id="lastmatches">
<?php include 'lastmatches.php';?>
</div>
</div>
</body>
As you see i want to echo $winrate, but $winrate is a variable that comes from lastmatches.php. So it will never work. Some has got an idea to echo $winrate in the div info? Im stuck and i hope you guys can help me out!
Thanks in advance!
You need to include lastmatches.php before to define $winrate.
But if this file outputs some content then you will want to use the caching system to output the right content at the right place.
<div id="master">
<div id="info">
<?php include 'division.php';
// begin cache
ob_start();
include 'lastmatches.php';
// end cache
$lastmatchescontent = ob_get_clean();
echo $winrate;
?>
</div>
<div id="lastmatches">
<?php echo $lastmatchescontent; ?>
</div>
</div>
</body>
i suggest you to follow MVC approach, if you do not want to use framework u can do something like this: https://github.com/LPodolski/basic_php_templating
this will allow code to be more readable, by separating concerns of generating output from getting data from db, parsing it etc