Archived topic
Search results
9 replies · Started by Catalin on May 5, 2018
Hi,
My search results show the post title and part of the content. Which is good. I have custom posts made with pods.io and I would like to show under the title one of the custom forms. How could I do that?
Thanks.
Hi there,
You can use the after entry title hook:
http://demo.generatepress.com/hook-locations/
with conditional tag of that custom posts:
https://docs.generatepress.com/article/using-hooks-conditional-tags/
https://codex.wordpress.org/Conditional_Tags
Let me know.
That actually added the text in the single post page. I need to have it displayed where all my search results are.
Try this in hooks:
<?php if ( is_search() || is_category() ) : ?>
<div class="under-title-text">This Content will ONLY show on the search results page</div>
<?php endif; ?>
Let me know if this works.
Yes, I get the text right under the title.
1. How could I get it when I check also the categories?
2. How could I increase the space between title and this new text?
3. The text I'll get under the title comes from 6 different post type (books, articles, reviews etc.) and it's should be the form for Author. I guess I'll need a code that brings that form for any of my posts (like: if this is Books, bring {@author}). Or, if the form has always the name, it will be easier (not so many ifs)? :)
1. Edited the code above.
2. With the edited code above, add this CSS:
.under-title-text {
padding-top: 20px;
padding-bottom: 20px;
}
3. Not quite sure what you mean. Can you give me an example?
It has to be within these conditional tag: https://codex.wordpress.org/Conditional_Tags
Thanks. It worked for 1. and 2.
3. This is a category page with 3 book titles. (http://www.bibliografic.esploro.ro/category/imagologie/) Where it says This Content will ONLY show on the search results page, it should be the book author, from here: http://www.bibliografic.esploro.ro/capitol/de-la-pelerinaj-la-procesiune-purtarea-capului-sfantului-visarion-al-larisei-pe-drumul-ciumei-din-valahia-secolului-al-xviii-lea/ (Balinte, Cristina (Capitol / Articol în volum)
The book author is introduced with a custom form.
Is the author a custom field?
If so, you can do this inside your conditional:
$author = get_post_meta( get_the_ID(), 'your_custom_field_id', true );
echo $author;
Thanks.
A friend help me with the following code and it works.
<?php
if (is_search() || is_category()) :
$author = get_post_meta(get_the_ID(), 'autor', true);
$type = get_post_meta(get_the_ID(), '_pods_tip_lucrare', true);
?>
<div class="under-title-text">
<strong><?= $author ?></strong> (<?= $type ?>)
</div>
<?php endif; ?>
Awesome, thanks for sharing it!