Site logo

Archived topic

php code help

15 replies · Started by William on May 27, 2020

Viewing posts 1–15 of 16

Hello! Need help with 2 things

1. I wanted to use a static page as category archive so I used the PHP code mentioned on here

I used a snippet plugin to add it and it does take me to the static page. However, the problem is when I click on the post titles on the static page, instead of taking me to the post, it brings me back to the static page. Same thing happens on the homepage. The post design on my homepage includes category above title and when I turn the function on using the snippet plugin, everytime when I click the title (not category) of the post on the homepage it brings me to the static category page I created.

2. I try to make the author not clickable by using another PHP mnetioned here . I used the last function and it's still clickable.

By the way I disabled both PHP snippets because my site is live

Thank You

Hi Tom,

1. My permalink structure is site.com/category/postname

When I turn the snippet on for the PHP if I click on the post title, the URL is correct (site.com/category/postname) but the page it shows is the static category page not the post.

2. How do I remove the author link in the post also? The one inside the feature image.

Thank You!

Hi there,

1. not sure about this - template redirects are painful especially when cat-slugs are in the URL.
Whats the purpose of using static pages for Category Archives ? They're may be an alternative way.

2. In Appearance > Elements - edit the Header Element for the single post and remove the {{post_author}} template tag

Hi David,

1. So what I want to achieve is to make my category archive pages to look like the category static pages I created. Right now if you click on the category names those archive pages have different layout compared to the pages I created in the navigation bar. Once users click on the category, I want it to bring them to the same pages in the navigation bar.

2. I mean author link, not the text. I want to make author names non clickable

Thank You!

1. Ah, I've seen this before, but I don't believe we found a solution. That specific function just doesn't seem to work with that permalink structure. It might be worth asking over on https://wordpress.stackexchange.com/.

2. Try this:

add_filter( 'generate_page_hero_post_author', function() {
    return sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><span class="author-name" itemprop="name">%s</span</span>',
        esc_html( get_the_author_meta( 'display_name', $author_id ) )
    );
} );

Hi Tom,

Thank You, was able to get rid of the author link. As for the category archive, since I can't link category archives to a static page is there a way to edit/customize the category archives to at least look like the static pages I created in the navigation bar?

Thanks

Can you add these two PHP Snippets to your site:

add_filter( 'generate_header_entry_meta_items', function( $items ) {
    if ( is_archive() ) {
        $items = array(
            'categories',
        );
    } 
    return $items;
} );

add_filter( 'generate_footer_entry_meta_items', function( $items ) {
    if ( is_archive() ) {
        $items = array(
            'author',
        );
    } 
    return $items;
} );

This should move the Category above the title and place the author below.
Once done let me know so i can take a look at the CSS required

Hi David,

Just added the snippet. Also, any idea how to get rid of "by" in front of the author's names? Thank You!

Can you try this:

add_filter( 'generate_inside_post_meta_item_output', function( $output, $item ) {
	if ( 'author' === $item ) {
        return '';
    }
    return $output;
}, 50, 2 );

Hi Leo, Thank You! Was able to get rid of "by". Now just waiting on the CSS. Thanks!

Try adding this CSS:

.generate-columns-container article .inside-article {
    padding: 30px;
    box-shadow:1px 3px 5px 1px rgba(0, 0, 0, .09);
    text-align: center;
}
.generate-columns-container article .inside-article .post-image {
    margin: -30px -30px -30px -30px;
}
.generate-columns-container article .inside-article .post-image img {
    width: 100%;
}

.generate-columns-container .entry-header .cat-links a {
    display: inline-block;
    font-size: .75em;
    text-transform: uppercase;
    padding: .25em;
    background-color: #f2970e;
    color: #fff;
    min-width:100px;
    margin-bottom: 2em;
}
@media (max-width: 768px) {
    .generate-columns-container article {
        margin-left: 20px;
        margin-right: 20px;
    }
}

Hi David, I have some technical difficulties with the "code snippet" plugin after adding a php code with an error. I managed to contact my hosting company to delete the plugin, but once I reinstall, I get the error again. From what I read here: https://docs.generatepress.com/article/adding-php/ it says im able to delete the code through cpanel. Any idea where I can navigate to find the code?

Once i fix this issue I can then test out the CSS you provided since it requires php snippets. Thank You!

Hi David, Thanks! I'll give it a shot.

This archived topic is closed to new replies.