Custom Post type
-
Hello Romik
I am using evolve with a custom post type with custom fields. I used archive-cpt.php and single-cpt.php to allow for the display of the custom fields.
Now that these pages do not render the HTML code but call to wrapped functions, which is the best way to support CPT?
Thanks
Zulok
-
This topic was modified 6 years, 6 months ago by
zulok.
-
This topic was modified 6 years, 6 months ago by
-
Hello Zulok,
which HTML code you mean, please? Example?
Hi Romike
Here is a short example of single-taller.php based on a modification of single.php
Basically, some custom fields are displayed as part of the post.
Thx
Zulok
<div class="entry-content article"> <?php the_content(__('Read More »', 'evolve')); ?> <?php wp_link_pages(array('before' => '<div id="page-links"><p>' . __('<strong>Pages:</strong>', 'evolve'), 'after' => '</p></div>')); ?> <div class="clearfix"></div> </div><!--END .entry-content .article--> <!-- Display our fields --> <?php if (get_field("escola")){?> <p class="parrafo-peque?o-gris-oscuro"><span class="camps-event"><strong>Escola: </strong></span><?php the_field("escola") ; ?></p> <?php };?> <?php if (get_field("ponent")){?> <p class="parrafo-peque?o-gris-oscuro"><span class="camps-event"><strong>Mestre: </strong></span><?php the_field("ponent") ; ?></p> <?php };?> <p class="parrafo-peque?o-gris-oscuro"><span class="camps-event"><strong>Data Inici: </strong></span><?php $ed = get_field( "data_ini", $post_id, false); //get_the_ID echo substr($ed,8,2) . '/' . substr($ed,5,2) . '/' . substr($ed,0,4);?></p> <?php if (get_field("data_fi")){?> <p class="parrafo-peque?o-gris-oscuro"><span class="camps-event"><strong>Data Fi: </strong></span><?php $ed = get_field( "data_fi", $post_id, false); //get_the_ID echo substr($ed,8,2) . '/' . substr($ed,5,2) . '/' . substr($ed,0,4);?></p> <?php };?> <?php if (get_field("hora")){?> <p class="parrafo-peque?o-gris-oscuro"><span class="camps-event"><strong>Hora: </strong></span><?php the_field("hora") ; ?></p> <?php };?> <?php if (get_field("lloc")){?> <p class="parrafo-peque?o-gris-oscuro"><span class="camps-event"><strong>Lloc: </strong></span><?php the_field("lloc")?></p> <?php };?> <?php if (get_field("preu")){?> <p class="parrafo-peque?o-gris-oscuro"><span class="camps-event"><strong>Preu: </strong></span><?php the_field("preu") ; ?> €</p> <?php };?> <?php if (get_field("mail_informatiu")){?> <p class="parrafo-peque?o-gris-oscuro"> <span class="camps-event"><strong>Sol.licitar Informació: </strong> <a href="mailto:<?php the_field("mail_informatiu") ; ?>?subject=Sol.licitud d'informació sobre: <?php if ( get_the_title() ){ the_title();} ?>&body=Desitjaria rebre més informació sobre l'event <?php if ( get_the_title() ){ the_title();} ?>."><?php the_field("mail_informatiu") ; ?> </a> </span> </p> <?php };?> <div id="view1"> <?php $location = get_field('mapa'); if( ! empty($location) ):?> <p class="parrafo-peque?o-gris-oscuro"><span class="camps-event"><strong>Mapa: </strong></span><?php echo $location['address']; ?></p> <div id="map" class="acf-map"></div> <script type="text/javascript"> function load() { var lat = <?php echo $location['lat']; ?>; var lng = <?php echo $location['lng']; ?>; var latlng = new google.maps.LatLng(lat, lng); var myOptions = { zoom: 16, mapTypeControl: true, zoomControl: true, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map"), myOptions); var marker = new google.maps.Marker({ position: map.getCenter(), map: map }); } load(); </script> <?php endif; ?> </div> // etc... </div>
-
This reply was modified 6 years, 6 months ago by
zulok.
which theme version are you using? based on the code it doesn’t seem like the last one.
in the code I also see some bugs, e.g. this
<?php };?>
should be<?php } ?>
Hi Romik
I am using 3.8.4. Only this part of the code belongs to evolve,
<div class="entry-content article"> <?php the_content(__('Read More »', 'evolve')); ?> <?php wp_link_pages(array('before' => '<div id="page-links"><p>' . __('<strong>Pages:</strong>', 'evolve'), 'after' => '</p></div>')); ?> <div class="clearfix"></div>
Below the code is the one to display custom meta fields.
Thanks for pointing out the bugs in the code I added
Zulok
-
This reply was modified 6 years, 6 months ago by
zulok.
Please try the latest version. However, even old one can use a custom post template, so there should be no problem if custom coding is done correctly ??
Hi Romik
That’s what I am trying to do. I have a couple of local intances one with version 3.8.4 as the public one, and the other in 3.9.3 where I want to replicate the modifications for the CPT.
The problem is that I don’t know where the actual HTML is generated for single.php and archive.php, and it is not clear to me how many files should I duplicate for the CPT with the new wrappings. ??
Thanks
David
Sorry, but we don’t provide a customization service in forums so I cannot help with this. I would recommend to read some tutorials how to modify it as evolve uses default WP template system, so there should be no problem to integrate it at all. For example, try with default WP theme to see if the problem persists. If it does, then the problem is with the custom coding.
Hello Romik
Thanks for your quick answer and for keeping this theme updated frequently.
I have been using evolve with a few custom types since 2015 and gone through updates several times with small adjustments. With versions up to 3.8.4 I copied evolve single.php and archive.php into single-{cpt}.php and archive-{cpt}.php where I inserted my own code to display additional fields. I choose this implementation instead of building both files from scratch so that all the website shares the common customizations of evolve, and to keep code modular. This is the recommended way as I have read in the WP Codex.
Actually my question was to locate the PHP where the actual HTML code is generated for the post content, and secondly which files had I to copy and modify as the code has been restructured/wrapped.
With a little debugging I think I have found a solution that I post for other users.
.- Copy evolve\archive.php into evolve-child\archive-cpt.php
.- Replace the custom post type (:46) get_template_part( ‘template-parts/post/content’, ‘cpt‘ );
.- Copy evolve\template-parts\post\content-post.php into \template-parts\post\content-cpt.php
.- Make any changes in the latter fileDoes it make sense?
Thank you
Zulok
of, you actually didn’t have correct the path. The prolem was not clear to me, when you wrote HTML issue ??
OK. Thanks
-
This reply was modified 6 years, 6 months ago by
- The topic ‘Custom Post type’ is closed to new replies.