Home › Forums › Support › filter php to show blog post by category without header, navigation and footer
- This topic has 13 replies, 3 voices, and was last updated 3 years, 3 months ago by
David.
-
AuthorPosts
-
February 21, 2023 at 3:38 am #2540988
Cristiana
Hey there! 🙂
I need to create a category filter that only shows posts from that category with no header, navigation bar or footer.This is the result to be obtained.
https://magazine.dooid.it/vicinanze/toscana/Other than that.. I need to create a filter that recall a specific post through the post id. Also without showing header, navigation bar or footer.
this is the example.
https://magazine.dooid.it/segnalazione/36126/Thank you for the time and the help!
February 21, 2023 at 5:15 am #2541073David
StaffCustomer SupportHi there,
does it have to be a PHP Snippet?
As you can do it with the GP layout element:https://docs.generatepress.com/article/layout-element-overview/
Let me know.
February 21, 2023 at 6:55 am #2541189Cristiana
I think that this isn’t the right solution for me.
I need the filter only when I go to invoke it in the url. I don’t want this to be a general rule and always present on my site.February 21, 2023 at 7:35 am #2541229David
StaffCustomer SupportWhat would be special about that URL? eg. a URL Parameter.
If so, then you could:
1. create the Layout Element, and use that to disable the header etc.
2. But DO NOT set the Display Rules
3. Then use thegenerate_element_displayfilter to display that element when a custom condition is met, such as checking for a URL param:add_filter( 'generate_element_display', function( $display, $element_id ) { if ( 99 === $element_id && isset( $_GET['your-url-param'] ) ) { $display = true; } return $display; }, 10, 2 );Let me know.
February 22, 2023 at 10:29 am #2543002Cristiana
Thanks for your answer.
I’ll try to explain better the situation.The special thing about the link https://magazine.dooid.it/vicinanze/toscana/ is that by inserting the parameter “vicinanze” and changing “toscana” which is a category, it shows the category archive without header and footer.
By clicking on the articles shown in this list, they are presented without header and footer,too.————-
2nd necessityIn the link https://magazine.dooid.it/segnalazione/36126/
we have more or less the same functioning.“Segnalazione” is the parameter that allows you to see a certain article without foot and head.
“36126” instead is the post ID directly of the article.As I said I don’t need this rule to display on the whole site, but only when clicking on these links.
Thanks
February 22, 2023 at 7:40 pm #2543409Fernando Customer Support
Hi Cristiana,
It’s the same concept. The parameter is just added after.
In this way, no extra code is needed.
So, the example link would now be something like this with David’s code:
https://magazine.dooid.it/toscana/?your-url-paramYou can replace
your-url-paramwith anything you prefer.February 23, 2023 at 2:22 am #2543703Cristiana
thanks for your patience and help.
I’m a beginner with these things.
I created the layout element as David suggested.
but where should i put the code?February 23, 2023 at 6:33 am #2543958David
StaffCustomer SupportThe code is a PHP Snippet, this doc explains:
February 23, 2023 at 8:04 am #2544190Cristiana
Unfortunately I don’t understand what I have to do.
I had already read the guide you sent me, but I can’t apply it on the site.
Is it possible to organize a video call with screen sharing?
February 23, 2023 at 5:57 pm #2544756Fernando Customer Support
Sorry, we don’t offer video calls or screen sharing for our support service.
What exact step did you take to add it?
If you haven’t tried, can you install the plugin Code Snippets: https://wordpress.org/plugins/code-snippets/
1. In your Admin dashboard, go to Snippets > Add new.
2. Add your code and set it to “Run snippet everywhere”.
3. Click on “Save changes and activate”.
February 24, 2023 at 5:35 am #2545385Cristiana
Ok fine.
I downloaded the plugin as you told me, did the following steps you mentioned and added the code david suggested.and then?
thanks for your patience and help 🙂
February 24, 2023 at 6:13 am #2545434David
StaffCustomer Support1. Edit your Layout Element, and in the browser URL bar you will see the url, it will look something like this:
yourdomain.com/wp-admin/post.php?post=202&action=editThe
202is the ID, look for the ID of your Element and make a note of it.Then in the code snippet – for reference:
add_filter( 'generate_element_display', function( $display, $element_id ) { if ( 99 === $element_id && isset( $_GET['your-url-param'] ) ) { $display = true; } return $display; }, 10, 2 );Where there is the
99replace that with Element ID.Then where it says:
$_GET['your-url-param']change theyour-url-paramfor the parameter you want to use to activate the layout.February 28, 2023 at 8:33 am #2550198Cristiana
Thank you for the guide step by step.
I’ve just done these things. And now?February 28, 2023 at 11:06 am #2550396David
StaffCustomer SupportYou should now be able to use the link with the URL Param to make that work.
-
AuthorPosts
- You must be logged in to reply to this topic.