简体   繁体   English

在Wordpress的另一页中显示页面/代码的一部分

[英]Showing part of a page/code in another page in wordpress

I have a code that I use to show a check list in Wordpress in a page as follows: 我有一个代码,用于在页面的Wordpress中显示检查清单,如下所示:

PHP: PHP:

<ul class="leftlist">
        <?php
        while ( $loop->have_posts() ) : $loop->the_post();
        ?>
        <li class="todo" id="<?php echo get_the_ID();?>" itemage="<?php echo get_post_meta(get_the_ID(),'_todotime',true)?>"><a href="javascript:;"
        <?php if($all_meta_for_user[get_the_ID()][0]){              
        ?>
        class="strike"
        <?php
         }
        ?>
        >           
        <?php if($all_meta_for_user[get_the_ID()][0]){?>
            <span class="check_box cb"></span>
            <?php }else{?>
        <span class="uncheck_box cb"></span>
        <?php }?>   
        <p><?php the_title(); ?></p></a>           
        <?php
        endwhile;
        ?>            
        </ul>

This code works fine. 此代码可以正常工作。 However, on a separate page, I just want to show the count of the incomplete list and not the whole check list. 但是,在单独的页面上,我只想显示不完整列表的计数,而不是整个检查列表。 How can I achieve this? 我该如何实现?

read this Sessions 阅读会话

if your count value is something like $count=50; 如果您的计数值为$count=50;类的值$count=50; then store this in a session like below 然后将其存储在如下所示的会话中

//you have to call session_start(); in starting of every page where you want to access sessions


session_start();

$count=50;
$_SESSION["count"]=$count;

Then in any page you can access this count value as below 然后,您可以在任何页面中按以下方式访问此计数值

in some other page 在其他页面

session_start();
echo $_SESSION["count"];

UPDATE 更新

Then you can use Cookies 然后您可以使用Cookies

put this end of the onclick function 放在onclick函数的此端

$('.sort, .itemage').on('click', function (e) {
-------
--------
------- all your javscript    

 var count=$(".leftlist li:visible").length;
    document.cookie="incompletecount="+count;
});

in any other page where you want to access this count value 在您要访问此计数值的任何其他页面中

function getCookie(name) {
  var value = "; " + document.cookie;
  var parts = value.split("; " + name + "=");
  if (parts.length == 2) return parts.pop().split(";").shift();
}
alert(getCookie('incompletecount'));
var incount=getCookie('incompletecount');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM