Category name post on page

NapitWPTech Theme Support Forums Masonry Brick Category name post on page

Tagged: 

This topic contains 9 replies, has 2 voices, and was last updated by  Bishal Napit 7 months, 2 weeks ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #155

    Fra79Valex
    Participant

    hello and congratulations for your theme Masonry Bricki!
    I wanted to ask if it is possible to add in the post on the home page, the name of the category
    Thanks for your help

    #156

    Bishal Napit
    Keymaster

    Hi Fra79Valex,

    For adding the category names of the posts to the home, search as well as the archive pages too, you can create a child theme and make the adjustments via using the child theme. You can find the tutorial on creating the WordPress child theme here: https://napitwptech.com/tutorial/wordpress-development/tutorial-creating-wordpress-child-theme/.

    Here, in the child theme, you might need to duplicate the file template-parts/content.php of the parent theme and then find this below code:

    <?php if (is_single()) : ?>
    	<footer class="entry-footer">
    		<?php masonry_brick_entry_footer(); ?>
    	</footer><!-- .entry-footer -->
    <?php endif; ?>

    in the same file and then just update the code via the code provided below and check:-

    <footer class="entry-footer">
    	<?php masonry_brick_entry_footer(); ?>
    </footer><!-- .entry-footer -->

    Also, in order to hide the display of tag if any, you can try this CSS code in the Additional CSS Box provided via the Customizer Options and check:

    .home .tags-links, .archive .tags-links, .search .tags-links {
    	display: none;
    }

    If you like the theme and appreciate the work put out on the theme, then, you can help by rating this theme through this link here: https://wordpress.org/support/theme/masonry-brick/reviews/

    Thanks.
    Bishal Napit

    #157

    Fra79Valex
    Participant

    Hello
    I copied the file “content.php” within the child theme, I modified the code as I’ve indicated, but how do I show the category name associated with the post?
    thanks

    #158

    Bishal Napit
    Keymaster

    Hi Fra79Valex,

    Have you done all of the above customization as mentioned and copied the required file exactly in the same structure as same in the main theme file? Also, if you have only one category added in your site, then, could you add other category too in your site and check? Also, adding the code in this way will display the category of the post in the above mentioned pages. Nothing more is required to do other than this to achieve the exact goal.

    Thanks.
    Bishal Napit

    #159

    Fra79Valex
    Participant

    I put the content file on the root folder of child theme, I tried to put it in a brick-child folder / template-parts / .. but me error page, I disappears around the site EXCEPT header …
    I have to file Put a code TO TOP perhaps?

    content.php. Here is my file

    <?php

    /**

    * Template part for displaying posts.

    *

    * @link https://codex.wordpress.org/Template_Hierarchy

    *

    * @package Masonry Brick

    */

    ?>

    <article id=”post-<?php the_ID(); ?>” <?php post_class(‘masonry-content’); ?>>

    <?php do_action(‘masonry_brick_before_post_content’); ?>

    <?php if (has_post_thumbnail()) : ?>

    <?php if (!is_single()) : ?>

    <figure class=”featured-image”>

    ” title=”<?php the_title_attribute(); ?>”><?php the_post_thumbnail(‘masonry-brick-featured-thumbnail’); ?>

    </figure>

    <?php endif; ?>

    <?php endif; ?>

    <div class=”post-wrapper”>

    <header class=”entry-header”>

    <?php

    if (is_single()) {

    the_title(‘<h1 class=”entry-title”>’, ‘</h1>’);

    } else {

    the_title(‘<h2 class=”entry-title”>‘, ‘</h2>’);

    }

    if (‘post’ === get_post_type()) :

    ?>

    <div class=”entry-meta”>

    <?php masonry_brick_posted_on(); ?>

    </div><!– .entry-meta –>

    <?php endif;

    ?>

    </header><!– .entry-header –>

    <div class=”entry-content”>

    <?php

    if (is_single()) :

    the_content();

    else :

    if (is_sticky()) :

    // displaying full content for the sticky post

    the_content(sprintf(

    /* translators: %s: Name of current post. */

    wp_kses(‘<button type=”button” class=”btn continue-more-link”>’ . __(‘Read More <i class=”fa fa-arrow-circle-o-right”></i>’, ‘masonry-brick’) . ‘</button> %s’, array(‘i’ => array(‘class’ => array()), ‘button’ => array(‘class’ => array(), ‘type’ => array()))), the_title(‘<span class=”screen-reader-text”>”‘, ‘”</span>’, false)

    ));

    else :

    the_excerpt(); // displaying excerpt for the archive pages

    endif;

    endif;

    wp_link_pages(array(

    ‘before’ => ‘<div class=”page-links”>’ . esc_html__(‘Pages:’, ‘masonry-brick’),

    ‘after’ => ‘</div>’,

    ));

    ?>

    </div><!– .entry-content –>

    <?php if (is_single()) : ?>

    <footer class=”entry-footer”>
    <?php masonry_brick_entry_footer(); ?>
    </footer><!– .entry-footer –>

    </div>

    <?php do_action(‘masonry_brick_after_post_content’); ?>

    </article><!– #post-## –>

    #160

    Bishal Napit
    Keymaster

    Hi Fra79Valex,

    The file needs to be probably reside inside the folder named as template-parts, which need to be inside the child theme root folder. The file name also need to be content.php. So, the final file structure for this in the child theme should be like this: child_theme_folder_name/template-parts/content.php.

    Also, I see that the code is not modified as stated above. It looks like exactly the same as the parent theme file. So, could you create the above file in child theme and then paste this below PHP code instead and check:-

    <?php
    /**
     * Template part for displaying posts.
     *
     * @link https://codex.wordpress.org/Template_Hierarchy
     *
     * @package Masonry Brick
     */
    ?>
    
    <article id="post-<?php the_ID(); ?>" <?php post_class('masonry-content'); ?>>
    	<?php do_action('masonry_brick_before_post_content'); ?>
    
    	<?php if (has_post_thumbnail()) : ?>
    		<?php if (!is_single()) : ?>
    			<figure class="featured-image">
    				<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('masonry-brick-featured-thumbnail'); ?></a>
    			</figure>
    		<?php endif; ?>
    	<?php endif; ?>
    
    	<div class="post-wrapper">
    		<header class="entry-header">
    			<?php
    			if (is_single()) {
    				the_title('<h1 class="entry-title">', '</h1>');
    			} else {
    				the_title('<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>');
    			}
    
    			if ('post' === get_post_type()) :
    				?>
    				<div class="entry-meta">
    					<?php masonry_brick_posted_on(); ?>
    				</div><!-- .entry-meta -->
    			<?php endif;
    			?>
    		</header><!-- .entry-header -->
    
    		<div class="entry-content">
    			<?php
    			if (is_single()) :
    				the_content();
    			else :
    				if (is_sticky()) :
    					// displaying full content for the sticky post
    					the_content(sprintf(
    									/* translators: %s: Name of current post. */
    									wp_kses('<button type="button" class="btn continue-more-link">' . __('Read More <i class="fa fa-arrow-circle-o-right"></i>', 'masonry-brick') . '</button> %s', array('i' => array('class' => array()), 'button' => array('class' => array(), 'type' => array()))), the_title('<span class="screen-reader-text">"', '"</span>', false)
    					));
    				else :
    					the_excerpt(); // displaying excerpt for the archive pages
    				endif;
    			endif;
    
    			wp_link_pages(array(
    				'before' => '<div class="page-links">' . esc_html__('Pages:', 'masonry-brick'),
    				'after' => '</div>',
    			));
    			?>
    		</div><!-- .entry-content -->
    
    		<footer class="entry-footer">
    			<?php masonry_brick_entry_footer(); ?>
    		</footer><!-- .entry-footer -->
    
    	</div>
    	<?php do_action('masonry_brick_after_post_content'); ?>
    </article><!-- #post-## -->

    Hope you have got the idea about how to do this feature in your site this time more clearly.

    Thanks.
    Bishal Napit

    #161

    Fra79Valex
    Participant

    hello I solved the problem, was due to a plugin that gave me error,
    I did notice that the category is shown me under the post and instead I wish it were within the metatags, maybe instead of “author” … you can do?
    many thanks for the help

    #162

    Bishal Napit
    Keymaster

    Hi Fra79Valex,

    For adding that in the meta-tags area, you might not need to do the same work as stated above. You can just add the below PHP code in the functions.php file of the child theme and check:-

    function masonry_brick_posted_on() {
    	$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
    	if (get_the_time('U') !== get_the_modified_time('U')) {
    		$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
    	}
    
    	$time_string = sprintf($time_string, esc_attr(get_the_date('c')), esc_html(get_the_date()), esc_attr(get_the_modified_date('c')), esc_html(get_the_modified_date())
    	);
    
    	$posted_on = sprintf(
    			esc_html_x('%s', 'post date', 'masonry-brick'), '<a href="' . esc_url(get_permalink()) . '" rel="bookmark">' . '<i class="fa fa-calendar"></i>' . $time_string . '</a>'
    	);
    
    	$byline = sprintf(
    			esc_html_x('%s', 'post author', 'masonry-brick'), '<span class="author vcard"><a class="url fn n" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '">' . '<i class="fa fa-user"></i>' . esc_html(get_the_author()) . '</a></span>'
    	);
    
    	echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK.
    
    	if ('post' === get_post_type()) {
    		/* translators: used between list items, there is a space after the comma */
    		$categories_list = get_the_category_list(esc_html__(', ', 'masonry-brick'));
    		if ($categories_list && masonry_brick_categorized_blog()) {
    			printf('<span class="cat-links">' . wp_kses(__('<i class="fa fa-folder-open"></i>%1$s', 'masonry-brick'), array('i' => array('class' => array()))) . '</span>', $categories_list); // WPCS: XSS OK.
    		}
    	}
    
    	if (!post_password_required() && ( comments_open() || get_comments_number() )) {
    		echo '<span class="comments-link">';
    		comments_popup_link(wp_kses(__('<i class="fa fa-comment"></i>Leave a comment', 'masonry-brick'), array('i' => array('class' => array()))), wp_kses(__('<i class="fa fa-comment"></i>1', 'masonry-brick'), array('i' => array('class' => array()))), wp_kses(__('<i class="fa fa-comment"></i>%', 'masonry-brick'), array('i' => array('class' => array()))));
    		echo '</span>';
    	}
    }

    Now, you might also need to add this CSS code in the Additional CSS Box provided via the Customizer Options to better display the category name in that area:-

    .entry-meta .cat-links {
    	display: inline-block;
    	margin-left: 10px;
    }

    To remove the author name display form the home and archive pages, you can try this CSS code in the Additional CSS Box provided via the Customizer Options and check:-

    .home .entry-meta .byline, .archive .entry-meta .byline, .search .entry-meta .byline {
    	display: none;
    }

    Thanks.
    Bishal Napit

    #163

    Fra79Valex
    Participant

    hello now it works!
    the only thing is this error, when I do analysis of the child theme, which is shown in the plugin “Child Theme Configurator,” I used to create the theme-child and refers to Sendit for newsletters, and suggests: “Please contact this Theme’s author and report the items inside the box above. You may or may not be incendio use this Theme as a Child Theme while These conditions exist.

    It is possible That this theme has specific requirements to work correctly as a child theme. Please make sure you are using the latest version of this theme and check your theme’s documentation for more information. ”

    This was the plugin that gave me problems before, when I could not show categories using your code. I then turned off, and then it worked, it now appears ache if it is active, all work the same, although this error you see below:

    Notice: Constant SENDIT_EMAIL_TABLE already defined in /wp-content/plugins/sendit/libs/constants.php on line 4
    Notice: Constant SENDIT_LIST_TABLE already defined in /wp-content/plugins/sendit/libs/constants.php on line 5
    Notice: Constant SENDIT_VERSION already defined in /wp-content/plugins/sendit/libs/constants.php on line 6
    Notice: Constant SENDIT_DB_VERSION already defined in /wp-content/plugins/sendit/libs/constants.php on line 7
    Notice: Undefined index: post in /wp-content/plugins/sendit/libs/admin/meta-boxes.php on line 11
    Notice: Undefined index: post_type in /wp-content/plugins/sendit/libs/frontend/frontend.php on line 14
    Notice: Undefined index: post_type in /wp-content/plugins/sendit/libs/frontend/frontend.php on line 24
    Notice: Undefined index: action in /wp-content/plugins/sendit/libs/frontend/frontend.php on line 59
    Notice: Undefined index: action in /wp-content/plugins/sendit/libs/frontend/frontend.php on line 92

    it works the same but …

    Thanks for your help

    #164

    Bishal Napit
    Keymaster

    Hi Fra79Valex,

    The error seems to be pointing to the plugin, not the theme as from the above error messages. Also, creating the child theme for this theme will not have any issue at all. Can you be sure on this? You can also find the sample child theme in the above tutorial link too. Lastly, can you try uninstalling that plugin and check if the error resolves for your site too?

    Thanks.
    Bishal Napit

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.