Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Which description are you trying to display? The one for low nutrients or for the various low-* categories listed? the_archive_description() uses the page’s query object to decide what to display. If the query is for low-nutrients, calling the_archive_description() should work for that particular term. But if the query is for a named page that contains another query for low-nutrient categories, it will not work.

    If you want to get the description for a category term, you need that term’s term ID. Then you can do
    <?php echo term_description( $term_id ); ?>
    If your intent is to display the description for each low-* category, within the loop generating each term’s output, the term object ought to be available in the loop. You need to examine the loop code to determine what variable is assigned the term object. Lets say the variable assigned the current term object is $term. Then in the loop you can do
    echo term_description( $term->term_id );

    Thread Starter Anthony Valentine

    (@npoutdoors)

    Ya i was hoping to show the description for each category. Low Sodium, Low Carb, Low Sugar etc….

    I’ll continue to dig around It’s tough when you have absolutely no knowledge in PHP haha

    Trial and error I guess!

    Thanks a lot,

    Anthony

    Thread Starter Anthony Valentine

    (@npoutdoors)

    I’m also having trouble finding where to even put the code once I figure it out.

    Moderator bcworkz

    (@bcworkz)

    Yes, finding the template being used for a particular page is a common problem. There are plugins that help you figure that part out. Though they may only tell you the main template. The part you need to edit could be in a sub-template.

    Sub-templates are usually loaded by a call to get_template_part(), though require or include statements could work. The template part function takes two arguments which are used together to compose the actual filename. I know you said you don’t know anything of PHP. If you at least have any sort of coding aptitude, you can figure this out. Define the WP_DEBUG constant as true in wp-config.php so you will be immediately notified of any PHP errors you introduce.

    If the output is due to the main query, the code starting the output loop typically starts with something like

    if ( have_posts()) {
      while ( have_posts()) {
        the_post();

    You may see colons : instead of curly braces { demarcating a block of code. Alternative syntax serving the same purpose.

    Secondary query loops can take the same form as the main query loop, but with class references, like $the_query->have_posts(). Sometimes the loop is simply a foreach statement, for example
    foreach ( $posts as $post ) {

    My examples are for displaying posts, but your category page is outputting terms, not posts, so expect variations. In the term case, the template may not even be a theme template, but from a plugin. If so, one of the template identification plugins might have trouble identifying the right template. It often comes down to making educated guesses confirmed by adding trial output and checking if the output appears on the page in question. If you still have trouble with plugin templates, you might need to ask in the plugin’s dedicated support forum for assistance.

    While it’s OK to temporarily alter templates to figure out the right file, you shouldn’t permanently alter the original template file. Whatever you change will be lost during the next update. To avoid this, you should create a child theme. You can copy over the applicable theme template to the child and edit as you see fit. For plugin templates, it’s not as easy. There still ought to be a way to override a plugin template, but alterations might also be possible by using filter hooks. If you see a apply_filters() call related to the output you wish to change on a template, you can use a hook from your child theme’s functions.php file. While a more advanced concept, hooks are preferable to directly altering templates.

    If you can identify the right template, I or someone else here should be able to help you work out the specifics that depend upon what the template code is actually doing.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display Category Descriptions on Custom Recipe Posts’ is closed to new replies.