php Snips php:页面,菜单,帖子

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Snips php:页面,菜单,帖子相关的知识,希望对你有一定的参考价值。

<?php
  $menu_name = 'menu-1'; //menu slug
  $locations = get_nav_menu_locations();
  $menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
  $menuitems = wp_get_nav_menu_items( $menu->term_id, array( 'order' => 'DESC' ) );


  $map_ul_data = array();


  $c = count($menuitems);
  $pid = $post->ID+0;
  /* get this page parent ID, so we can later find other pages with the same parent */
  if($pid !== NaN && $pid !== NULL || true) {
    for($i=0; $i<$c; $i++) {
      $tmp_item = $menuitems[$i];
      /* map data */
      if($tmp_item->post_status == 'publish' || true)
        $map_ul_data[$tmp_item->menu_item_parent][] = array('id' => $tmp_item->object_id, 'title' => $tmp_item->post_title, 'url' => $tmp_item->url);
      /* what is the ID of the page that is aur parent */
      $tmp_id = $menuitems[$i]->object_id;
      if($tmp_id == $pid)
        $this_page_parent_id = $tmp_item->menu_item_parent;
    }
  }

  /* get same service in other towns */
  $culi = count($map_ul_data[$this_page_parent_id]);
  if ($culi>0) :
    for ( $j=0; $j<$culi; $j++ ) :
      $tmp_tm = $map_ul_data[$this_page_parent_id][$j];
      if( intval($post->ID) !== intval($tmp_tm['id']) ) :?>
          <div class="page-link">
            <a href="<?php echo $tmp_tm['url'] ?>"><?php echo $tmp_tm['title'] ?></a>
          </div>
      <?php
      endif;
    endfor;
  endif; ?>
<?php
<?php
$menu_name = 'menu-1'; //menu slug
$locations = get_nav_menu_locations();
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
$menuitems = wp_get_nav_menu_items( $menu->term_id, array( 'order' => 'DESC' ) );

$map_ul_data = array();
$c = count($menuitems);
$pid = '341'; //Locksmith Services submenu 'ID'

if($pid !== NaN && $pid !== NULL) {
  for($i=0; $i<$c; $i++) {
    $tmp_item = $menuitems[$i];
    if($tmp_item->post_status == 'publish' || true) {
			$tmp_item_parent_id = $menuitems[$i]->menu_item_parent;
			if($tmp_item_parent_id == $pid) { ?>
				<div class="page-link">
					<a class="dynamic-list-menu-item" href="<?php echo $tmp_item->url ?>"><?php echo $tmp_item->title ?></a>
				</div>
				<?php
			}
		}
	}
}
?>
<?php
  foreach ($pages_no_dup as $i => $page) : ?>
    <?php ($i==0) ? print '<tr>': '';
    ($i%2==0 && $i!==0) ? print '</tr><tr>': '';
    ?>
    <td>
    <a href="<?php print $page->url ?>"><?php print $page->post_title ?></a>
    </td>
    <?php


  endforeach;
  print '</tr>';
  

以上是关于php Snips php:页面,菜单,帖子的主要内容,如果未能解决你的问题,请参考以下文章

使用下拉菜单动态过滤 Wordpress 帖子(使用 php 和 ajax)

php 添加此代码以将ACF字段添加到页面/帖子。务必检查wordpress仪表板顶部菜单中的屏幕选项

php 重命名菜单更改帖子管理菜单中的帖子

php 最新的帖子菜单项

php 最新的帖子菜单项

php 从菜单中删除没有帖子的条款。