douao2019 2016-01-25 06:01
浏览 55
已采纳

如何在wordpress的分页悬停事件中显示其他页面的帖子标题(仅作为工具提示)?

I am working on a project in Wordpress. I have a blog with number of pages with a pagination at bottom like 1, 2, 3 and so on. I need to implement a functionality on hover event of a page number which show a tooltip having post's header (as a list) of that page like shown in below screenshot:

Example Image

My blog pages links are like :

www.domain.com/page/1/ 
www.domain.com/page/2/ 
www.domain.com/page/3/
...

I am a front-end developer and have a little knowledge in php. I searched on google with no luck. Can anyone help how can I achieve this?

Thanks!

Edited:

Can I achieve it by sending ajax requests. You might try here

  • 写回答

1条回答 默认 最新

  • dongzhanlu8890 2016-01-25 13:53
    关注

    let's assume that the navigation looks like this.

    <div class="navigation">
        <ul>
            <li><a href="http://example.com/1" >Previous Page</a></li>
            <li><a href="http://example.com/">1</a></li>
            <li class="active"><a href="http://example.com/page/2/">2</a></li>
            <li><a href="http://example.com/page/3/">3</a></li>
            <li><a href="http://example.com/page/3/" >Next Page</a></li>
        </ul>
    </div>
    

    and that the post headers look like this

    <div class="post-header">
        <h2><a href="http://example.com/post-link/">Post Title</a></h2>
        <!-- some meta stuff goes here -->
    </div>
    

    alright, now that that's over here's the ajax bit

    jQuery( function($){
    
        $("div.navigation a").mouseover(function(){ 
            // we'll need this for later use
            var thisTag = $(this);
            // no point in making another request if we already have the data
            if( $(this).data('hovered') ) {
                // this is where you'll trigger the saved tooltips
                console.log( thisTag.data('titles') );
                return;
            }
            // we'll add a flag to check whether we've already checked this link (in retrospect 'checked' would've been a better choice)
            $(this).data('hovered', true);
            // we don't have to do this but it looks cleaner
            var ajaxurl = $(this).attr('href');
            // pretty straight forward, we grab everything in the linked page (exactly what those infinite scroll plugins/themes do) and find the titles.
            $.ajax({
                url: ajaxurl,
                type: 'get',
                success: function(data) {
                    var titles = [];
                    // you'll have to modify the selector to match your theme
                    $(data).find('.post-header h2 a').each( function(){
                        titles.push( $(this).text() );
                    });                                
                    // I'm doing this so that this can be retrived on subsequent hovers. however, this part should be replaced with the tooltip
                    thisTag.data('titles', titles);
                    console.log( titles );
                }
            });
        });
    
    });
    

    you'll have to adjust the selectors to match your theme and that's it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)
  • ¥66 比特币地址如何生成taproot地址
  • ¥20 数学建模数学建模需要