Archived

This topic is now archived and is closed to further replies.

  • 0

Move the category title above the post title?

Question

Posted · Report post

How do I move the category title and move it above the post title as shown in the posts on this blog: http://blog.westelm.com ?

Share this post


Link to post
Share on other sites

16 answers to this question

Posted · Report post

Nevermind. Figured it out:

 

/* Prints the post category above post title */
add_filter('pagelines_post_title_output','category_above_title');        
	function category_above_title($title){ 
	
$category = get_the_category(); 

if($category[0]){ 
	$category_name .= '<span class="categories sc"><a class="category" href="'.get_category_link($category[0]->term_id ).'">'. $category[0]->cat_name.'</a></span>';

}

$title = $category_name . $title;

return $title;
}
//end function

 

Enjoy!

Share this post


Link to post
Share on other sites

Posted · Report post

I'm basically trying to do the exact same thing. I tried the code above and it worked, but I often use multiple categories for each post and they show up as a bulleted list above the title. Even when a post has only one category it's listed with a bullet point to it's left. My site is www.compression.org. I commented the code out for now so the posts don't look bad, but if needed I can show you what it looks like. If there is a way to add CSS to the categories and remove the bullet that would be great. I can then go bad and use only one category and add tags for more detailed classification or something like that. The most important thing is how to get the categories to show up right in the first place. I looked around and it doesn't seem like anyone has "solved" this issue, yet, so anything to get me in the right direction would be much appreciated. Thanks, Jason This isn't my site, but here's something I'd like to do (http://fresh-energy.org/category/publications/powering-progress/2012-no-08-august/). A primary category is listed above the title and several other categories are listed below the post.

Share this post


Link to post
Share on other sites

Posted · Report post

Hi Jason, For forum search purposes, can you create a new topic please.

Share this post


Link to post
Share on other sites

Posted · Report post

It's in a dev environment right now.

Share this post


Link to post
Share on other sites

Posted · Report post

Thanks for the tip. I messed with this, and while a good start, didn't completely meet my needs. What I more specifically want to do is place the Category title directly above the Post Title. Using the action the_post, while a good start, put it in the the Loop, but it ends up above the thumbnail.

 

I did some sleuthing, however, and found that I could accomplish this using the filter: pagelines_post_title_output, as outlined here: http://www.pagelines.com/wiki/Pagelines_post_title_output

 

The question is, how to write the code properly in my functions.php file. I'm getting better at writing these, but this one has me stumped. I think the reason why is I'm trying not only to display the category title, but only one category title and display it as a hyperlink. I know I can accomplish that using this code:

 

<?php $category = get_the_category(); if($category[0]){ echo '<a href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.'</a>';}?>

 

I've been trying like mad to use this code along with the previously mentioned filter to make it work. I feel like I"m close, but I can't nail it.

 

Any help would be really appreciated.

 

For what it's worth, this is what I have now:

add_filter('pagelines_post_title_output','category_above_title');        
	function category_above_title($title){ 

	$category = get_the_category(); if($category[0]){ echo '<span class="categories sc"><a class="category" href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.'</a>
	</span>';

	$title = $category . $title
	
return $title;
}

Share this post


Link to post
Share on other sites

Posted · Report post

With PageLines Customize (or a child theme) activated, add the following to your custom functions.php:

add_action('the_post', 'add_my_cat');
	function add_my_cat( ) {
	 ?  ? if ( is_home() )
	 ?  ?  ?  ? printf( '
%s
', the_category() ); }[/code]

Give thanks to @pross :)

Share this post


Link to post
Share on other sites

Posted · Report post

OK. Thanks. What I think I really need is a developer that knows PHP. It's probably a simple solve.

Share this post


Link to post
Share on other sites

Posted · Report post

Hi,

 

We have a number of pro developers available at http://www.pagelines.com/pros

Share this post


Link to post
Share on other sites

Posted · Report post

I think I figured it out out. Except instead of just outputing the category, it outputs the word "Array" in front of the category.

 

If anyone doesn't mind taking a look at this code and letting me know what I did wrong, I'd have an answer and the community would have a helpful tip:

 

add_filter('pagelines_post_title_output','category_above_title');        
	function category_above_title($title){ 
	
$category = get_the_category(); 

if($category[0]){ 
	$category .= '<span class="categories sc"><a class="category" href="'.get_category_link($category[0]->term_id ).'">'. $category[0]->cat_name.'</a></span>';

}

$title = $category . $title;

return $title;
}

Share this post


Link to post
Share on other sites

Posted · Report post

Would it be possible for you to provide a concept image of what you're trying to achieve please.

Share this post


Link to post
Share on other sites

Posted · Report post

Ok. I started a new discussion. Thanks.

Share this post


Link to post
Share on other sites

Posted · Report post

@compression_institute Thanks for your cooperation.

Share this post


Link to post
Share on other sites

Posted · Report post

Sure. As context, I achieved the current style (see:

 

The only problem with this is it adds the category at the top of the "the_post", which is above the thumbnail image. I want this directly above the post title, below the thumbnail, like this: https://www.dropbox.com/s/hbktqnnt47fk2sj/Digital-Marketing-Blog-new.png.'>https://www.dropbox.com/s/hbktqnnt47fk2sj/Digital-Marketing-Blog-new.png.

Share this post


Link to post
Share on other sites

Posted · Report post

You'd have to provide a link to your site first, then we can try to help. :)

Share this post


Link to post
Share on other sites

Posted · Report post

With your site being in dev environment, its difficult to assist you further. What I suggest is installing Action Map which is a free plugin on the PageLines store and once active, will display all available hooks on your page, which you can then use in your code.

 

As I think the hook you're currently using isn't the correct one, especially if you wish to have it above the image, from your screenshot.

 

http://support.pagelines.me/docs/plugins/action-map/

Share this post


Link to post
Share on other sites