- This topic has 14 replies, 2 voices, and was last updated 1 year, 10 months ago by David.
-
AuthorPosts
-
May 26, 2022 at 5:40 am #2233299René
Hello,
I would like to create several subpages where a different table & text should be displayed at the top according to the post. The table & the text should cover the full width of the page and then the sidebar and the rest of the content begins below.
Of course, I could create a separate hook element for each subpage, but that would be far too time-consuming, because well over 100 subpages are to be created in this layout.
Here is a graphic that shows how the layout should look like: https://ibb.co/VHXz73T
Is there a better way to do this in GP? Thanks very much
May 26, 2022 at 6:17 am #2233347DavidStaffCustomer SupportHi there,
how and where is that table and text saved on your site ?
June 12, 2022 at 3:09 am #2250769RenéHey David,
sorry for my late aswer. It is the AAWP (Plugin) Table and i insert it via a Custom Field. The text should be taken from the normal post editor. As I said, several posts should be created and I don’t want to have to create a hook for each post. Here is an example: https://www.vergleich.org/arbeitssocken/ The sidebar starts below the table.
Sorry for my bad english.
June 12, 2022 at 6:43 am #2250903DavidStaffCustomer Supportand i insert it via a Custom Field
What exactly is it you insert in the custom field? Is it a shortcode ?
June 12, 2022 at 7:07 am #2250924RenéYes, the Table is a Shortcode from AAWP.
June 12, 2022 at 7:11 am #2250930DavidStaffCustomer SupportYou could do something like this:
add_action('generate_after_entry_header', function(){ $aawpfield = get_post_meta( get_the_id(), 'your_custom_field_name', true ); if ( $aawpfield && is_single() ) { echo do_shortcode( $aawpfield ); } });
Just update the
your_custom_field_name
to match your custom field.If you want to do it in a GP HooK Element you only need:
<?php $aawpfield = get_post_meta( get_the_id(), 'your_custom_field_name', true ); if ( $aawpfield && is_single() ) { echo do_shortcode( $aawpfield ); } ?>
June 12, 2022 at 7:14 am #2250934RenéThank you for your prompt reply. Then that would be clarified with the table 🙂 But how do I do that with the text?
June 12, 2022 at 8:18 am #2251102DavidStaffCustomer SupportIs the text also dynamic ? Where does that come from ?
June 12, 2022 at 8:30 am #2251114Renéas previously mentioned, the text should be taken from the normal editor. It is enough if the first paragraph is taken. I have already written a PHP script that reads the text of the first paragraph and displays it at the top. Unfortunately, the paragraph is then displayed twice and I have to hide one with CSS. But it’s not a nice solution.
June 12, 2022 at 8:34 am #2251115Renéif there is no good solution for this in the theme, maybe you could put the content in the editor to be displayed above in a shortcode. But my programming skills are not enough for that.
June 12, 2022 at 8:36 am #2251123DavidStaffCustomer SupportWe don’t interfere with the Editor, there are some options:
1, Use the manual Excerpt field to add your text.
2. Use a custom field to store the text. I would recommend using ACF for that Custom Field as it will allow you to store Rich TextJune 12, 2022 at 8:41 am #2251126RenéThen I’ll probably stay with my PHP script, which reads the first paragraph and places it above (copies). But maybe you have a script for me that removes the copied paragraph (the original)? So far I only hide the second paragraph with CSS. I don’t know how Google interprets that
June 12, 2022 at 9:20 am #2251152DavidStaffCustomer SupportCan you share the code you’re using to extract the first paragraph? As you should be able to include a string replace to remove it too.
June 12, 2022 at 10:22 am #2251185RenéA programmer friend of mine (https://github.com/Lightweb-Media) has now helped me out. Here’s the code
Functions.php:
function get_first_para($content){ $output = preg_match_all('%(<p[^>]*>.*?</p>)%i', $content, $matches); $first_para = $matches [1] [0]; return $first_para; } function remove_first_para($content, $first_para){ return str_replace($first_para, "",$content); } add_filter( 'the_content', 'filter_the_content_in_the_main_loop', 10,1); function filter_the_content_in_the_main_loop( $content ) { // Check if we're inside the main loop in a single Post. if ( is_singular() && in_the_loop() && is_main_query() ) { $first_para = get_first_para($content); $content = remove_first_para($content, $first_para); return $content; } return $content; }
Header.php:
do_action( 'generate_after_header' ); ?> <div <?php generate_do_attr( 'page' ); ?>> <div style="padding: 20px 10px 0px 10px;"> <?php /** * generate_inside_site_container hook. * * @since 2.4 */ if (is_page_template('page-wide-table.php')) { the_title( '<h1>', ': Die besten Produkte im Vergleich ('. do_shortcode("[aktuelles_jahr]").')</h1>'); $first_para = get_first_para(get_the_content()); $first_para = str_replace("[aktuelles_jahr]", do_shortcode("[aktuelles_jahr]") , $first_para); echo '<p>'.$first_para.'</p>'; echo do_shortcode(get_post_meta($post->ID, 'cf-wide-table', true)); } ?> </div> <?php do_action( 'generate_inside_site_container' ); ?>
Now it works, fine. Still not the best solution, but ok.
June 13, 2022 at 2:49 am #2251733DavidStaffCustomer SupportGlad to hear you got a solution. And thanks for sharing that.
-
AuthorPosts
- You must be logged in to reply to this topic.