Php Wordpress- 无法获取点击元素的 the_title
Php Wordpress- can't get the the_title of a clicked element
我试图从自定义 post 类型中获取点击元素的 the_title()。
<a href='index.php?hello=$menuName'> <?php $menuName = the_title(); ?> </a>
<?php echo $_GET[hello]; ?>
但它没有返回标题名称,它只是给我变量名称。
我只想用这里的值来设置菜单名
$menuName = $_GET['hello'];
$menu_header = get_term_by('name', $menuName , 'nav_menu');
这是完整的代码。
<div class="dropdown-content">
<?php $args = array( 'post_type' => 'location', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<a href='index.php?hello=$menuName'> <?php $menuName = the_title(); ?> </a>
<?php echo $_GET[hello]; ?>
<?php
endwhile;
function runMyFunction() {
$menuName = $_GET['hello'];
$menu_header = get_term_by('name', $menuName , 'nav_menu');
$menu_header_id = $menu_header->term_id;
$locations = get_theme_mod('nav_menu_locations');
//set the menu to the new location and save into database
$locations['primary'] = $menu_header_id;
set_theme_mod( 'nav_menu_locations', $locations);
}
if (isset($_GET['hello'])) {
runMyFunction();
?>
</div>
</div>
</div>
提前致谢
在以下代码中:
<a href='index.php?hello=$menuName'> <?php $menuName = the_title(); ?> </a>
您尝试设置一个在您的 href
中仍未定义的变量。此外,在循环中,the_title()
returns 当前 post 标题,所以这样做很奇怪...
最后一点是 php 中的单引号不解释变量,与双引号相反。如果你想让它成为一个合适的方式,我建议你这样设置你的 link :
<a href="index.php?hello=<?php echo $menuName; ?>"></a>
我试图从自定义 post 类型中获取点击元素的 the_title()。
<a href='index.php?hello=$menuName'> <?php $menuName = the_title(); ?> </a>
<?php echo $_GET[hello]; ?>
但它没有返回标题名称,它只是给我变量名称。
我只想用这里的值来设置菜单名
$menuName = $_GET['hello'];
$menu_header = get_term_by('name', $menuName , 'nav_menu');
这是完整的代码。
<div class="dropdown-content">
<?php $args = array( 'post_type' => 'location', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<a href='index.php?hello=$menuName'> <?php $menuName = the_title(); ?> </a>
<?php echo $_GET[hello]; ?>
<?php
endwhile;
function runMyFunction() {
$menuName = $_GET['hello'];
$menu_header = get_term_by('name', $menuName , 'nav_menu');
$menu_header_id = $menu_header->term_id;
$locations = get_theme_mod('nav_menu_locations');
//set the menu to the new location and save into database
$locations['primary'] = $menu_header_id;
set_theme_mod( 'nav_menu_locations', $locations);
}
if (isset($_GET['hello'])) {
runMyFunction();
?>
</div>
</div>
</div>
提前致谢
在以下代码中:
<a href='index.php?hello=$menuName'> <?php $menuName = the_title(); ?> </a>
您尝试设置一个在您的 href
中仍未定义的变量。此外,在循环中,the_title()
returns 当前 post 标题,所以这样做很奇怪...
最后一点是 php 中的单引号不解释变量,与双引号相反。如果你想让它成为一个合适的方式,我建议你这样设置你的 link :
<a href="index.php?hello=<?php echo $menuName; ?>"></a>