Get, modify, then print post title in wordpress - wordpress

Is there a way native way in wordpress to make uppercase the first letter of the first word of the scentence / the_title of the post?
If not, how do I do it in php, while it is wrapped in a <a></a> tag?
Here is the full line of code.
<?php ucfirst(the_title());?>
As you see, I have tried ucfirst, but it does not work. The other thing that I tried is:
<?php
$temp_title = the_title();
$final_title = ucfirst($temp_title);
?>
<?php echo $final_title;?>

ucfirst() returns a string. You need to echo the value returned from ucfirst().
Furthermore, the WordPress function the_title() prints the title directly, rather than returning it as a string. Use get_the_title() instead.
<?php echo ucfirst(get_the_title());?>

I think this is your problem: http://core.trac.wordpress.org/browser/tags/3.8/src/wp-includes/post-template.php#L51. As you can see the_title() is using get_the_title() and then if($echo) it echoes it out. I would experiment and try get_the_title().

First off you had an ending parantheses that didn't have a matching parantheses in your echo $final_title. Second you should try to apply ucfirst to the echo of your title. I removed $finaltitle, because it no longer serves a purpose. I haven't tried the code, but it should work. Please note that ucfirst() only works if the first letter is in the alphabet.
<?php
$temp_title = the_title();
?>
<?php echo ucfirst($temp_title);?>

Related

How to remove « from wordpress several section

while writing wp_title(), next_post_link() and previous_post_link() a special character comes, i.e. "«". How to get rid of this character?
wp_title
You can use something like <title><?php wp_title(''); ?></title> to remove the separator.
previous_post_link
If you need to remove the «, you can just simply override it like this
<?php previous_post_link('%link'); ?>
next_post_link
If you need to remove the », you can just simply override it like this
<?php next_post_link('%link'); ?>

wp_title showing page title but not site title

I couldn't find an answer to this question anywhere and I have a hard time believing I'm the only one who has had this problem.
My title function inside my title tag of header.php, <?php wp_title('|', true, 'right'); ?>, is returning the page title but not the site title.
Example: About Us |
Why would it not be returning the site name??
Looks like wp_title() does not return the site's title. Sorry, hopefully someone will benefit from this answer.
I've never tried combining the entire title inside one function. Instead I use multiple calls:
<?php wp_title(''); ?><?php if(wp_title('', false)) { echo ' |'; } ?> <?php bloginfo('name'); ?>

Show next/prev if more than one post

A little lost - believe I'm almost there though. I'm trying to make it so the next and previous links don't show unless there is more than one post.
<?php if($numberofposts != "1") : ?>
Prev
<?php endif; ?>
Hopefully it's just something simple I'm overlooking.
Check to see if $numberofposts contains a number (instead of a string). It probably does. If so, you will want to rewrite your code like this:
<?php if($numberofposts > 1) : ?>
Prev
<?php endif; ?>
If it doesn't contain a number, you should probably rewrite whatever function it's pulling from so that it does.

Aptana 3 format phtml files

i've been using aptana for a while now, and i have a little question because it is driving me mad. It is possible to recode formmat rules if there is no option in the preferences options (Windows->Preferences->Aptana studio->Formmatter).
I want to recode format rules of .phtml files for a simple rule, <?php ... ?> tag. Everytime i autoformat .phtml files, the "tag" ?> adds a line. I do not want that new line, i want it keep at the same line as the initial tag.
if i write in a .phtml file something like this:
<?php if ($this->x > 10) : ?>
<p> It is not greater than 10 </p>
<?php else : ?>
<p> It is greater than 10 </p>
<?php endif : ?>
and do autoformat, the autoformat return this:
<?php if ($this->x > 10) :
?>
<p> It is not greater than 10 </p>
<?php else :
?>
<p> It is greater than 10 </p>
<?php endif :
?>
I hope you can understand my question. How can anybody recode a format rule or show me the option where i can say do not add a new line in ?> tag.
Thanks in advance.
P.D.
Excuse if i have some grammars errors, if been a while since i have to write in english.
It's not possible (yet) with the current formatter capabilities. However, I've created an issue for that at http://jira.appcelerator.org/browse/APSTUD-3340 and you are more than welcome to add yourself as a watcher, so you will get notified.
That main problem is that the current formatter works partition-by-partition, and not by looking at the entire content as a whole.
Cheers

Home Page Only Footer

I have a blog, http://sweatingthebigstuff.com and I would like to add an extra line in the footer which will display only from the homepage. I found this code, but it is not working for me. Do I have the wrong syntax or is there something else I can try to get this to work?
<?php if ( is_home() ) { ?>
text
<?php } ?>
Here is where footer.php is called
<?php include (TEMPLATEPATH . '/sidebar1.php'); ?>
<div class="cleared"></div>
<?php get_footer(); ?>
And here is the footer code:
text 2
Contact | Disclaimer | Privacy StatementCopyright © 2009-2010 Sweating The Big Stuff. All Rights Reserved.
and then some sitemeter crap.
is_home() sets a global var that doesn't seem to reset itself or re-evaluate, wp kinda strange.
Try putting wp_reset_query() at the end start of your if statement code
Actually, it'll be better to call it before as we can ensure the queries are reset
<?php wp_reset_query();
if ( is_home() ) { ?>
text
<?php } ?>
Now that the php is working, ideally you'd want the code above.
text
I just did a view source and I can plainly see the php code, which shouldn't be visible since it is meant to be parsed server side. The following shouldn't be there in the view source.... wrong file being edited?
<p>
<?php if ( is_home() ) { ?>
text
<?php } ?>
<wp_reset_query()>
<br />
<br />
The footer.php file should be located in wp-content/themes/nameofyourtheme folder
is_home() is a method that should return true or false. You need to implement this method somewhere. If blogspot doesn't implement this method for you, you need to do it yourself. For your website I think this function would do what you want:
<?php
function is_home(){
$r = $_SERVER['REQUEST_URI'];
return $r == '/' || $r == '' || $r == '/index.php';
}
if(is_home()) {
?>
text
<?php } ?>
And where you want the footer, put:
<?php include 'footer.php'; ?>
instead of the line:
<?php get_footer(); ?>
I believe your problem is that get_footer() is reading the footer as text, so it isn't executing the PHP beforehand. If you do it this way you can add as much PHP in the header as you want.
There is nothing wrong with your syntax, and when I view your page source, I see " text "
What is the file extension of your footer page? if it is "footer.php" then I shouldn't see the opening and closing terms for php (). php won't run unless the file extension is ".php"
as to a previous answer:
<?php wp_reset_query();?> should go BEFORE <?php if(is_home()){?>text<?php } ?> in this scenario. is_home() depends on a loop being present on the page. Maybe somewhere you used a custom query, or one of your plugins used a custom query that upset the default query vars. Like I said, use the reset statement before your if statement.
You need to modify the code to include a check for is_front_page() like so:
<?php
$ishomepage = ( is_home() || is_front_page() );
switch( $ishomepage )
{
case true :
echo 'Your homepage-only snippet of text goes here';
break;
case false :
default :
// Do nothing... or do something else...
break;
}
?>
Reference: WordPress Codex: is_front_page()
Default WP installations don't have a homepage defined, it uses your index.php and checks for other templates like a home.php template as a starting point (home.php only if your theme has it.) Here's a diagram from their online docs that shows how their hierarchy works: WordPress Template Hierarchy.
By default, WordPress shows your most recent posts on the front page
of your site. But many WordPress users want to have a static front
page or splash page as the front page instead. This "static front
page" look is common for those who wish to not have a "blog" look to
their site, giving it a more CMS (content management system) feel.
If you want to know how to set a static homepage, read this article and follow the instructions: Creating a Static Frontpage. When you set a static front page, is_home() will work as expected.

Resources