Using WordPress to display identical blog content across several websites

I currently have a Wordpress blog set up at blog.mydomain.com. I am in the process of creating a mobile version of my website at m.mydomain.com, which will include a section for the blog. My goal is to use the same database and pull in all the existing blog posts while displaying them with CSS tailored for the mobile site. How can I achieve this?

EDIT: Below is the code I am attempting to insert the blog posts into:

<div class="blog">
    <div class="section-header">
        <img class="section-logo" src="images/logo-small.png" alt="img">
        <a href="#" class="section-navigation-deploy"><img class="navigation-deploy-icon" src="images/nav-icon.png" alt="img"></a>
        <div class="clear"></div>
   </div>
   <div class="deco-open"></div>

   <?php
require('http://blog.mydomain.com/wp-blog-header.php');
$posts = get_posts('numberposts=-1&order=DSC&orderby=date');
?>

   <?php foreach ($posts as $post) : start_wp(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<section><?php the_excerpt(); ?></section>
<?php endforeach; ?>


    <div class="deco-close"></div>


</div>

Answer №1

<?php
  require('./blog/wp-blog-header.php');
  $posts = get_posts('numberposts=-1&order=DSC&orderby=date');
?>

Make sure that the require statement points to the correct location of the wp-blog-header.php file within your blog directory.

In my current setup, I have placed this code in the wwwroot/index.php file while my blog is located in the wwwroot/blog directory. After fetching the posts into $posts, I will proceed to display them using the following loop:

<?php foreach ($posts as $post) : start_wp(); ?>
  <article>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <section><?php the_excerpt(); ?></section>
  </article>
<?php endforeach; ?>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The image does not resize properly even when placed directly within the .col element

Currently, I am working with Bootstrap 4.1.3 and having an issue where my image does not scale up to the height of the row. Can anyone point out what I might be doing wrong in the following code? <div class="container"> <div class="row top-lo ...

Changing a number from 0 to 1 in a field using AngularJS (HTML5)

It's strange behavior. I am using an input field with the type set to number. When I enter 1230, the model value remains as 1230. However, when I type 01, it becomes 1. Even though I can see 01 in the input value, there seems to be something relate ...

Creating an interactive HTML form that updates in real-time based on user input can be achieved using vanilla JavaScript. This allows for a

I am working on a form that dynamically generates more form fields based on a user input value. <form> <input type="Number" name="delivery"> </form> For example, if the user enters '3', it should automat ...

Transforming HTML code into a structured object

The provided code snippet includes HTML markup that needs to be transformed into a specific format. <html> <head> <title>Hello!</title> </head> <body> <div class=”div1”> <h1>This is a ...

Positioning Problems with Popups

I have been facing an issue with the positioning of a popup in my trivia game. Despite trying multiple solutions, I have not been able to achieve consistency. Here is a snippet of the HTML code: <div class="logo"> <img src="css/rio-40.png"/& ...

What is the process for implementing filtered HTML attributes in a directive?

I’ve created a custom directive that generates a popup menu by extracting data from HTML content. The purpose is to transform a group of Bootstrap carousel-compatible elements into a structured list. However, each .item element contains an attribute with ...

What is the reason for my HTML elements inheriting the opacity of their parent elements?

After inserting an image tag into my HTML document, I noticed that it was inheriting the opacity from the parent div element. Despite multiple attempts to adjust this, I have been unsuccessful. Here is an example: <div style="opacity: 0.7"> <img ...

Inquiring about the presentation of text using HTML and CSS

I am looking for a simple fix to make a line of HTML display exactly as follows: 22 West Washngton St. Northbrook, IL 39492 Instead of: 22 West Washington St. Northbrook, IL 39492 Can someone guide me on how to remove the space between the lines of ...

What is the best way to delete a parent div without losing its inherited CSS properties?

My current objective involves the following: <div id="table"> <div id="user"></div> <div id="user1"></div> </div> Upon clicking a button, the following actions take place: $("#body").append("<div id=\"user-wra ...

CSS Tutorial: Creating a Dynamic Gradient Bar

I am looking to create a dynamic colored bar with a moving color gradient effect. Without using JavaScript, I want to achieve this effect using CSS 3 properties such as gradients and animations. This is a snippet of what I have tried so far: HTML: <b ...

Disabling the scrollbar on a modal and enabling it on a custom div within the modal

Looking to create a bootstrap modal with a unique layout? Interested in having two columns that can be scrolled separately? body, html { font-size: 10px } <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_ ...

The button is obscured by the dropdown menu

Here is the code snippet I am working with: HTML <nav class="navbar bg-dark navbar-dark"> <div class="container-fluid"> <div class="navbar-header"> <a href="#" class=&quo ...

Displaying a dynamic menu using Angular's ngFor loop

I am attempting to create a menu with sub-menus. The desired structure for my menu is outlined below. However, the demo I'm testing is not producing the correct structure. Check out the demo here. "Sub Test": { // Main menu "Example1":"hai",//sub ...

Identifying added elements that respond to link hover effects

I've been working on a project where I'm trying to replace the default browser cursor with an SVG one using jQuery. Everything seems to be working smoothly, except for changing the cursor when it hovers over links - nothing I've tried so far ...

Are there any resources available for optimizing performance on iOS and Android browsers?

Being a web developer means considering the Android and iOS web browsers, which have their own rendering engines and limitations in power and memory. This can pose many complications. Therefore, I'm curious if there is a detailed guide available for ...

Transitioning between javascript functions

Having some issues with a switch case statement, also tried using if-else but no luck. In the HTML code: <select onBlur="functionCalc()" id="art"> <option value="hours" id="hours">Hours</option> <option value="minutes" id="mins">M ...

What are the steps to integrating JavaScript functions into an HTML document?

Struggling with integrating a JavaScript function from one file into an HTML file? I'm having trouble getting it to work and suspect it has something to do with making the JavaScript accessible in the HTML. The function is meant to sum up values taken ...

Strange image resizing issues observed during refresh

Every time I refresh the page, I am faced with this strange resizing issue showcased in the GIF below: https://i.sstatic.net/tzlYTUyf.gif The image appears to be resized in an odd manner. <WifiWidgetContainer> <Image ...

Is it possible to modify the color of a division row using an onchange event in JQuery?

I am facing a requirement to dynamically change the color of rows based on the dropdown onchange value. The rows are structured in divisions, which were previously tables. There are two main divisions with rows that need to be updated based on dropdown sel ...

Photos inside a flexbox do not resize correctly

When placing 2 images inside a flexbox with the column direction, I anticipated that the images would resize accordingly when adjusting browser window size. However, this is not the case. Regardless of the CSS styles applied, I am unable to maintain the o ...