Add additional fields to posts in category grid

Posted in: Newspaper
Post count: 46

Hello. I need to add additional information to the post excerpts displayed in any of the category post grids. For example, I need each post excerpt to display a logo at the bottom. I also need each post to display all content rather than just an except.

Is this possible with your theme?
Or, I’ve used ACF to generate the fields I need and produce the code but where do I use this code? What template or what do I create in my child theme to do this?

Thanks in advance

Post count: 46

An example of what I mean could be used here:

https://demo.tagdiv.com/newspaper_travel/

To add a logo underneath each of the posts, which can be added in a custom field on each post page and displays on each of the post excerpts on this page.

Post count: 20685

Hi,

Only with modifications to the modules would it be possible for them to display additional information. They can only display what is defined in their coding, for example
https://www.screencast.com/t/cB27rrRC
So they are not able to display a logo unless this is added by some means in each of the modules.

The excerpt can be either automatic, picked from the post content and have a length according to the setting
https://forum.tagdiv.com/excerpts-introduction/
Or you can set custom excerpts for each post, these will be displayed exactly as you enter them
https://www.screencast.com/t/Og6EfgCkA

We will try to add more settings and features for the flex blocks and flex grids in the future. I can’t say what these will be unfortunately.

Thanks

Post count: 46

OK. Thanks.

So, I’m using Flexbox 1. Can I copy / rename this and edit it or add it to my child theme?
Or can I only edit the original file?

Post count: 20685

Hi,

Modules from the modules folder can be modified in a child theme
https://forum.tagdiv.com/the-child-theme-support-tutorial/
Create the same directory path to the modules in the child theme as in the main theme, then copy the desired module in the child theme. The flex modules can be modified in the child theme.

Thanks

Post count: 46

Great. Thanks very much : )

Post count: 46

Hi again. I’m having trouble getting this to work. Are you able to help at all?
I’ve created a custom filed in ACF for adding an image.
I’ve then opened the module I’m using – td_module_flex_1.php

Then added the field code like this:

<?php

class td_module_flex_1 extends td_module {

function __construct($post, $module_atts = array()) {
//run the parrent constructor
parent::__construct($post, $module_atts);
}

function render() {
ob_start();

$hide_image = $this->get_shortcode_att('hide_image');
$image_size = $this->get_shortcode_att('image_size');
$category_position = $this->get_shortcode_att('modules_category');
$btn_title = $this->get_shortcode_att('btn_title');
$title_length = $this->get_shortcode_att('mc1_tl');
$author_photo = $this->get_shortcode_att('author_photo');
$excerpt_length = $this->get_shortcode_att('mc1_el');
$excerpt_position = $this->get_shortcode_att('excerpt_middle');

if (empty($image_size)) {
$image_size = 'td_696x0';
}
if (empty($btn_title)) {
$btn_title = 'Read more';
}

$excerpt = '<div class="td-excerpt">';
$excerpt .= $this->get_excerpt($excerpt_length);
$excerpt .= '</div>';

?>

<div class="<?php echo $this->get_module_classes();?>">
<div class="td-module-container td-category-pos-<?php echo $category_position; ?>">
<?php if( $hide_image == '' ) { ?>
<div class="td-image-container">
<?php if ($category_position == 'image') { echo $this->get_category(); }?>
<?php echo $this->get_image($image_size, true);?>
</div>
<?php } ?>

<div class="td-module-meta-info">
<?php if ($category_position == 'above') { echo $this->get_category(); }?>

<?php echo $this->get_title($title_length);?>

<?php if ($excerpt_position == 'yes') { echo $excerpt; } ?>

<div class="td-editor-date">
<?php if ($category_position == '') { echo $this->get_category(); }?>

<span class="td-author-date">
<?php if( $author_photo != '' ) { echo $this->get_author_photo(); } ?>
<?php echo $this->get_author();?>
<?php echo $this->get_date();?>
<?php echo $this->get_comments();?>
</span>
</div>

<?php if ($excerpt_position == '') { echo $excerpt; } ?>

<div class="td-read-more">
href;?>"><?php echo __td($btn_title, TD_THEME_NAME);?>
</div>

cat<div class="uni-logo"><?php $uni_logo = get_field( 'uni_logo' ); ?>
<?php if ( $uni_logo ) { ?>
" alt="<?php echo $uni_logo['alt']; ?>" />
<?php } ?></div>dog
</div>
</div>
</div>

<?php return ob_get_clean();
}
}

I’ve added the text ‘cat / dog’ before and after my code so i could see where it is supposed to appear.

You can see the result here:

http://whystudyhere-com.sites.stackstaging.com/block-14-full-2/

Any help gratefully appreciated.

Post count: 46

Sorry. The link above has changed to this:
http://whystudyhere-com.sites.stackstaging.com/wsh-homepage/

  • This reply was modified 7 years by 3ftDeep.
Post count: 20685
Post count: 46

OK. Thanks. But, from what you see I’m trying to do, it should work, right? I’ve not used custom fields before. I just need to know I’m going in the right direction.

Post count: 46

Are you able to test acf with this theme at all? I’m sure my code is OK. It’s just not registering the field.
Maybe try to get an image added in an acf field in a post to display in td_module_flex_1.php like I’m trying to do?

It would really help if you can confirm it works or not. Or add any field and let me know how you did it.

Alternatively, it is possible to add my own custom fields to the theme and include them in flex_1? Like you have ‘source’ or ‘via’ ?

Thanks again in advance.

Post count: 20685

I also don’t have much experience with custom fields, but I think I managed to do it, at least point you in the right direction.

First I have set the field – https://www.advancedcustomfields.com/resources/image/
https://www.screencast.com/t/lHd6LfgWh6g
Code in module as mentioned in their documentation but with an additional parameter
https://www.screencast.com/t/FAhz70Wg8BYr
Code here – https://forum.tagdiv.com/topic/custom-fields-howto-any-help/

I upload image in the post edit page – https://www.screencast.com/t/t0tZMRlLIj
Image appears like so – http://prntscr.com/lxtsrs

This is a quick test to see if the image is displayed, you can tweak it as you want for a more proper result. Hope it is helpful.

Post count: 46

Hi Simion. Thank you so much for this.
I got it working : )

I couldn’t get your code to work but it was this, from your code, that helped:

,$this->post->ID); ?>

So, this is the code that worked:
<?php $universitylogo = get_field( 'universitylogo',$this->post->ID); ?>
<?php if ( $universitylogo ) { ?>
" alt="<?php echo $universitylogo['alt']; ?>" />
<?php } ?>

The field in ACF was set to ‘image’ then select ‘image array’
In the general ACF field settings it was ‘post type’ equal to ‘post’

Thanks so much for your help. You are a genius : )

Just one more question. You mentioned this in the other post you linked to.
https://www.screencast.com/t/7wBdSz3a9
Where are these custom fields found? I don’t have them on any post page. I’ve also checked the screen options, in case it was hidden but it’s not there either?

Post count: 20685

Hi,

Glad it worked. Those should be seen at the bottom of the post edit screen if enabled in the screen options. I made some screenshots
https://www.screencast.com/t/aqYqtqQ3
https://www.screencast.com/t/FKpeXWbdoOB
https://www.screencast.com/t/Eu4GnrPo89E

Post count: 46

Thanks. But I don’t have the ‘custom fields’ option to tick?

Post count: 20685

From what I can see having the ACF plugin removes the other custom fields, deactivating it will restore them.

I found a code that can be entered in the theme or child theme functions file, this will (at least in my case it does) enable the default custom fields regardless of ACF being active
https://www.wpbeginner.com/wp-tutorials/how-to-fix-custom-fields-not-showing-in-wordpress/
https://www.screencast.com/t/IGAEYLobqEp
https://www.screencast.com/t/1so9f3vj
You could give that a try, should work.

Viewing 16 posts - 1 through 16 (of 16 total)
You must be logged in to reply to this topic.