- This topic has 15 replies, 3 voices, and was last updated 3 years, 11 months ago by
Tom.
-
AuthorPosts
-
June 12, 2019 at 5:31 am #926821
Carlo
looking to style my published pages and posts and inside of the content (not the header element) im wanting to add some extra element, so seeing if it is possible to do so?
this is what im trying to achieve.
category (styled with underline and color)
H1 title
author image & name | Date (published or updated)
note, as i mentioned, i want to add this info to my pages too as ive used the category plugin to set categories for my pages too.
im ok if i need to use shortcodes or whatever i need to do to try and accomplish it.
thanks
June 12, 2019 at 8:34 am #927187Leo
StaffCustomer SupportHi there,
These two articles should help you to get started:
https://generatepress.com/forums/topic/display-post-categories-above-title/#post-645410
https://docs.generatepress.com/article/entry-meta-style/#example-1Let me know 🙂
June 13, 2019 at 2:54 am #928072Carlo
thanks Leo,
1. got the categories to show above the H1 title, but how can i make categories visible inside of pages? i am using the Category Tag Pages plugin to assign categories to pages currently.
2. any way to style the categories text at the top of the posts (and pages)? i would like to remove the folder icon and make the category text all capitals.
3.i added the entry meta style (example-1) and got that working fine, i also wanted it to be added to pages so i added the snipped code…
add_action( ‘generate_after_entry_header’, ‘tu_page_meta’ );
function tu_page_meta() {
if ( ‘page’ == get_post_type() ) : ?><?php generate_posted_on(); ?><!– .entry-meta –>
<?php endif;
}the code above does work, except author icon, name and date are on every single page, home page , category pages, privacy policy… any way to filter it so it only shows on certain pages? or exclude certain pages?
4. trying to add the following additions from this page https://docs.generatepress.com/article/generate_post_date_output/
-Only Show Updated Date
-Add Icon to Date
-Remove Link from Datebut not getting any of those to have any effect when i add them via snippets?
is it because ive use the code from https://docs.generatepress.com/article/entry-meta-style/#example-1?thanks
June 13, 2019 at 8:35 am #928579Leo
StaffCustomer SupportCan we try one thing at the time?
Try this snippet for #1 first and see if it works:
add_filter( 'generate_category_list_output','lh_remove_categories' ); function lh_remove_categories( $categories ) { return ''; } add_action( 'generate_before_entry_title','lh_single_cats_above_title' ); function lh_single_cats_above_title() { $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) ); if ( $categories_list ) { printf( '<span class="entry-meta cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', _x( 'Categories', 'Used before category names.', 'generatepress' ), $categories_list ); } }
June 14, 2019 at 12:49 am #929198Carlo
unfortunately that made no difference.
i deactivated the old snipped from this link: https://generatepress.com/forums/topic/display-post-categories-above-title/#post-645410
and activated the one you just mentioned but still the same result. it shows on “posts” but not on “pages”.
any other ideas?
also if we get this working well, will it be possible to exclude certain pages from show the category tag? like homepage, category pages ect..?June 14, 2019 at 8:34 am #929715Leo
StaffCustomer SupportHmm I guess
generate_before_entry_title
hook doesn’t exist on static pages.Can you give this a shot?
add_action( 'generate_before_content','lh_single_cats_above_title' ); function lh_single_cats_above_title() { $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) ); if ( $categories_list ) { printf( '<span class="entry-meta cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', _x( 'Categories', 'Used before category names.', 'generatepress' ), $categories_list ); } }
June 15, 2019 at 12:13 am #930222Carlo
ok that worked, got the “categories” to show in pages.
now, is there a way to filter this so not show the category on certain pages (like homepage, privacy ect..)
how about filter out anything that has a “uncategorized” category?
June 15, 2019 at 9:01 am #930670Tom
Lead DeveloperLead DeveloperI would:
1. Create a Hook Element: https://docs.generatepress.com/article/hooks-element-overview/
2. Set the hook tobefore_content
3. Check the “Execute PHP” checkbox
4. Add this Hook content:<?php $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) ); if ( $categories_list ) { printf( '<span class="entry-meta cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', _x( 'Categories', 'Used before category names.', 'generatepress' ), $categories_list ); } ?>
Then you can use the Display Rules to choose where (or where not) to include the hook.
June 15, 2019 at 6:19 pm #930933Carlo
got that working fine Tom, thankyou.
i filtered out certain categories so now only showing where it needs to 🙂As far as styling the “category” text that is above the H1 Title,
1.how can we remove the “folder icon” before the category?
2.make the category text in capitals
3.underline the category text (with a colored line)June 16, 2019 at 8:28 am #931439Tom
Lead DeveloperLead DeveloperGive this CSS a shot:
.entry-meta.cat-links:before { display: none; } .entry-meta.cat-links { text-transform: uppercase; border-bottom: 1px solid red; display: inline-block; }
June 16, 2019 at 4:58 pm #931704Carlo
that looks so good. very happy with that, now just a few small things and it’ll be exactly as i was hoping for.
im currently using the following php code and CSS to show entry meta data.
from: https://docs.generatepress.com/article/entry-meta-style/#example-1i have been trying to adjust the publish date with no effect? have used the code from:
https://docs.generatepress.com/article/generate_post_date_output/
but the only change was a second date became visible when i activated it.How can i make the following changes:
-Remove Link from Date
-Show Updated Date- with the word “Updated” before the date (if more that 1 week from original publish date – is this possible?)June 17, 2019 at 9:00 am #932482Tom
Lead DeveloperLead DeveloperHi there,
Try this function instead of the one from docs:
add_filter( 'generate_post_author', '__return_false' ); add_filter( 'generate_show_comments', '__return_false' ); add_filter( 'generate_post_date_output', function( $date, $time_string ) { printf( ' <span class="byline">%1$s</span>', sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>', esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ), esc_html( get_the_author() ), get_avatar( get_the_author_meta( 'ID' ) ) ) ); if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) { echo '<span class="comments-link">'; comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) ); echo '</span>'; } printf( '<span class="posted-on">%s</span>', $time_string ); }, 10, 2 );
As for the updated date, try this: https://docs.generatepress.com/article/show-the-updated-post-date/
June 17, 2019 at 6:48 pm #932837Carlo
Hy Tom, if i deactivate the old snippet and replace it with the new one i get:
The site is experiencing technical difficulties. (and page wont load) i deactivate it and all goes back to normal.
any other ideas?
Just so were on the same page, this is what i’ve currently got thats working, but wont allow the date adjustments i mentioned earlier:add_filter( 'generate_post_author', '__return_false' ); add_filter( 'generate_show_comments', '__return_false' ); add_filter( 'generate_post_date_output', 'tu_fancy_byline' ); function tu_fancy_byline( $date ) { printf( ' <span class="byline">%1$s</span>', sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>', esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ), esc_html( get_the_author() ), get_avatar( get_the_author_meta( 'ID' ) ) ) ); if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) { echo '<span class="comments-link">'; comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) ); echo '</span>'; } echo $date; }
June 18, 2019 at 6:31 am #933293Tom
Lead DeveloperLead DeveloperCan you try the updated code here?: https://generatepress.com/forums/topic/add-author-image-name-date-and-category-to-posts-and-pages/#post-932482
June 18, 2019 at 6:47 am #933324Carlo
That worked, the link is removed from the date now.
Just one more thing and were done..Is it possible to work out a solution for this?
Show Updated Date- with the word “Updated” before the date (if more that 1 week from original publish date) -
AuthorPosts
- You must be logged in to reply to this topic.