Jump to content
evanders

Move the category title above the post title?

Recommended Posts

Jenny    33
Jenny

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


Jenny :: Web designer at Simple Mama (follow me at @simplemamacom)

Check out Share Me, a social sharing add-on for DMS that is super simple to set up.

Share this post


Link to post
Share on other sites
Jenny    33
Jenny

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 :)


Jenny :: Web designer at Simple Mama (follow me at @simplemamacom)

Check out Share Me, a social sharing add-on for DMS that is super simple to set up.

Share this post


Link to post
Share on other sites
Jason M    1
Jason M

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
Danny    1,327
Danny

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


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
Rob    547
Rob

@compression_institute Thanks for your cooperation.


Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
evanders    0
evanders

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
Danny    1,327
Danny

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


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
evanders    0
evanders

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
Danny    1,327
Danny

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/


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
evanders    0
evanders

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
evanders    0
evanders

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
evanders    0
evanders

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×