Support » Plugin: List category posts » Show the parent page after the page title

  • Resolved rughooker

    (@rughooker)


    I use this plug in for many different things. Thank you.

    I have a site with courses and I am using AccessAlly. I want to list the lessons from all courses that have the search term. I’ve been able to do that using this:

    `[catlist search=”texture sampler” orderby=parent]’

    But it would be helpful if the course name (the parent page title) would show after each post.

    Current results:
    05-08-20 Bird Nest

    I would like to see:
    05-08-20 Bird Nest 2020 Replays

    Where 2020 Replays is the title of the parent page.

    Is this possible?

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Contributor zymeth25

    (@zymeth25)

    Displaying content from parent posts/pages is currently not supported by the shortcode but it can be coded in a custom template.

    Thread Starter rughooker

    (@rughooker)

    I’ve Googled the sh*t out of this for the past 3 hours. I can continue working, but I want to be sure I am on the right track. I will need to create a function that will pull the parent title, let’s call that course_title.

    Then I need to add to the template
    $lcp_display_output .= $this->course_title($post);

    Am I on the right track?

    Plugin Contributor zymeth25

    (@zymeth25)

    WordPress has so many built in functions that it is rarely necessary to write your own. In your case you can use the get_the_title function like so:
    $lcp_display_output .= get_the_title($post->post_parent);

    Thread Starter rughooker

    (@rughooker)

    The parent title still does not show on the page. Do I need to add something to the shortcode to make it show up? This is the excerpt where I added the code to the template file, stored in wp-content/themes/mytheme/list-category-posts/cindilist.php. Lines 76 & 77 are the ones I added:

    73 //Show the title and link to the post:
    74 $lcp_display_output .= $this->get_post_title($post);
    75
    76 //Display Parent name: Added to template by Cindi 1/21/21
    77 $lcp_display_output .= $this->get_the_title($post->post_parent);
    78
    79 //Show comments:
    80 $lcp_display_output .= $this->get_comments($post);

    This is the shortcode I am using:
    [catlist search=”texture sampler” template=cindilist excludeposts=this]

    • This reply was modified 10 months, 2 weeks ago by .
    Plugin Contributor zymeth25

    (@zymeth25)

    I think we might have a misunderstanding here. The code that I sent would grab the title of the parent but in WordPress only pages can have parents, not posts. When adding a new page you can see under “Page Attributes” that you can specify a parent page, but you can’t do it for posts.

    My code is not displaying anything because the posts have no parents. My guess is by “parent page” you mean the page the posts were originally published on or maybe it matches their category?

    • This reply was modified 10 months, 2 weeks ago by zymeth25.
    Thread Starter rughooker

    (@rughooker)

    No, It is pulling pages and the pages are being listed beautifully, but the parent is not displaying after the page title. I’m not sure why I did not need post_type=”page”

    Plugin Contributor zymeth25

    (@zymeth25)

    I’m not sure why I did not need post_type=”page”

    If you are 100% sure they are pages not posts then some other plugin or theme is modifying the query and allowing pages through.

    but the parent is not displaying after the page title

    Maybe your template is not being pulled properly. To verify please test this by adding your changes to the plugin’s default template at wp-content/plugins/list-category-posts/templates/default.php.

    Remove the changes once you have finished testing and let me know of the result.

    Thread Starter rughooker

    (@rughooker)

    It must be a major plug-in issue. This is an online course site, so the plug-ins win.

    I made the change, but the parent name did not pull through when I added the code to the default template in its original location.

    If I add:

    [catlist search=”texture sampler” template=cindilist excludeposts=this post_parent=’296′ conditional_title=”Practical Color Planning”]

    it breaks everything up by parent, but I would have to include a list of dozens of short codes to search the entire site just for one set of results.

    I can do this with text expander quickly, but it is not future proof if I add more parents…..

    I allowed myself one day for this rabbit hole. I think I have to let it go. I learned more about this plugin during this exploration. I love the conditional_title option. Never noticed that before. Thanks for your help.

    Plugin Contributor zymeth25

    (@zymeth25)

    It is hard to explain why the parent’s title is not displayed though. It works on my end so there must be something odd going on in your setup. If you want to troubleshoot further you could start disabling other plugins one by one and see which one causes this.

    Thread Starter rughooker

    (@rughooker)

    Recreated all the steps and now I get this message:

    Does this point to an error? I cannot make heads or tails of this except that line 77 is the line I added.

    Fatal error: Uncaught Error: Call to undefined method CatListDisplayer::get_the_title() in /home/customer/www/howtorughook.com/public_html/wp-content/themes/authority-pro 1.5/list-category-posts/cindidefault.php:77 Stack trace: #0 /home/customer/www/howtorughook.com/public_html/wp-content/plugins/list-category-posts/include/lcp-catlistdisplayer.php(37): require() #1 /home/customer/www/howtorughook.com/public_html/wp-content/plugins/list-category-posts/include/lcp-catlistdisplayer.php(30): CatListDisplayer->create_output() #2 /home/customer/www/howtorughook.com/public_html/wp-content/plugins/list-category-posts/list-category-posts.php(170): CatListDisplayer->display() #3 /home/customer/www/howtorughook.com/public_html/wp-includes/shortcodes.php(343): ListCategoryPosts::catlist_func(Array, ”, ‘catlist’) #4 [internal function]: do_shortcode_tag(Array) #5 /home/customer/www/howtorughook.com/public_html/wp-includes/shortcodes.php(218): preg_replace_callback(‘/\\[(\\[?)(catlis…’, ‘do_shortcode_ta…’, ‘\r\n[catlist sear…’ in /home/customer/www/howtorughook.com/public_html/wp-content/themes/authority-pro 1.5/list-category-posts/cindidefault.php on line 77
    There has been a critical error on this website. Please check your site admin email inbox for instructions.

    Learn more about debugging in WordPress.

    Plugin Contributor zymeth25

    (@zymeth25)

    Ah, the problem is in your template, you added this:

    76 //Display Parent name: Added to template by Cindi 1/21/21
    77 $lcp_display_output .= $this->get_the_title($post->post_parent);

    but should have just pasted what I had written, without $this like so:

    76 //Display Parent name: Added to template by Cindi 1/21/21
    77 $lcp_display_output .= get_the_title($post->post_parent);
    Thread Starter rughooker

    (@rughooker)

    Got it to work!!!

    Is there a way to put a space or other text such as :space after the title but before the parent? Or even a <span> with a class so I can style the parent differently?

    Plugin Contributor zymeth25

    (@zymeth25)

    $lcp_display_output .= '<span class="something">' . get_the_title($post->post_parent) . '</span>';

    Or you could separate it in multiple lines like the rest of the template file. Just remember enclose HTML in quotes.

    Thread Starter rughooker

    (@rughooker)

    It works! Thank you so much for your help.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Show the parent page after the page title’ is closed to new replies.