My technical knowledge is not the best and I will understand if this question remains unanswered. I am trying to create a new view with the template schema. I am trying to follow the instructions from here: Tainacan Wiki. When I activate the plugin I get the error “Plugin generated 19 unexpected output characters during activation” (see picture 1). After activation, tainacan backend looks as in picture 2. In picture 3, the structure of the plugin in the plugins folder can be seen. I am attaching the two php files and the css file, in case someone can tell me what I am doing wrong. I thank you in advance.
As you might have guessed, the Extra View Modes plugin is one good reference for starting building this. The issue that you are facing is caused by a fatal error on your tainacan-lista-de-referencias.php file. Please remove completely this line:
?> /* End of file */
And the problem should be solved
If you have any other doubts on building the view mode, don’t worry about asking it here. This is a territory that few have explored and we would love to hear your feedback!
I was able to activate the plugin without errors. However, I do not see the new view in the views available in the settings of the collection. Should I do something more that I am missing?
After I activated the plugin in the plugins list I was able to see it as an option for enabling view modes in the collection form. Have you activated it?
I checked the server logs and activated the wordpress debug feature but I do not see any warnings related to this issue. I am guessing that this might be again due to the fact of using php 8.2. What do you think? I did not want to revert to php 7.4, but it seems I will have to do it.
Let me correct the previous message. The debug option was not really activated. I attach the log. It seems that it has to do with my php version. Is not it?
After many difficulties due to my scarce technical knowledge, I was able to downgrade to php 7.4, but the view does not appear in the view modes available in the collection settings. Anything else that I can look for?
I am sorry to flood this chat. It is a problem with the specific collection. I created a new collection with preset Dublin core and the view appeared. What can be the problem with my collection? What should I look for?
It is up to your template file to check for settings and respond to them properly. For example, it is in your php that you may fetch the collection settings to see if the option to always hide thumbnails is active. You may also look at the PHP $_GET variable to see which queries are enabled in the URL. The topic can grow in complexity depending on what you are looking for. I advise taking a look at other codes to help you out. The Extra View Modes is the best for this I believe.
But just so I can understand, what exactly are you trying to achieve with this view mode? Is it much different from the default ones, to the point that you need to create one instead of customizing existing via CSS?
Yes, Mateus. I want to construct a view mode in which each post is presented as bibliographic reference in APA style. I have not been able to see examples in which the value of a specific field is retrieved.
Got it @argeifontesfunes! That will require a bit more effort, but bare with me, we’ll get there!
For fetching metadata other than title and description (which are WordPress core metadata), you can have access to the $view_mode_displayed_metadata global variable in the context of the loop. Using our template queries and WP_Query, you can perform calls to obtain information about the metadata, including their value. Here are some code examples of view modes that I built:
You’ll see in this file calls to tainacan_the_metadata() where settings are passed to tweak the HTML that is generated for the metadata in the list. Here are the accepted params:
You can look into the logic behind the tainacan_the_metadata function to build your own if you want. Another way to tweak how an item metadata appear is by using the filters. Here is one of the available:
In this code, for example, I’m using this filter to append “R$” to a numeric metadata that I want to display as a monetary value:
Note that this appears also in the item single page.
I appreciate strongly all the time that you spend helping me in my technical ignorance. Unfortunately, I am having difficulty understanding the code you provided. I found a solution this weekend with the help of ChatGPT that is working. I do not know if it is far fetched or inefficient. This is the code, in case you want to comment:
<?php
// Function to get tainacan metadata value
function get_tainacan_metadata_value($metadata_id) {
ob_start(); // Start output buffering
tainacan_the_metadata(array(
'metadata__in' => array($metadata_id),
'exclude_title' => true,
'before_title' => '',
'after_title' => '',
'before_value' => '
',
'after_value' => '
'
));
$output = ob_get_clean(); // Get the buffered output and stop buffering
// Use regular expression to extract the content of the h4 element
if (preg_match('/
(.*?)<\/h4>/', $output, $matches)) {
return $matches[1];
} else {
return 'Value not found.';
}
}
// Main loop
if (have_posts()): ?>
<div class="tainacan-referencias-container">
<?php while (have_posts()): the_post(); ?>
<div class="tainacan-referencia">
<a href="<?php the_permalink(); ?>">
<?php
// Example usage with metadata ID 144212
$metadata_id = 144212;
$result = get_tainacan_metadata_value($metadata_id);
echo $result;
?>
</a>
</div>
<?php endwhile; ?>
</div>