Jump to content


Photo
* * * * - 1 votes

Move the category title above the post title?


Best Answer evanders , 29 January 2013 - 03:01 AM

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!

Go to the full post


  • Please log in to reply
16 replies to this topic

#1 evanders

evanders

    Member

  • Members
  • 23 posts
  • Country: Country Flag

Posted 27 January 2012 - 06:25 PM

How do I move the category title and move it above the post title as shown in the posts on this blog:

Please Login or Register to see this Hidden Content

?

#2 Jenny

Jenny

    Advocate

  • Unicorn Store Dev

  • 2924 posts
  • LocationWV
  • Country: Country Flag

Posted 27 January 2012 - 07:24 PM

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

#3 evanders

evanders

    Member

  • Members
  • 23 posts
  • Country: Country Flag

Posted 02 February 2012 - 04:24 PM

It's in a dev environment right now.

#4 Jenny

Jenny

    Advocate

  • Unicorn Store Dev

  • 2924 posts
  • LocationWV
  • Country: Country Flag

Posted 02 February 2012 - 05:30 PM

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

Please Login or Register to see this Hidden Content


Give thanks to @pross :)

#5 Jason M

Jason M

    Advanced Member

  • Members
  • 71 posts
  • Country: Country Flag

Posted 02 September 2012 - 03:07 AM

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 (

Please Login or Register to see this Hidden Content

). A primary category is listed above the title and several other categories are listed below the post.

#6 Danny

Danny

    Is Awesome!

  • Moderators
  • 15702 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 02 September 2012 - 10:19 AM

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

#7 Jason M

Jason M

    Advanced Member

  • Members
  • 71 posts
  • Country: Country Flag

Posted 03 September 2012 - 06:46 PM

Ok. I started a new discussion. Thanks.

#8 Rob

Rob

    One Smart Egg

  • Members
  • 13575 posts
  • LocationEast Coast, USA
  • Framework Version:The Latest, of course
  • Country: Country Flag

Posted 03 September 2012 - 10:30 PM

@compression_institute Thanks for your cooperation.

#9 evanders

evanders

    Member

  • Members
  • 23 posts
  • Country: Country Flag

Posted 26 January 2013 - 06:43 AM

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: 

Please Login or Register to see this Hidden Content

 

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:

 

Please Login or Register to see this Hidden Content

 

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:

Please Login or Register to see this Hidden Content



#10 Danny

Danny

    Is Awesome!

  • Moderators
  • 15702 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 27 January 2013 - 09:47 AM

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

#11 evanders

evanders

    Member

  • Members
  • 23 posts
  • Country: Country Flag

Posted 28 January 2013 - 02:12 AM

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

Please Login or Register to see this Hidden Content

) using the following hook:

 

Please Login or Register to see this Hidden Content

 

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: 

Please Login or Register to see this Hidden Content



#12 evanders

evanders

    Member

  • Members
  • 23 posts
  • Country: Country Flag

Posted 28 January 2013 - 02:17 AM

Whoops, this is an image of what I am trying to achieve: 

Please Login or Register to see this Hidden Content



#13 Danny

Danny

    Is Awesome!

  • Moderators
  • 15702 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 28 January 2013 - 07:52 AM

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.

 

Please Login or Register to see this Hidden Content



#14 evanders

evanders

    Member

  • Members
  • 23 posts
  • Country: Country Flag

Posted 29 January 2013 - 01:57 AM

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



#15 Rob

Rob

    One Smart Egg

  • Members
  • 13575 posts
  • LocationEast Coast, USA
  • Framework Version:The Latest, of course
  • Country: Country Flag

Posted 29 January 2013 - 02:34 AM

Hi,

 

We have a number of pro developers available at

Please Login or Register to see this Hidden Content



#16 evanders

evanders

    Member

  • Members
  • 23 posts
  • Country: Country Flag

Posted 29 January 2013 - 02:48 AM

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:

 

Please Login or Register to see this Hidden Content



#17 evanders

evanders

    Member

  • Members
  • 23 posts
  • Country: Country Flag

Posted 29 January 2013 - 03:01 AM   Best Answer

Nevermind. Figured it out:

 

Please Login or Register to see this Hidden Content

 

Enjoy!