Viewing 24 posts - 1 through 24 (of 24 total)
  • Author
    Posts
  • #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”.

    #1121408

    Hey 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,
    Ismael3

    #1121533

    Hello 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? :/

    #1122019

    Hi,

    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,
    Ismael

    #1122183

    Hi,

    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?

    #1122644

    Hi,

    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,
    Ismael

    #1122957

    Hey,

    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?

    #1123028

    Hi,

    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,
    Ismael

    #1123195

    No, 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?

    #1123809

    Hi,

    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,
    Ismael

    #1123893

    Hi,

    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!

    #1124616

    Hi,

    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,
    Ismael

    #1124883

    Thank 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>" : "";
    #1124953

    Hi,

    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,
    Ismael

    #1125011

    Thank 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>";
    #1125354

    Hi,

    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,
    Ismael

    #1125480

    Look at the private content :)

    #1125852

    Hi,

    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,
    Ismael

    #1125855

    Hey 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?

    #1126242

    Hi,

    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,
    Ismael

    #1128042

    Hey 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?

    #1128767

    Hi,

    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,
    Ismael

    #1131117

    Hey Ismael,

    it works now – I think it was the cache.

    Thank you very much for your help!

    Best regards!

    #1131631

    Hi,

    Great! Glad to hear. Please feel free to open a new thread if you need anything else.

    Have a nice day.

    Best regards,
    Ismael

Viewing 24 posts - 1 through 24 (of 24 total)
  • The topic ‘How to display parent page title on postslider on homepage?’ is closed to new replies.