Support » Plugin: Category to Pages WUD » Category Description Query

  • Resolved jondewitt

    (@jondewitt)


    Hi @wistudatbe – great plugin. I am using it to easily organize pages in a way that isn’t necessarily friendly with child/parent relationships. However there’s one thing I am not sure how to accomplish, specifically in my template files.

    I am trying to output the content of my category description (from admin) on my page template file. Is there currently any way to do this? I can see they are saved in the _term_taxonomy table, but I am not sure how to access them.

    I am accessing the category titles by using:
    get_the_term_list( $post->ID, ‘categories’ )

    Thank you for any assistance.

    • This topic was modified 8 months ago by  jondewitt.
    • This topic was modified 8 months ago by  jondewitt.
Viewing 9 replies - 1 through 9 (of 9 total)
  • jondewitt

    (@jondewitt)

    I figured this out by myself using an SQL query but boy would it be great if this plugin could be updated with some helper functions such as: get_pagecat_title(), get_pagecat_description() and get_pagecat_children();

    My solution:

    
    $table_prefix = $wpdb->prefix;
    
    $query = "
        SELECT taxonomy.description
        FROM {$table_prefix}terms as terms, {$table_prefix}term_taxonomy as taxonomy
        WHERE terms.term_id = taxonomy.term_id AND terms.name = %s
        ";
    
    $desc = $wpdb->get_var($wpdb->prepare($query, $cat_title));
    
    echo $desc;
    
    Plugin Author Danny WUD

    (@wistudatbe)

    Hi @jondewitt,

    Thanks for using my plugin!
    I need some time to extend this plugin with more features.
    At this moment i’m too busy to accomplish it and will try to do this next month.
    Thank you for this extra tips/information and approach to solve it.

    Regards,
    Danny

    jondewitt

    (@jondewitt)

    Hi @wistudatbe, I have figured out a solution for another request of mine, listing all pages in the same category as the current page:

    
    <?php
        global $post;
        $term_list = wp_get_post_terms($post->ID, 'categories', array("fields" => "ids"));
        $cat_id = array_values($term_list)[0];
        $args = array(
            'post_type' => 'page',
            'tax_query' => array(
                array(
                    'taxonomy' => 'categories',
                    'field' => 'id',
                    'terms' => $cat_id
                )
            )
        );
    
        $related = get_posts($args);
        foreach ( $related as $post ) : setup_postdata( $post ); ?>
            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
        <?php
        endforeach;
        wp_reset_postdata();
    ?>
    

    It could probably be nicer but works for now!

    I look forward to your updates.

    Plugin Author Danny WUD

    (@wistudatbe)

    Hi jondewit,

    I continue next month developing (extending) this plugin.
    If possible i will add these features and let you know the results.

    Regards, Danny

    Plugin Author Danny WUD

    (@wistudatbe)

    Hi jondewit,

    If you can add this to version 2.2.0 and you can send me the zip file, i can check it or it runs well and apply it to one of the next releases.
    You can send this file + instructions to support [at] wud-plugins.com .

    Regards,
    Danny

    Plugin Author Danny WUD

    (@wistudatbe)

    Hi jondewit,
    I will add a shortcode for the list page URLS from the same category.
    The shortcode will have a parameter to define how many page URLS must be showed.

    The shortcode can be used in a widget or inside a page content.
    Regards, Danny

    Plugin Author Danny WUD

    (@wistudatbe)

    Hi jondewit
    Concerning your initial question: Category Description Query.
    This can be done by shortcodes:
    [wudcatlist] = Displays categories as list. –
    [wudtaglist] = Displays tags as list.
    [wudcatdrop] = Displays categories as drop down. –
    [wudtagdrop] = Displays tags as drop down.

    Regards, Danny

    Plugin Author Danny WUD

    (@wistudatbe)

    Hi @jondewit

    In version 2.2.6 will be a new shortcode available, which shows the related post and/or pages.
    This is the code:

    
    if(!function_exists('cattopage_wud_short_code_page_list')){
    	function cattopage_wud_short_code_page_list($atts) {
    		global $post;
    		$max_posts = -1;
    		$post_typ = array('page','post');
    		if(isset($atts["max"]) && $atts["max"]!='' ){			
    			if(is_numeric($atts["max"]) && $atts["max"] > 0 && $atts["max"] == round($atts["max"], 0)){
    				$max_posts = trim(filter_var($atts["max"], FILTER_SANITIZE_STRING));
    			}
    		}	
    		if(isset($atts["type"]) && $atts["type"]!='' ){
    			if($atts["type"] == 'page'){
    				$post_typ = array('page');
    			}
    			elseif($atts["type"] == 'post'){
    				$post_typ = array('post');
    			}
    		}		
    		$related_args = array(
    			'post_type' => $post_typ,
    			'posts_per_page' => $max_posts,
    			'post__not_in' => array($post->ID),
    		);
    		$related = new WP_Query( $related_args );
    
    		if( $related->have_posts() ) :
    		?>
    		<div>
    			<h3>Related posts</h3>
    				<?php while( $related->have_posts() ): $related->the_post(); ?>
    					<li><a href="<?php the_permalink(); ?>" style="text-decoration: none;"><?php the_title(); ?></a></li>
    				<?php endwhile; ?>
    		</div>
    		<?php
    		endif;
    		wp_reset_postdata();
    	}
    }
    

    Regards, Danny

    Plugin Author Danny WUD

    (@wistudatbe)

    Here are the shortcodes (from version 2.2.6 on!)
    [wudrelated] = Displays all related post and/or pages.
    [wudrelated max=”5″] = Displays maximum 5 related post and/or pages
    [wudrelated type=”page”] = Displays all related pages
    [wudrelated type=”post”] = Displays all related posts

    Regards, Danny

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.