0
0
0906ddd2021-09-03 18:03:06
WordPress
0906ddd, 2021-09-03 18:03:06

How to link to a page in WordPress?

for example, in the menu item there is a contact page, where WordPress itself picks up,

and if there is also a block on the main page in which there is a link for more details
(it should also lead to the contact page)
how to write href correctly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2021-09-03
@0906ddd

https://wp-kama.ru/function/get_permalink

A
Artem Zolin, 2021-09-03
@artzolin

Basic query and output of posts with links:

// задаем нужные нам критерии выборки данных из БД
$args = array(
  'posts_per_page' => 5,
  'post_type' => 'post',
);

$query = new WP_Query( $args );

// Цикл
if ( $query->have_posts() ) {
  echo '<ul>';
  while ( $query->have_posts() ) {
    $query->the_post();
    echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
  }
  echo '</ul>';
} else {
  // Постов не найдено
}
// Возвращаем оригинальные данные поста. Сбрасываем $post.
wp_reset_postdata();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question