Everytime I enter a posts page, index.php is called. Now on the site I load next pages (page2, page3...) with Ajax and insert the posts (just the posts) from the Ajax result inside my page. This works perfect but I was wondering if it is possible to have a different page template for second-pages so I would just load the articles in those (no scripts or styles or parent-innecesary divs).  This way the Ajax call would be faster.  A thing to consider is that if it would be possible, it wount just be for the page number different to one, as the user might enter directly in the fourth page (this one should have all the styles and divs) and then load the fifth, sixth by this second-Ajax template.  EDIT2:  I realized about   if (strcasecmp('XMLHttpRequest', $_SERVER['HTTP_X_REQUESTED_WITH']) === 0)   EDIT:  &lt;?php get_header(); ?&gt;      &lt;div id="main"&gt;      &lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;          &lt;article id="post-&lt;?php the_ID(); ?&gt;"&gt;          ...          &lt;/article&gt;      &lt;?php endif; ?&gt;      &lt;/div&gt;  &lt;?php get_footer(); ?&gt;   And then I load via javascript Ajax next pages:  $.ajax({      url : page_to_load,      success : function (data) {          $('#main').append($('#main&gt;article', data));      }  });   If Im right, every time an Ajax page is called all the page is actually downloaded (scripts,etc.)  I was sondering if it would be possible to have a different page template for this second page, something like:      &lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;          &lt;article id="post-&lt;?php the_ID(); ?&gt;"&gt;          ...          &lt;/article&gt;      &lt;?php endif; ?&gt;   So ONLY articles are loaded, no header,scripts,styles or anything extra.  Thanks.
120639
I'm trying to put search results into a div with ajax. The issue is I'm getting errors saying undefined function have_posts() when the the search template is accessed. It also took issue with get_header() which was in the search-results.php but I took it out. Here's how I have it setup.    &lt;div id="my_search"&gt;    &lt;form role="search" method="get" id="searchform" action="http://myurl.com/" &gt;     &lt;input type="text" value="" name="s" id="s" /&gt;     &lt;input type="submit" id="searchsubmit" value="Search" /&gt;    &lt;/form&gt;   &lt;/div&gt;   &lt;div id="results"&gt;&lt;/div&gt;   &lt;script type="text/javascript"&gt;     $(document).ready(function(){     $("#searchsubmit").click(function(e){      e.preventDefault();      var search_val=$("#s").val();       $.post('http://mysite.com/wp-content/themes/beta/search-results.php',{search_string:search_val},function(data){         if(data.length&gt;0){             $("#results").html(data);         }      });     });       });   &lt;/script&gt;   And here is the search-results.php template. I'm wondering if maybe I'm not passing the search results to the template.  &lt;ul&gt;  &lt;?php if (have_posts()) : while (have_posts()) : the_post();  ?&gt;   &lt;li&gt;&lt;a title="Permalink to this post" href="&lt;?php echo get_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt;   &lt;?php endwhile; endif; ?&gt;  &lt;?php if (!have_posts()) { echo('&lt;li&gt;No results to show.&lt;/li&gt;'); } ?&gt; &lt;/ul&gt;
56524
I needed a way to filter a page/posts content before it was loaded so I could add scripts to the header if a specific shortcode was present. After much searching I came across this on    function has_my_shortcode($posts) {     if ( empty($posts) )         return $posts;      $found = false;      foreach ($posts as $post) {         if ( stripos($post-&gt;post_content, '[my_shortcode') )             $found = true;             break;         }      if ($found){         $urljs = get_bloginfo( 'template_directory' ).IMP_JS;      wp_register_script('my_script', $urljs.'myscript.js' );      wp_print_scripts('my_script'); }     return $posts; } add_action('the_posts', 'has_my_shortcode');   which is absolutely brilliant and did exactly what I needed.   Now I need to extend it a bit further and do the same for sidebars. It can be by a particular widget type, shortcode, code snippet or anything else that would work to identify when the script needs to be loaded.  The problem is I can't figure out how to access the sidebars content before the sidebar is loaded (the theme in question will have several sidebars)
120620
I am having a little trouble trying to figure out how I can accomplish this: I have a container with two colums in it, a right and a left column. Each column will have 3 posts with a short excerpt stacked in it. Ideally I would like to add one into the right and one into the left until it reaches 3 rows of posts(although if that proves to be alot more of a difficult task than I am fine with posting to the first column than the second. I am able to loop through the posts and add them to one column, but I am having trouble figuring out how one will loop into two separate divs, without repeating the divs. Here is how I am attempting it, so far this code will loop into the left column.  The first left side is using the loop to display the title(excerpt will come after) and the right side is just using html. Can anyone help me figure this one out?         &lt;h2&gt;Popular posts&lt;/h2&gt;        &lt;h3&gt;Showing the most popular posts.&lt;/h3&gt;  &lt;div class="col4 inner-left"&gt;        &lt;ul class="popular-list"&gt;    &lt;?php        query_posts('meta_key=post_views_count&amp;orderby=meta_value_num&amp;order=DESC&amp;posts_per_page=10&amp;post_type=pop');        if (have_posts()) : while (have_posts()) : the_post(); ?&gt;             &lt;li&gt;              &lt;a href=&lt;?php the_permalink(); ?&gt;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;              &lt;p&gt;Popular post. This is a popular post, it really is.&lt;/p&gt;             &lt;/li&gt;    &lt;?php        endwhile; endif;        wp_reset_query();     ?&gt;                   &lt;/ul&gt;     &lt;/div&gt;  &lt;div class="col4 inner-right"&gt;         &lt;ul class="popular-list"&gt;             &lt;li&gt;               &lt;a href="popularpostlink.php"&gt;This is a popular post&lt;/a&gt;               &lt;p&gt;Popular post. This is a popular post, it really is.&lt;/p&gt;             &lt;/li&gt;                  &lt;li&gt;                   &lt;a href="popularpostlink.php"&gt;This is a popular post&lt;/a&gt;                   &lt;p&gt;Popular post. This is a popular post, it really is.&lt;/p&gt;                 &lt;/li&gt;             &lt;/ul&gt;         &lt;/div&gt;
7714
Different pages often need different set of scripts and styles for them.  I use functions.php and construction like this to load scripts and styles:  function load_assets() {    wp_enqueue_style( 'styles', get_template_directory_uri() . '/css/styles.css');    wp_enqueue_script('main-js', get_template_directory_uri() . '/js/main.js'); } add_action( 'wp_enqueue_scripts', 'load_assets' );   I know I can put some condition here like this:  is_page()   but is there a better way?  Suggestion:  Can wp_register_script() be used to target specific pages?
73066
I have multiple views with pagers on same page. But all of the pagers using the same GET argument "page", so when user chooses a page in first pager, all of the pagers changing their state to those page. How can I make things work? Drupal 6, Views 2.
46240
I am developing a WP theme with MVC approach. It only have index.php, functions.php and styles.css on the parent directory. So, I do not want to place page templates on it rather then I want to programmatically provide them from View classes while functionality from edit screen stays the same.   Users need to have page templates select option on the edit screen. How do I successfully add Items to the template dropdown?  I tried to hook into  filter.   Example code:  add_filter( 'theme_page_templates', function($templates){      $templates['my-page-template.php'] = "My Page Template";      return $templates;  });   This does not work because of the use of  on the filtered array, which removes the added page template item. I don't understand why this function is used. It seems you can only remove page template from the list but can not add a new one using the given filter.  Is there any other way around?
92703
I love admin-ajax.php. But I hate having to localize in order to point frontend scripts to it, and I wish there was an equivalent, easy-to-find file for themes. (It also just bothers me to see frontend requests go through "/wp-admin/". No practical reason, just looks ugly IMO.)  So I've simply copied admin-ajax.php to the root dir at "/ajax.php", adjusted the include paths and removed the WP_ADMIN constant definition. Seems to work like gangbusters (I can now just direct all my frontend AJAX requests to /ajax.php! And I can still use the normal wp_ajax hooks in my plugins!).  But is this safe? What might go wrong? Since this isn't built into core, I assume there's a good reason as to why not. But looking through the code, I can't see any immediate problems.   You're smart--tell me if this approach is crazy. Or if there's a simpler method that I'm overlooking.
19602
Could I theoretically use multiple php code areas / widgets in a page, each doing their own posts query and fetching with wp_query and get_posts() and use a page template that has no post loop?
27809
I am building a custom (child) theme and I want to style the first post of my loop in a different way than the others (bigger image, different position of some stuff).   Which is the best way of doing it? My "problem" is that my theme has support for different post types and the style would vary depending on the type of content, so I want to avoid repeating code as much as possible (i.e. using a function).   As I am a bit more used to OOP, my ideal scenario would be passing a variable to the view and check it in the loop of each content-type (that way I can re-use most of the code from the TwentyEleven templates). From what I know, that is not possible (please correct me if I am wrong).   For now, what I do is this:  function electric_index_loop($readMore = 0) {  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array(     //Excluimos los "miniposts" (citas, estados, enlaces...) del listado     'tax_query' =&gt; array(         array(             'taxonomy' =&gt; 'post_format',             'field' =&gt; 'slug',             'terms' =&gt; array('post-format-aside', 'post-format-link',                 'post-format-status', 'post-format-quote'),             'operator' =&gt; 'NOT IN'         )     ),     'posts_per_page' =&gt; 5,     'paged' =&gt; $paged );  // The Query query_posts($args);  // The Loop if (have_posts()) {     $post_count = 0;     global $more;     $more = $readMore; // 0 fuerza que se muestre sólo el "excerpt", 1 fuerza que se muestre todo el contenido     twentyeleven_content_nav('nav-above');     while (have_posts()) {         the_post();         if ($post_count == 0) {             get_template_part('highlight', get_post_format());         } else {             get_template_part('content', get_post_format());         }         $post_count++;     } } else {     ?&gt;     &lt;article id="post-0" class="post no-results not-found"&gt;         &lt;header class="entry-header"&gt;             &lt;h1 class="entry-title"&gt;&lt;?php _e('Nothing Found', 'twentyeleven'); ?&gt;&lt;/h1&gt;         &lt;/header&gt;&lt;!-- .entry-header --&gt;          &lt;div class="entry-content"&gt;             &lt;p&gt;&lt;?php _e('Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven'); ?&gt;&lt;/p&gt;             &lt;?php get_search_form(); ?&gt;         &lt;/div&gt;&lt;!-- .entry-content --&gt;     &lt;/article&gt;&lt;!-- #post-0 --&gt;     &lt;?php } wp_reset_query();}   As you see, I check the counter in the loop that I create in the function and ,if the current post is the first, I load a different template ("highlight").  I'd have to create different templates for the different types of content (which, in some cases sucks, because I can get all I need in some cases with just a CSS class).   Well, is there a better way of doing these? Perhaps a hook or something?   Thanks in advance!
97763
This is the first time I've ever tried to load a view using Ajax in Drupal7 and I would be appreciated if you help me from scratch. I've spent hours to learn how to do this but I still failed!  I created a view called image_gallery, it has three blocks called hd,tablet and phone and it displays set of images.I created a tab and I want to display and load these blocks (generally views) with Ajax. this my HTML:      &lt;div&gt;         &lt;div id="image_gallery_tab"&gt;             &lt;ul&gt;                 &lt;li id="igt1"&gt;HD&lt;/li&gt;                 &lt;li id="igt2"&gt;Tablet&lt;/li&gt;                 &lt;li id="igt3"&gt;Cellphone&lt;/li&gt;             &lt;/ul&gt;         &lt;/div&gt;         &lt;div id="image_gallery_content"&gt;             &lt;div class="igc" id="igc1"&gt;                 &lt;?php print views_embed_view("image_gallery","hd") ?&gt;             &lt;/div&gt;             &lt;div class="igc" id="igc2"&gt;             &lt;/div&gt;             &lt;div class="igc" id="igc3"&gt;             &lt;/div&gt;         &lt;/div&gt;     &lt;/div&gt;   I set the Use Ajax to "yes" in the views UI. this is my jQuery code:  $("#image_gallery_tab ul li").click(function(){         var id = $(this).attr("id").slice(-1);         $(".igc").css("display","none");         if(id==2)             {             $.ajax({                 url: Drupal.settings.basePath + 'views/ajax',                 type: 'POST',                 dataType: 'json',                 data: 'view_name=image_gallery&amp;view_display_id=tablet', // Pass a key/value pair.                 success: function(response) {                   $("#igc2").innerHTML=response.display;                 },                 error: function(data) {                  alert('An error occured!');                 }               });             }     });   but it displays nothing. what is wrong here and what shall I do? thanks
91901
I released a plugin that creates a shortcode and requires a JavaScript file and a CSS file to load on any page that contains that shortcode. I could just make the script/style load on all pages, but that's not the best practice. I only want to load the files on pages that call the shortcode. I've found two methods of doing this, but both have problems.    sets a flag to true inside the shortcode handler function, and then checks that value inside a wp_footer callback. If it's true, it uses wp_print_scripts() to load the JavaScript. The problem with this is that it only works for JavaScript and not CSS, because CSS should be declared inside &lt;head&gt;, which you can only do during an early hook like init or wp_head.    fires early and "peeks ahead" to see if the shortcode exists in the current page content. I like this method much better than the first, but the problem with it it won't detect if the template calls do_shortcode().  So, I'm leaning towards using the second method and then trying to detect if a template is assigned, and if so, parse it for the shortcode. Before I do that, though, I wanted to check if anyone knows of a better method.   Update: I've integrated the solution into my plugin. If anyone is curious to see it fleshed out in a live environment you can  or .  Update 2: As of WordPress 3.3, it's now possible to , and the JavaScript file will be called within the document's footer. That's technically possible for CSS files as well, but should be considered a bad practice because outputting CSS outside the &lt;head&gt; tag violates W3C specs, can case FOUC, and may force the browser to re-render the page.
116365
I mean, like php'h include...  something like   my_file_to_be_included = "include_me.asp"  -- >   for what I've seen so far, there are a couple of alternatives, but every one of them has some sort of shortcoming...  what I'm trying to figure out is how to make a flexible template system... without having to statically include the whole thing in a single file with a loooooong case statement...  here there are a couple of links            but it has some shortcomings I'd like to avoid... seems like (haven't tried yet) Server.Execute code runs in another context, so you can't use it to load a functions your are planning to use in the caller code... nasty...        I'm not sure about it (couldn't test it yet) but it seems like this one dinamycally handles the page to a SSDI component...  any idea???
119666
I'm making an AJAX call in drupal 7 via the standard AJAX Framework. My  problem is that when a status message is set by the AJAX callback, it is simply lost (or displayed at the next reload of the page). How can I display the status messages right after the AJAX callback has finished running, without reloading the page? Is there a module for that?
399
I have been racking my brains over how in bloody hell can you have a different header for the title (or first) page of a document.   I am not asking here how I can not have a header by clearing the page style for this page using \thispagestyle{plain} or something of the sort but how can I have a different header just for the very first page.   Please help as I have a deadline to meet.   So far, I have not been able to find anything useful on TeX.SE.   Here is some of my code to give you some idea of what I want to achieve:  \documentclass[12pt]{article} \usepackage{amsmath} \usepackage[margin=2.5cm]{geometry} \usepackage[utf8]{inputenc} \usepackage{amsfonts} \usepackage{fancyhdr} \usepackage{hyperref} \usepackage{graphicx} \usepackage{csc} \pagestyle{fancy} \fancyhead[L]{**Left Header for all pages**}\fancyhead[R]{**Right Header for all pages**} \lhead{**Left Header for just the first page**} \rhead{**Right Header for just the first page**} \title{Problem Set 1}         \author{MyBloodyName} \date{January 31, 2017} \begin{document}     \maketitle     \newpage     Easier? \end{document}
33938
I have one of those "I swear I didn't touch the server" situations. I honestly didn't touch any of the php scripts. The problem I am having is that php data is not being saved across different pages or page refreshes. I know a new session is being created correctly because I can set a session variable (e.g. $_SESSION['foo'] = "foo" and print it back out on the same page just fine. But when I try to use that same variable on another page it is not set! Is there any php functions or information I can use on my hosts server to see what is going on?  Here is an example script that does not work on my hosts' server as of right now:  &lt;?php session_start(); if(isset($_SESSION['views']))     $_SESSION['views'] = $_SESSION['views']+ 1; else     $_SESSION['views'] = 1;  echo "views = ". $_SESSION['views']; echo '&lt;p&gt;&lt;a href="page1.php"&gt;Refresh&lt;/a&gt;&lt;/p&gt;'; ?&gt;   The 'views' variable never gets incremented after doing a page refresh. I'm thinking this is a  problem on their side, but I wanted to make sure I'm not a complete idiot first.  Here is the phpinfo() for my hosts' server (PHP Version 4.4.7):
47257
I have 8 content types and 4 of them are the same and the difference is just their name. they all have a page view and the way I display them on screen is the same. instead of having 8 pages. (VIEWNAME_i stands for the i-th view.)   views-view--VIEWNAME_i--page.tpl views-view-field--VIEWNAME_i--page.tpl   I need a template function to reduce these 8 pages into 2. I want to define a general page for views-view--VIEWNAME_i--page.tpl. I would assign every view's variables in this function. I also want to do the same for fields page.
92282
I need to add a list of companies' information to my website and I want to display the list in a page. Then by clicking on each company, user can see more information about that company in its individual post. What is the right approach for doing this? I researched about custom post types and custom fields. But they seem to be not right for me. Do I have to build a post for each company? They are more than a hundred. Is there a more speedy way to do this? P.S The companies has identical fields. Each company has a name, description, etc and also has a few photos.