A
A
ArmyDone2021-11-03 11:21:19
WordPress
ArmyDone, 2021-11-03 11:21:19

How to display the content of the block that was clicked?

In general, I have a page with cards, they are created through acf repeater, by clicking on a card a page should open on which the elements for this card that is clicked should be displayed. They are also created via acf. Now the contents of all cards are displayed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Litvinenko, 2021-11-04
@ArmyDone

I'll try to paint, because going the path of least resistance is not entirely correct.
We create a new record type documents, change the x_theme text domain to our own. read:
https://wp-kama.ru/function/register_post_type

// Register Custom Post Type
function custom_post_type() {

  $labels = array(
    'name'                  => _x( 'Documents', 'Post Type General Name', 'x_theme' ),
    'singular_name'         => _x( 'Document', 'Post Type Singular Name', 'x_theme' ),
    'menu_name'             => __( 'Documents', 'x_theme' ),
    'name_admin_bar'        => __( 'Documents', 'x_theme' ),
    'archives'              => __( 'Documents Archives', 'x_theme' ),
    'attributes'            => __( 'Item Attributes', 'x_theme' ),
    'parent_item_colon'     => __( 'Parent Item:', 'x_theme' ),
    'all_items'             => __( 'All Items', 'x_theme' ),
    'add_new_item'          => __( 'Add New Item', 'x_theme' ),
    'add_new'               => __( 'Add New', 'x_theme' ),
    'new_item'              => __( 'New Item', 'x_theme' ),
    'edit_item'             => __( 'Edit Item', 'x_theme' ),
    'update_item'           => __( 'Update Item', 'x_theme' ),
    'view_item'             => __( 'View Item', 'x_theme' ),
    'view_items'            => __( 'View Items', 'x_theme' ),
    'search_items'          => __( 'Search Item', 'x_theme' ),
    'not_found'             => __( 'Not found', 'x_theme' ),
    'not_found_in_trash'    => __( 'Not found in Trash', 'x_theme' ),
    'featured_image'        => __( 'Featured Image', 'x_theme' ),
    'set_featured_image'    => __( 'Set featured image', 'x_theme' ),
    'remove_featured_image' => __( 'Remove featured image', 'x_theme' ),
    'use_featured_image'    => __( 'Use as featured image', 'x_theme' ),
    'insert_into_item'      => __( 'Insert into item', 'x_theme' ),
    'uploaded_to_this_item' => __( 'Uploaded to this item', 'x_theme' ),
    'items_list'            => __( 'Items list', 'x_theme' ),
    'items_list_navigation' => __( 'Items list navigation', 'x_theme' ),
    'filter_items_list'     => __( 'Filter items list', 'x_theme' ),
  );
  $args = array(
    'label'                 => __( 'Documents', 'x_theme' ),
    'description'           => __( 'Post Type Description', 'x_theme' ),
    'labels'                => $labels,
    'supports'              => array( 'title', 'editor', 'thumbnail', 'comments', 'revisions', 'custom-fields', 'page-attributes', 'post-formats' ),
    'taxonomies'            => array( 'documents_cat', 'documents_tag' ),
    'hierarchical'          => false,
    'public'                => true,
    'show_ui'               => true,
    'show_in_menu'          => true,
    'menu_position'         => 25,
    'menu_icon'             => 'dashicons-text-page',
    'show_in_admin_bar'     => true,
    'show_in_nav_menus'     => true,
    'can_export'            => true,
    'has_archive'           => true,
    'exclude_from_search'   => false,
    'publicly_queryable'    => true,
    'capability_type'       => 'post',
    'show_in_rest'          => false,
  );
  register_post_type( 'documents', $args );

}
add_action( 'init', 'custom_post_type', 0 );

after creation, we re-save the permalinks, just click save in permalinks.
Now some standard templates are available to us, for the archive page you can create archive-documents.php, for a single page single-documents.php the second one is required in your case. Both use the standard loop, without any wp_query, since it already works for your post type. This means that by copying the standard content of archive.php and formatting it in the form of cards, you will get exactly your post type as an output.
If you want to use it on another page, then the order is something like this. Create a page template, such as page-documents.php. In it, we define with a comment that this is a template for our documents.
/*
Template Name: Documents page
Template Post Type: documents
*/

We create a page in the admin panel, select this template in the attributes.
in the template, we launch a custom cycle for displaying cards
<?php
  $_posts = new WP_Query( array(
    'post_type'         => 'documents',
    'posts_per_page'    => -1,
  ));
?>

<?php if( $_posts->have_posts() ) : ?>
  <div class="dicuments">
  <?php while ( $_posts->have_posts() ) : $_posts->the_post(); ?>
  // тут получаем произвольные поля
  // тут вывод карточки включая стандартные теги и произвольные поля
    <div class="document">
      <h3><?php the_title() ?></h3>
      <?php if ( has_post_thumbnail() ) : ?>
        <div class="img-wrapper">
          <?php the_post_thumbnail() ?>
        </div>
      <?php endif; ?>
      <?php the_excerpt() ?>
      <a href="<?php the_permalink() ?>">readmore</a>
    </div>
  <?php endwhile; ?>
  </div>
<?php endif; wp_reset_postdata(); ?>

read about custom cycles
https://wp-kama.ru/function/wp_query
In single documents, copy the code from the standard single and finish it to the desired state.
Inside the loop, we use ACF as usual, outside the loop you need to google a little, especially on the archive page. For just a page as usual

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question