自定义WordPress博客主题时总显示:会话已过期,请重新登录。您不会被带离此页。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自定义WordPress博客主题时总显示:会话已过期,请重新登录。您不会被带离此页。相关的知识,希望对你有一定的参考价值。

登陆了还是这样,试了下网上说的更换浏览器,修改cookie过期日期,都没用。怎么解决?

参考技术A 你可以去后台的 “设置” - “常规”,看看站点地址(URL)和WordPress地址(URL)一不一样,还有带不带www,一般是这个问题,更多请访问EndSkin

在 wordpress 自定义主题索引上显示页面链接

【中文标题】在 wordpress 自定义主题索引上显示页面链接【英文标题】:display pages links on wordpress custom theme index 【发布时间】:2019-04-12 21:36:02 【问题描述】:

我正在从头开始开发我的第一个 wordpress 主题。我需要一些帮助来解决与WP_Query 类和导航菜单相关的两个问题。我想在我的主题索引上显示页面标题和特色图片。我已经阅读了文档,最好的方法是在进行自定义查询后使用标准的 wordpress 循环。我正在使用此代码获取已发布的页面,但它不起作用,控制台总是记录我这个错误``。现在我正在显示已发布的文章,但我需要将其更改为页面。这是查询的代码

<?php get_header(); ?>

<?php
$args = array('post_type'=>'page');
$pages = new WP_Query($args);
//var_dump($pages);
?>
<div class="container-fluid" id="wrapper">

<div class="row justify-content-center" id="home-cover">
  <div class="col-sm-12 col-md-6 col-lg-6 text-center" id="donate-button-wrapper">
    <button class="btn btn-link btn-donate">Call to action</button>
  </div>
</div>
<!-- ultimare -->
<div class="row">
  <?php if($pages->have_posts()) : while ($pages->have_posts()) : $pages->the_post(); ?>
      <div class="col-sm-12 col-md-3 col-lg-3" id="home-cols">

        <a href="<?php the_permalink(); ?>" class="home-card-link">
      <div class="card" id="post-link">
        <div class="home-img-wrapper">
        <?php the_post_thumbnail('post-thumbnail', array('class'=>'card-img-top home') ); ?>
        </div>
        <div class="card-body">
          <h4 id="home-card-link-title"><?php the_title(); ?></h4>
        </div>
      </div>

        </a>

      </div>
    <?php endwhile; ?>
  <?php endif;  wp_reset_postdata(); ?>
</div>

<?php get_footer(); ?>

对于menù问题,我使用bootstrap 4来设置我的主题。我需要了解如何在wordpress上注册我的菜单,我想在PC上使用bootstrap的标准导航栏,并使用offcanvas菜单当网站从移动设备显示时,请键入。这是我用来显示菜单的代码:

<script>
(function($)

$(document).on('click', '.navbar-brand',function(event)
  event.preventDefault();
  if($('#menu-row').hasClass('menuOpen'))
    $('#menu-row').removeClass('menuOpen')
    .addClass('menuClosed');
    $('#nav-icon').removeClass('fas fa-times fa-2x')
    .addClass('fas fa-bars fa-2x');
  
  else
    $('#menu-row').removeClass('menuClosed')
    .addClass('menuOpen');
    $('#nav-icon').removeClass('fas fa-bars fa-2x')
    .addClass('fas fa-times fa-2x');
  
);
(jQuery));
</script>

<style>
.row.justify-content-center.menuClosed
  transform: translateX(-100%);
  transition: all 300ms;

.row.justify-content-center.menuOpen
  transition: all 300ms;
  transform: translateX(0%);

</style>

<?php
<!doctype html>
<html <?php language_attributes(); ?>>
<head>
  <meta charset="<?php bloginfo( 'charset' ); ?>">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <link rel="profile" href="http://gmpg.org/xfn/11">

  <title><?php bloginfo('name'); ?></title>
  <?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>

<nav class="navbar navbar-expand-md fixed-top" id="bs-nav">
  <a class="navbar-brand" href="#"><i class="fas fa-bars fa-2x" id="nav-icon"></i></a>
</nav>

  <div class="container-fluid" id="menu-wrapper">
    <div class="row justify-content-center menuClosed" id="menu-row">
      <div class="col-sm-12 col-lg-12 col-md-12">
        <?php wp_nav_menu( array( 'theme_location'=>'header-menu', 'menu_class'=>'nav mx-auto') ); ?>
      </div>
    </div>
  </div>

我已经尝试传递 array() 的参数,如 wordpress 文档中所述,但它会以错误的方式应用这些类,我无法设置 ulli 的样式来分配引导类。

【问题讨论】:

【参考方案1】:

对于菜单问题:

我知道如何访问 wp_nav_menu 中的 li 元素的方法是遍历所有菜单项。 最好的方法是使用Walker_Nav_Menu class 将此代码放入您的 functions.php 文件中:

  class Your_Custom_Walker extends Walker_Nav_Menu


   function start_el(&$output, $item, $depth=0, $args=array(), $id = 0) 

   // You can access all the item properties this way
  // you can view them all by calling print_r($item)

    $title = $item->title;
    $permalink = $item->url;
    $name = $item->post_name;

    $li_classes = 'class1 class2 class3 ect.. '; // You can put all the classes you want on the li element here

    $output .= "<li class= '".$li_classes."'>";

    $output .= '<a href="' . $permalink . '">';

    $output .= $title;

    $output .= '</a>';

 


然后在要显示菜单的文件中,创建 My_Custom_Walker 类的实例:

wp_nav_menu(array(
                'menu' => 'YOUR MENU NAME',
                'theme_location' => 'primary',
                'menu_class'     => 'nav ', // Here you set the classnames of the ul element
                // Create the instance of the Walker and the will run the start_el function 
                'walker' => new My_Custom_Walker()
             ) );

【讨论】:

【参考方案2】:

尝试为 wp_query 实例使用另一个名称。 埃克斯:

  $page_query = new WP_Query( array( 'post_type' => 'page' ) );

这对我有用。 我认为 $pages 是一个全局名称。 希望这对你有用。

【讨论】:

以上是关于自定义WordPress博客主题时总显示:会话已过期,请重新登录。您不会被带离此页。的主要内容,如果未能解决你的问题,请参考以下文章

自定义 wordpress 主题:布局图像不显示

在 wordpress 自定义主题索引上显示页面链接

自定义 wordpress 主题,图片不显示?

aden 博客 外贸营销网站建设模板 wordpress主题 V2.2

wordpress博客文章作者信息页面显示不了

将 Google Web 字体用于自定义 WordPress 主题