-
AuthorPosts
-
July 23, 2019 at 1:53 pm #1121200
Hello guys,
I want to display the parent page title within each posts of the postslider on my homepage. For example: It should display “Einfache Rezepte” at the end of the first post and “Rezepte für Kinder ” at the end of the second post and “Vegane Rezepte” at the end of the third page. Here you can see the parent-child structure:
I used the following code which displays the parent page title from the third post in all posts – whats wrong with this code?
apply_filters( 'the_title', get_the_title( wp_get_post_parent_id( get_the_ID() ) ) )
On the “Private Content” section you can find the website. I talk about the first section “Beliebteste DIY Badekugel-Rezepte des Monats”.
July 24, 2019 at 8:08 am #1121408Hey coolicious,
Thank you for using Enfold.
Sorry, I don’t seem to understand what you’re trying to do. Could you explain a bit further? Where did you put that code? It’s a PHP code so you can’t add it directly in the builder if in case that’s what you’re trying to do.
Best regards,
Ismael3July 24, 2019 at 1:34 pm #1121533Hello Ismael,
I added the code in the postslider.php in row 718:
$output .= !empty($excerpt) ? "<div class='slide-entry-excerpt entry-content' $markup>".$excerpt."</div><div>".apply_filters( 'the_title', get_the_title( wp_get_post_parent_id( get_the_ID() ) ) )."</div>" : "";
Like I described I want to display the titles of PARENT page (look at the screenshot for example “Einfache Rezepte” within the “post slider” modul from enfold on my homepage (Link in private content). Please look there at the first section of the homepage and you can see that only the title of the PARENT page of the last CHILD page displays on every post although they others CHILD pages have other PARENTs.
Is this more clear? :/
July 26, 2019 at 2:36 am #1122019Hi,
Thank you for the update.
How did you manage to display pages in the post slider? It’s not possible by default. Did you turn on the post type selection support?
Best regards,
IsmaelJuly 26, 2019 at 4:15 pm #1122183Hi,
my pages and posts use the same categories and tags – this is possible with the following code snippet which I included in the functions.php:
/* Kategorien & Tags to Pages */ function add_categories_to_pages() { register_taxonomy_for_object_type( 'category', 'page' ); } add_action( 'init', 'add_categories_to_pages' ); // add tag support to pages function tags_support_all() { register_taxonomy_for_object_type('post_tag', 'page'); } // ensure all tags are included in queries function tags_support_query($wp_query) { if ($wp_query->get('tag')) $wp_query->set('post_type', 'any'); }
Do you now understand my question and can help me with my problem?
July 29, 2019 at 6:52 am #1122644Hi,
Thank you for the info.
Have you tried moving it outside the “the_title” filter?
$output .= "<div class='slide-entry-excerpt entry-content' $markup>".$excerpt."</div><div>".get_the_title( wp_get_post_parent_id( get_the_ID() ) )."</div>" : "";
Best regards,
IsmaelJuly 29, 2019 at 9:56 pm #1122957Hey,
when I put this code instead of mine, then I get this error message (look at private content)!
Old Code:
$output .= !empty($excerpt) ? "<div class='slide-entry-excerpt entry-content' $markup>".$excerpt."</div><div class='fav-cats'><span class='cal-icon avia_button_icon avia_button_icon_left aria-hidden='true' data-av_icon='' data-av_iconfont='entypo-fontello'></span> ".apply_filters( 'the_title', get_the_title( wp_get_post_parent_id( get_the_ID() ) ) )."</div>" : "";
New Code:
$output .= "<div class='slide-entry-excerpt entry-content' $markup>".$excerpt."</div><div>".get_the_title( wp_get_post_parent_id( get_the_ID() ) )."</div>" : "";
Right so?
July 30, 2019 at 4:08 am #1123028Hi,
Sorry about that. We forgot to remove the “else” at the very end of the code. Look for this.
: "";
Take note of the spaces. Replace it with a semicolon to end the line. Or just replace the whole code with this:
$output .= "<div class='slide-entry-excerpt entry-content' $markup>".$excerpt."</div><div>".get_the_title( wp_get_post_parent_id( get_the_ID() ) )."</div>";
Best regards,
IsmaelJuly 30, 2019 at 5:18 pm #1123195No, that doenst work Ismael but I changed the way to display this posts. Now they are no more pages now they are posts.
Therefore I need a snippet to display just only the first subcategory of every post.Do you can help me with that maybe?
August 1, 2019 at 9:11 am #1123809Hi,
Thank you for the update.
You should be able get the category using the “get_the_terms” function. Usage examples can be found in the documentation.
// https://developer.wordpress.org/reference/functions/get_the_terms/
In your case, you can try this:
$cats = get_the_terms( get_the_ID(), 'category' ); $output .= "<div class='slide-entry-excerpt entry-content' $markup>".$excerpt."</div><div>".$cats[0]->name."</div>";
Best regards,
IsmaelAugust 1, 2019 at 1:27 pm #1123893Hi,
thank you for your code.
Right now it displays the parent category. How can I do that if I want to display only the first subcategory?
Thanks!
August 5, 2019 at 3:22 am #1124616Hi,
Thank you for the update.
Replace the get_the_terms with the get_term_children function.
// https://codex.wordpress.org/Function_Reference/get_term_children
Best regards,
IsmaelAugust 5, 2019 at 8:52 pm #1124883Thank you for your idea!
I used it in this way, right? But it doesnt show anything now:
$cats = get_term_children( get_the_ID(), 'category' ); $output .= !empty($excerpt) ? "<div class='slide-entry-excerpt entry-content' $markup>".$excerpt."</div><div class='fav-cats'><span class='cal-icon avia_button_icon avia_button_icon_left aria-hidden='true' data-av_icon='' data-av_iconfont='entypo-fontello'></span> ".$cats[0]->name."</div>" : "";
August 6, 2019 at 4:45 am #1124953Hi,
Thank you for the update.
This line:
$cats = get_term_children( get_the_ID(), 'category' );
.. should be replaced with:
$term_id = get_the_terms( get_the_ID(), 'category' ); $term_children = get_term_children( $term_id[0]->term_id, 'category' ); $output .= "<div class='slide-entry-excerpt entry-content' $markup>".$excerpt."</div><div>".$term_children[0]->name."</div>";
Best regards,
IsmaelAugust 6, 2019 at 9:02 am #1125011Thank you Ismael – but this doesnt work – there shows nothing except the icon :/ (Look at the private content)
I have the following code now:
$term_id = get_the_terms( get_the_ID(), 'category' ); $term_children = get_term_children( $term_id[0]->term_id, 'category' ); $output .= "<div class='slide-entry-excerpt entry-content' $markup>".$excerpt."</div><div class='fav-cats'><span class='cal-icon avia_button_icon avia_button_icon_left aria-hidden='true' data-av_icon='' data-av_iconfont='entypo-fontello'></span> ".$term_children[0]->name."</div>";
August 7, 2019 at 3:13 am #1125354Hi,
Can we have access to the file server? Please post the FTP details in the private field. We would like to test it.
Thank you for the update.
Best regards,
IsmaelAugust 7, 2019 at 12:20 pm #1125480Look at the private content :)
August 8, 2019 at 10:00 am #1125852Hi,
Thank you for the update.
We adjusted the code in the postslider.php file a bit.
$term_children = array(); $terms = wp_get_post_terms( $entry->ID, 'category' ); foreach ($terms as $term) { if( $term->parent == 0 ) { continue; } $term_children[] = $term->name; } $output .= "<div class='slide-entry-excerpt entry-content' $markup>".$excerpt."</div><div class='fav-cats'><span class='cal-icon avia_button_icon avia_button_icon_left aria-hidden='true' data-av_icon='' data-av_iconfont='entypo-fontello'></span> ".$term_children[0]."</div>";
It should now display the first sub category.
Best regards,
IsmaelAugust 8, 2019 at 10:05 am #1125855Hey Ismael,
thanks for your help.
Could you explain me how this works now? It shows only the sub category “Einfache Rezepte” althouth the posts are not in this sub category.
What should I do?
August 9, 2019 at 3:17 pm #1126242Hi,
My bad. I didn’t notice that.
We adjusted the code a bit. It now displays the “Rezept für Kinder” category. Is that correct?
Best regards,
IsmaelAugust 15, 2019 at 8:24 pm #1128042Hey Ismael,
I’m so sry but no this isnt correct. You hard coded it I think and that isnt the right way.
I change the posts there every month because this section displays the three favourite diy recipies of the month which change every month. And the recipies are in different categories not always on the same category. Therfore this category text depends of the first sub category which the recipe was sort in from me when I publish the recipe. You know now what I want there?August 19, 2019 at 1:53 am #1128767Hi,
I’m so sry but no this isnt correct. You hard coded it I think and that isnt the right way.
What do you mean? I didn’t “hard code” it or place that particular category directly in the shortcode file. You can test it by adding a different category.
Best regards,
IsmaelAugust 26, 2019 at 10:09 pm #1131117Hey Ismael,
it works now – I think it was the cache.
Thank you very much for your help!
Best regards!
August 28, 2019 at 3:49 pm #1131631 -
AuthorPosts
- The topic ‘How to display parent page title on postslider on homepage?’ is closed to new replies.