My homepage's title is being displayed as the title of the last blog post created.
The code is:
<title><?php bloginfo('name'); ?></title>
So from my understanding that should display the blog title (set in general settings) on the homepage.
But its not. Its displaying the most recent post title.
What do i need to look for?
wp_title() is used to display the title of the page being displayed, but it uses the query results to get its value. So if you are executing a loop on many posts (which you obviously are on your homepage) and you don't reset it, you will get the title of the last post in your loop... logical.
Besides, note that the homepage is index.php in your theme, it is not a real page in WordPress. So it hasn't got a title. So wp_title() can't be of any use for you here.
Basically, your homepage has not got any title. So if this template is both for your homepage and other pages, you need to do a conditional check :
Is this homepage? (use is_home())
A. Yes, echo "Welcome on my great website"
B. No, wp_title(), which will echo the title of the page you are on...
Do you get it?
First off, you're executing two functions here -- wp_title, which retrieves the title of the page the visitor is currently on, and thereafter bloginfo, which with the argument 'name' indeed fetches your blog's name as set in the configuration.
However, there's a slight error in your code; you'd get the desired result as follows:
<title>
<?php
wp_title('|', true, 'right');
bloginfo('name');
?>
</title>
You should read about the parameters for wp_title on the WP Codex; the | gives you a delimiter, for example, and 'right' tells the function where to output said separator.
Note: I'd advise you to display both the post title and blog name, as only the blog name on every single page is both unhelpful for visitors and yields por results in search engine results.
I found your problem! Error in your code : remove > after <?php (you have written <?php>) so this :
<?php> bloginfo('name'); ?>
should now become this :
<?php bloginfo('name'); ?>
And it will work !
Related
this is my first time posting on this site so apologies if the question isn't totally appropriate but I'm building a portfolio site for my brother who is a composer and he needs his music library to be able to be checkbox filter-able. The problem is that when I conduct a search with filters, the results show only the excerpt, and not the audio player like I need.
Library page displaying the full posts with audio player
Search results page showing just the post title and nothing else
Also, excuse the sheer crudeness of the site. I just started it this morning... Thanks in advance!
To show the full content you have to use the_content function, in your search.php file replace the following
<?php the_excerpt(); // partial content ?>
with
<?php the_content(); // full content ?>
Also remember. the_excerpt function strips out all HTML tags so it could be a problem, you can read this article.
Scenario: The urls and titles of the posts on my blog are usually very long. Whenever I or anyone else tweets the post, I don't find any space to add the hashtags or quoted retweet text. I don't want to shorten the titles of the posts, so the other option is to shorten the url. For this purpose I want to grab the shortlink from wordpress post in this format
http://mydomain.com/?p=(post ID)
Can you please tell me how to do it?
Use wp get shortlink
Returns URL based on numerical ID, i.e. http://example.com/?p=1234
https://codex.wordpress.org/Function_Reference/wp_get_shortlink
Usage
<?php $short_link = wp_get_shortlink(); ?>
or
<?php echo wp_get_shortlink(); ?>
Source File
wp_get_shortlink() is located in wp-includes/link-template.php.
You can go to Settings -> Permalinks and set it to 'default' (or 'numeric' if you prefer) and then call
<?php the_permalink() ?>
in your “tweet this” link.
or you can use this: Twitter Friendly Links WordPress Plugin
I have a site whose home page shows a single Wordpress category page. I'm using a custom theme and the index.php file there does a 301 redirect to "mysitename.com/?cat=3". This page is generated with an event calendar plugin and a lot of custom code. It works, but the displayed URL is "mysitename.com/?cat=3" which I'd prefer my visitors not see; I'd rather have the URL be just "mysitename.com", "mysitename.com/index.php", or even "mysitename.com/calendar".
The visitor can view "prev month" and "next month", which result in URLs like "mysitename.com?cat=3&eventDate=2010-07&bt=a" -- still within the same category but with additional parameters in the URL. (I am OK having a more convoluted URL like this shown to my visitors on previous/next month; it's just the initial page URL I'd like to be nicer.)
I've messed around with the permalinks but can't get nice URLs to work correctly that way. Is there an .htaccess way to do this?
In the "permalinks" section under the "Settings" tab, you can add a category base to the categories.
Thus if you have a category base of "category" and a category name "Cool Stuff" with a slug of "cool_stuff"
Your category link would link like this depending on your permalink settings.
http://yoursite.com/category/cool_stuff/
Okay. My Last answer was not base on your "edited question".
If you remove the 301 redirect to "mysitename.com/?cat=3"
you can edit the index.php file.
This will most likely take care of your url issue.
You can edit the loop to show only categories from id: 3
Thus, you will make a querypost for category 3 as follow:
<?php query_posts('showposts=9'); ?>
See Query Post # Wordpress for more info.
Put this before the loop.
The coding may look like this:
<?php query_posts('cat=3'); ?>
<?php if (have_posts()) {?>
<?php while (have_posts()) : the_post(); ?>
<li>
<?php the_title(); ?>
<span style="float: right;"><?php the_time('m/d/y'); ?></span>
</li>
<?php endwhile; }?>
You could use .htaccess to map mywebsite.com/calendar to mywebsite/?cat=3, but WordPress will still look at the original url to find out which category to use, so this will not work.
I suggest you look in the code of the plugin to find out how it gets the current category, and maybe trick it (by an extra call to query_posts('cat=3')) to think we are looking at the url for category 3 (you don't need to display the posts, just do the query). You can even do this on your homepage (but maybe use home.php, not index.php, since the latter is a fallback for other template pages), so you don't need a redirect. But the key is that you need to look at the code of your plugin (can you tell us the name?) to find out how it works.
in Wordpress on a post how can I get the name of the category it belongs to (each post will only have one category on my website).
The version of wordpresss you're using is very much relevant for your question, but a good place to start would be the wordpress codex where you can find for example the documentation of this function.
It is also important to know whether your code will be placed within the infamous loop (which would be the case if you're editing the post template) or not (for example, if your code goes at the sidebar, header, etc).
Assuming the first case, and taking the example from the manual, you could use:
<?php
$categories = get_the_category();
// there is only one, so extract the first from the array
$category = $category[0];
?>
These can go in header.php for generating meta tags, page titles, etc.
<?php echo trim(strip_tags(category_description())); ?>
<?php echo single_cat_title(''); ?>
Also see Template Tags/single cat title « WordPress Codex
I use Barecity Theme for WordPress. i built everything, but now i need to add a single.php file to theme. now it displays all post content at homepage, I created a short_desc Custom Field. and I call it from code with;
<?php //get_post_meta($post->ID, 'short_desc', true); ?>
it is fine. but i need to display this short desc at home page listing, and the main content at details page. how can do that?
I appreciate helps!!
It sounds like what you are trying to do is show a custom field that you have set on a post on the index page (which lists all the posts).
To do that you'll need to modify index.php by adding your snippet where you would like to have the short description.
<?php echo get_post_meta($post->ID, 'short_desc', true); ?>
You need to use echo to display the results from the get_post_meta function.
Depending on how your posts are setup you can also use the More button when you write your posts. This will cut off your post at a certain point that you decide and only show that short part on the index and archive pages.
Another option would be to use
<?php the_excerpt(); ?>
Which shows the first 55 words (this can be adjusted though) of the post.
Hope that helps,
Paul